assembly - My mips code won't print out the max and min -


my mips code compiles , runs problem doesn't output want to. code supposed find max , min of array of 8 integers. can please take thanks.

.data     x: .word 1, 2, 3, 4, 5, 6, 7, 8     max: .asciiz "max: "     min: .asciiz "min: "     space: .asciiz " " .text .globl main main:     la $t0, x     lw $s0, 0($t0)  #sets max first value in array     lw $s1, 0($t0)  #sets min first value in array     addi $t4, $0, 0 #sets counter 0 li $t1, 0   #index array     lw $t2, x($t1) lw $t3, x($t1)  loop:      bge $t0, 8, endloop     bgt $t2, $s0, setmax     blt $t3, $s1, setmin     addi $t1, $t1, 4     addi $t0, $t0, 1     j loop   setmax:     move $s0, $t2     j loop setmin:      move $s1, $t3     j loop endloop:     li $v0 4     la $a0 max     syscall      li $v0 1     la $a0 ($s0)     syscall      li $v0 4     la $a0 space     syscall      li $v0 4     la $a0 min     syscall      li $v0 1     la $a0 ($s1)     syscall      li $v0 10     syscall 

the code prints out max of 1 , min of 1. please help, thanks.

i figured out. realized not using correct register counter. here's updated code.

.data     x: .word 1, 2, 3, 4, 5, 6, 7, 8     max: .asciiz "max: "     min: .asciiz "min: "     space: .asciiz " " .text .globl main main:     la $t0, x     lw $s0, 0($t0)  #sets max first value in array     lw $s1, 0($t0)  #sets min first value in array     addi $t4, $0, 0       #sets counter 0     li $t1, 0   #index array   loop:      bge $t4, 8, endloop     lw $t2, x($t1)     bgt $t2, $s0, setmax     blt $t2, $s1, setmin cont:     addi $t1, $t1, 4     addi $t4, $t4, 1     j loop   setmax:     move $s0, $t2     j cont setmin:      move $s1, $t2     j cont endloop:     li $v0 4     la $a0 max     syscall      li $v0 1     la $a0 ($s0)     syscall      li $v0 4     la $a0 space     syscall      li $v0 4     la $a0 min     syscall      li $v0 1     la $a0 ($s1)     syscall      li $v0 10     syscall 

yeah works, gerardo believe name idea of using cont. in end believe using $t4 counter real solution.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -