Write a MIPS program to continuously generate the following series of integers: 1, 2, 3, 6, 9, 18, 27, 54, 81, and so on. Use standard MIPS programming conventions. Use the jump instruction to generate an infinite loop. Write a subroutine EVEN that returns a 1 if the argument is even, else it returns a 0. You must call this subroutine with jal and return from it with jr. The MIPS program must be converted into machine code and placed in the instruction memory. The sequence can be computed by adding the value to itself if it is odd and by adding the previous value to it if it is even. Before replacing the test program in the instruction memory, make sure that your design works for the provided Test-Program.

Respuesta :

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: