'how can i end the programm if the array is full? MIPS
.data
array: .space 40
message1: .asciiz "Enter a number ~> "
message2: .asciiz "The max number is ~> "
.text
.globl main
main:
la $t0 , array
li $t1, 0
li $s0 , 0
move $s1 , $v0
loop:
addi $v0 , $0 , 4
la $a0 , message1
syscall
addi $v0 , $0 , 5
syscall
sw $v0 , 0($t0)
addi $t5 , $t5 , 4
addi $s0 , $s0 , 1
beq $s0 , $s1 , max
j loop
max:
la $t0 , array #load array start address
lw $t2 , 0($t0) #max = first element
li $s0 , 0 #i == 0
max_loop:
lw $t3, 0($t0) #temp = actual array element
slt $t4 , $t2 , $t3 #max < temp ?
bne $t4 , 1 , else
move $t2 , $t3 #max = temp
else :
addi $s0 , $s0 , 1
addi $t6 , $t5 , 4
beq $s0 , $s1 , exit
j max_loop
exit:
addi $v0 , $0 , 4
la $a0 , message2
syscall
li $v0 , 1
move $a0 , $t2
syscall
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
