The assembler in SPIM automatically assembles code starting at address 0x10000000.
x
?
0x10000000poly
?
0x10000004Here is what this part of the SPIM simulation looks like:
Here is an important addition to the program. Decide on the registers you need and what they are used for. Then write down your decisions! This is crucial for getting things correct.
## poly.asm ## ## evaluate 5x^2 -12x + 97 ## ## Register Use: ## ## $10 base register, address of x ## $11 x ## $12 value of the polynomial ## $13 temporary .text .globl main main: lui $10,______ # Init base register lw $11,0($_____) # Load x ori $12,$0,_____ # Initialize the accumulator # during the "load delay slot" . . . many instructions sw $12,___($___) # Store result in poly .data # In SPIM, the data section # starts at address 0x10000000 x: .word 17 # The base register points here . poly: .word 0 ## End of file
A register where a value is built up after several calculations is called an accumulator. (Some old processors have a single, special register that is used for this purpose. But MIPS has many general purpose registers for this).
Remember that data loaded from memory is not
available to the instruction following the load.
The instruction after a
lw
,
in the "load delay slot",
should not try to use the loaded data.