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: