Click here to Skip to main content
14,773,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 11:20am

1 solution

Yes, of course :-)

Well, my MIPS assembly is rusty. The following code, however, produces the correct result (tested on a simulator)
    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
    beq t2, zero, skipadd
    nop
    rem t2, t0, t5
    bne t2, zero, skipadd
    nop
    rem t2, t0, t7
    bne t2, zero, skipadd
    nop
    addu t1, t1, t0
skipadd:
    addiu t0,t0, 1
    li t2,1001
    bne t0,t2, loop
    nop
    nop		 # here t1 contains the result
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900