60 pts., due Oct. 3
For problems 2 and 3, use SPIM to test your program. Turn in well-commented program source and a sample run using script.
MOVEA.L START,A0 MOVEA.L N,A1 ADDA.L A0,A1 MOVEA.L A0,A2 MOVE.B (A0)+,D0 LOOP CMP.B (A0)+,D0 BLE NXT LEA -1(A0),A2 MOVE.B (A2),D0 NXT CMPA.L A0,A1 BGT LOOP MOVE.L A2,DESIRED
how many memory accesses (counting both data and instruction accesses) are performed in executing the program? Note that the characters are stored in memory using an ASCII encoding.
What is the value stored in DESIRED?
All calculations should be done in registers.
What is the largest value of n that your program can handle?
Use a subroutine which prompts the user to enter a string and then reads the string. This subroutine will be called twice by your main program and should take two parameters: the starting address of the array into which the string is placed, and the length of the array. Use registers $a0 and $a1 for passing the parameters.
Use the jal instruction to call your subroutine. The return address will be stored in register $31. If you don't make any nested subroutine calls (there's no need to) and you don't modify $31 (you shouldn't), you can just leave the return address there. To return to the instruction following the subroutine call use this instruction:
Here's a hint as to how to structure your program:
.data # Declarations, constants for main. ... .text .globl main main: ... jal gets # Call subroutine. ... li $v0, 10 syscall .data # Declarations, constants for gets. ... .text gets: ... jr $31