so, write a program that will do the following: For example: you have a given nu
ID: 3544463 • Letter: S
Question
so, write a program that will do the following:
For example:
you have a given number N:10
you have some values in an array: {1,2,3,4,5,10}
you need to compare each vale in the array with the given number N to check if the value is factor of N by not using division: ** you need to use subtraction to find the factor: for example: 10-5-5=0, so 5 is factor of 10.
you need to store the results in another array: let's say: result []. if a vaule is factor of N, then insert a "1" in to the result array. The size of the result array is the same as the size of the data array.
then print the result: for example:
N=10
so {1,2,3,4,5,10}
1->1
2->1
3->0
4->0
5->1
10>1
Please help.
Explanation / Answer
please rate - thanks
.data
numbers: .word 1,2,3,4,5,10
result: .word 0,0,0,0,0,0
n: .word 10
Nequal: .asciiz "N = "
so: .asciiz " so { "
close: .asciiz "} "
comma: .asciiz ","
nl: .asciiz " "
arrow: .asciiz "->"
.text
.globl main
main:
la $t2,numbers
la $t3, result
li $t0,1
li $t5,6
li $t6,0
nextnum:
lw $t4,0($t2)
lw $t1,n
subtract:
sub $t1,$t1,$t4
bgtz $t1,subtract
bltz $t1,nott
sw $t0,0($t3)
j next
nott: sw $t6,0($t3)
next: addi $t5, -1
beqz $t5,done
addi $t3,$t3,4
addi $t2,$t2,4
j nextnum
done: li $t5,6
la $t2,numbers
la $t3, result
la $a0,Nequal
li $v0,4
syscall
lw $a0,n
li $v0,1
syscall
la $a0,so
li $v0,4
syscall
li $t5,6
outvals: lw $a0,0($t2)
li $v0,1
syscall
la $a0,comma
li $v0,4
syscall
addi $t2,4
addi $t5,-1
bgtz $t5,outvals
la $a0,close
li $v0,4
syscall
li $t5,6
la $t2,result
la $t3,numbers
outsol: lw $a0,0($t3)
li $v0,1
syscall
la $a0,arrow
li $v0,4
syscall
lw $a0, 0($t2)
li $v0,1
syscall
la $a0,nl
li $v0,4
syscall
addi $t2,4
addi $t3,4
addi $t5,-1
bgtz $t5,outsol
li $v0,10
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.