Answer:
Explanation:
Here is a working solution in MIPS
.data
space: .asciiz ", "
.text
li $t1, 1 #Start at 1
li $t2, 1 #Store last value
li $t4, 1000 #terminate at 1000
li $t7, 2 #For division (divide by 2)
loop:
li $v0, 1
add $a0, $t1, $zero #print $t1
syscall
div $t1, $t7 #divide $t1 by 2
mfhi $t5 #get the remainder
move $t6, $t1 #hang on to what $t1 was originally
beqz $t5, even #if the remainder is 0, it's even
add $t1,$t1,$t1 #it's odd, so add to itself
move $t2, $t6 #store what $t1 was originally to last value
bgt $t1, $t4, done #if the number is over 1000, we're done
li $v0, 4 #Print a comma and space
la $a0, space
syscall
j loop
even:
add $t1,$t1,$t2 #set $t1 = $t1 + Last value ($t2)
move $t2, $t6 #store what $t1 was originally to last value
bgt $t1, $t4, done #if the number is over 1000, we're done
li $v0, 4 #Print a comma and space
la $a0, space
syscall
j loop
done: