117k views
0 votes
Write an assembly subroutine that check if a number is in the interval of [0, 10] and return 1 if the number is in this interval and 0 otherwise. Call this subroutine to check if each integer in an array in the memory is in this interval and write the results of all numbers into another array in the memory

1 Answer

3 votes

Answer:

.data

array: .word 1,3,5,7,9,11,13,15,17,19

result: .word 0,0,0,0,0,0,0,0,0,0

.text

la $s0, array

la $s1, result

addi $t0, $zero, 0

INTERVAL: bge $t0, 10, END

sll $t1, $t0, 2

add $t2, $s0, $t1

lw $t2, 0($t2)

jal LIMIT

IF: bne $a0, 1, ELSE

add $t3, $s1, $t1

sw $t2, 0($t3)

ELSE:

addi $t0, $t0, 1

j INTERVAL

END:

addi $v0, $zero, 10

syscall

LIMIT:

addi $a0, $zero, 0

START: bge $t2, 0, NEXT

b ENDLIMIT

NEXT: ble $t2, 10, SET

b ENDLIMIT

SET: addi $a0, $zero, 1

ENDLIMIT:

jr $ra

Step-by-step explanation:

The assembly source code is used to create a subroutine called "INTERVAL" that checks if a number from an array is in a range of 1 to 10. The program returns 1 if the condition is met but 0 if otherwise.

User Chengqi
by
5.2k points