Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI206 - Computer Organization & Programming

Similar presentations


Presentation on theme: "CSCI206 - Computer Organization & Programming"— Presentation transcript:

1 CSCI206 - Computer Organization & Programming
Pseudo-Instructions and Addressing Data zyBook: 5.8, 5.9

2 Pseudo-instructions beq $t, $s, label What is a pseudo-instruction?
A pseudo-instruction is not a real MIPS instruction, but one can use it as if it were. For example, we know these two MIPS instructions beq $t, $s, label bne $t, $s, label But we don’t have something like blt $t, $s, label Or the like

3 MIPS Pseudo-instructions
MIPS provides a set of such pseudo-instructions to make programmers’ life easier. Typically these pseudo-instructions are translated into real instruction at the assembly time For example, blt $t, $s, label Can be implemented as slt $at, $t1, $t2 bne $at, $zero, label

4 One more example li $t0, 0x8C828A43 Can be implemented as
lui $at, 0x8c82 ori $t0, $at, 0x8a43 [let’s do the worksheet]

5 Registers Addressing data in a register
Encode the register number (0-31) in the machine instruction R/I formats

6 Immediates Immediate data can be encoded in an I type instruction
this data is implicitly addressed what are the limitations?

7 32-bit Values from Immediates
step 1: lui - load upper immediate lui $t0, 0x00FF step 2: ori - or immediate ori $t0, $t0, 0xFF00 final result in $t0 which is 0x00FFFF00 MIPS optimizes for the common case, small immediate values two instructions are handle the other (less common) cases.

8 Basic Program Memory Map
Local (automatic) variables inside functions; activation records (recursion); unsafe to share between functions / modules Dynamic (runtime) allocation Dynamically allocated memory; safe to share between functions / modules Global variables Static (compile time) allocation Your program’s compiled machine code

9 Base + displacement addressing
lw/lh/lb sw/sh/sb Construct a memory address from a base address in a register plus some immediate offset Useful for variables top of stack/heap in $sp/$gp register, immediate value selects offset Useful for arrays beginning of array in a register, immediate value selects the index

10 PC-Relative Addressing (branches)
PC is the Program Counter, it is the address of the instruction being executed. I-format instruction provides a 16 bit offset, relative to the next instruction. Good for short branches (local loops, if, case, etc). Not enough bits for function calls (can’t jump very far away).

11 MIPS Branch Distance The branch immediate address is a sign extended (2's complement) value added to the current PC Since we are dealing with instructions that must be word aligned (32-bit), the last 2-bits are assumed to be 00, therefore a branch can reach +0x1fffc or -0x20000 bytes! (that is or instructions)

12 Pseudo-direct Addressing
J-type instructions contain a 26-bit word address (unsigned) (28-bit byte address), 2^28 == 256 MB range This leaves the upper 4-bits unaccounted for Uses the upper 4-bits of the next PC value This is enough for most programs How could you jump beyond the 256 MB?

13 MIPS Addressing


Download ppt "CSCI206 - Computer Organization & Programming"

Similar presentations


Ads by Google