Sie sind auf Seite 1von 8

Unsigned Binary Representation

Register Use Conventions


MIPS Arithmetic
 Fixed instruction length of 4 bytes (32 bits)
 All instructions have 3 operands
 1 instruction per line
 Operand order is fixed (destination first)

 Operands must be registers


 Each register is 1 word (32 bits / 4 bytes)
 Registers are internal memory locations inside MIPS used to store data
 Only 32 registers are provided
 Keeps clock cycle short
 Signals travel shorter distances
 Faster
Functions
 In the execution of function, the program:
1. Put parameters in a place the function can access them
2. Transfer control to the function
3. Acquire the storage resources needed for the function
4. Perform desired task
5. Place result value in a place where the calling program can access it
6. Return control back to point of origin
 Registers used for function call

 Special register in MIPS:


Program counter [PC] holds the address of current instruction to be
executed
 Instruction to call function: Use jump and link instruction
jal function_address
 Jumps to function address
 Saves address of next instruction into register $ra [PC+4]
 Instruction to return from function back to calling program: Use jump to
instruction
jr $ra
 Jumps to instruction with address stored in $ra
 Function handling convention:
In main program
1. Pass parameters to function in $a0-3
2. Call function: jal fn_address #return address in $ra
In function label
3. Execute function instructions
4. Return results in $v0-1
5. Return control back to calling program: jr $ra
 If need to pass more than 4 arguments or return more than 2 results:
Use temporary storage data structure: stack
 Register $sp (stack pointer) is used to store the most recently
allocated address in the stack for storing data
 $sp is adjusted by 4 bytes for each register that is saved (push) or
restored (restored)
Nested Functions

 Solution:
1. Caller pushes $ra and any argument registers ($a0-3) or temporary
registers ($t0-9) that are needed after the call onto the stack
2. Callee pushes any saved registers ($s0-7) used by callee
3. Stack pointer $sp is adjusted to account for the number of registers
placed onto the stack
4. Upon return, the registers are restored off the stack and the stack
pointer readjusted to its original state
 Across a function call:

Recursive Functions
Communicating with People
 Computers use 8-bit bytes to represent chracters
 Common standard is ASCII
 Special instructions to move bytes

Das könnte Ihnen auch gefallen