14,829,981 members
See more:
Hi
I have a project from my college to program in mips code. But the content of register doesn't increse
.I must program in mips to print if sum of digits of numbers from 1 to 1000 is divisible by 5 and 7 and not by 3 print
Sorry for my English

What I have tried:

.data
x: .word 1
.space 4000
li $v0,5 la$a0,x
syscall
.data

loop:
sw $t0,$a0
addi $t1,$zero,10
add $t4,$zero,$zero rem$t4,$t0,$t1
div $t0,$t0,$t1 bne$t0,$zero,loop rem$t5,$t4,5 bnez$t5,label
rem $t6,$t4,7
bnez $t6,label rem$t7,$t4,3 beqz$t7,label

li $v0,1 move$a0,$t4 syscall j label label: add$a0,$a0,1 ble$t0,1000,loop
#li $v0,5 #la$a0,\$t0
#syscall
Posted
Updated 18-Jan-18 10:20am

## Solution 1

Yes, of course :-)

Well, my MIPS assembly is rusty. The following code, however, produces the correct result (tested on a simulator)
ASM
    li t0, 1	# t0 is the index of the loop (1..1000)
li t1, 0    # t1 is the sum of the selected numbers
# t2 is a temporary
li t3, 3    # t3 holds the constant number 3
li t5, 5    # t5 holds the constant number 5
li t7, 7    # t7 holds the constant number 7
loop:
rem t2, t0, t3
nop
rem t2, t0, t5
nop
rem t2, t0, t7
nop
li t2,1001
bne t0,t2, loop
nop
nop		 # here t1 contains the result
v2