sorting array in mips (assembly)

前端 未结 3 1524
忘了有多久
忘了有多久 2021-01-07 13:25

im in a class learning assembly using mips. I am working on sorting an array of numbers and i think that I have the method working correctly, but just a bit of trouble. I do

3条回答
  •  执念已碎
    2021-01-07 14:04

    .data

    value: .word 0x3

    Array: .word 0x14, 0x12, 0x13, 0x05

    .text

    .globl main

    main: la $a0, Array

       lw  $t3,value  
    

    l1: lw $t0, 0($a0)

       lw  $t1, 4($a0)     
    
       blt $t1, $t0, swap   
    
       addi    $a0, $a0, 4
    
       addi $t3,$t3,-1     
    
       bne  $t3,$zero,l1
    
       jr $ra
    

    swap: sw $t0, 4($a0)

        sw  $t1, 0($a0)    
    
        j   l1
    

提交回复
热议问题