Convert C++ to MIPS assembly

后端 未结 3 1337
说谎
说谎 2021-01-21 12:06

This code is about to find maximum element from an array i want to convert this code into MIPS assembly code can anyone help me...Or just tell me how to initialize an array in M

相关标签:
3条回答
  • 2021-01-21 12:18
        .data   # variable decleration follow this line
    
    array1: .word   2, 3, 421, 4, 32, 4, 3, 1, 4, 5 #10 element array is declared
    max:    .word   2
    
    la  $t0, array1         #load base address of array1
    main:                       #indicated the start of the code
    #to access an array element ($t0), 4($t0), 8($t0)..........
    
    0 讨论(0)
  • 2021-01-21 12:27

    convert to mips

    addi $t1, $0, 99 
    addi $t4, $0, 9 
    add $t3, $t2, $t1 
    sub $t3, $t3, $t4
    
    loop: lw $s1, 0($t2)
    lw $s2, 0($t3) 
    slt $s3, $s1, $s2 
    beq $s3, $0, label1 
    sub $s4, $s2, $s1 
    sw $s4,0($t3) 
    j label2
    
    label1: 
    sub $s4, $s1, $s2 
    sw $s4,0($t3)
    
    label2: 
    addi $t2, $t2, 4 
    addi $t3, $t3, 4 
    subi $t1, $t1,1 
    beq $t1, $0, loop
    
    0 讨论(0)
  • 2021-01-21 12:28

    Here's an example

            .data
    array1:     .space  12              #  declare 12 bytes of storage to hold array of 3 integers
            .text
    __start:    la  $t0, array1     #  load base address of array into register $t0
            li  $t1, 5                  #  $t1 = 5   ("load immediate")
            sw $t1, ($t0)                #  first array element set to 5; indirect addressing
            li $t1, 13                  #   $t1 = 13
            sw $t1, 4($t0)           #  second array element set to 13
            li $t1, -7                  #   $t1 = -7
            sw $t1, 8($t0)           #  third array element set to -7
            done
    
    0 讨论(0)
提交回复
热议问题