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 we can use 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 implement the following using slt and bne, blt $t, $s, label Can be implemented as slt $at, $t1, $t2 bne $at, $zero, label

4 Another example Can be implemented using lui and ori as
li $t0, 0x8C828A43 # load immediate Can be implemented using lui and ori as lui $at, 0x8c # load upper immediate ori $t0, $at, 0x8a43 # or immediate [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 e.g., lw $t0, 32($s0) # load value at memory address $s onto $t0 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. e.g., beq $s0, $s1, label # if $s0 has the same value as $s1, jump to label 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 (words) from current instruction address.

12 MIPS Branch Distance Computation
Why between +0x1fffc and -0x20000 bytes? The 16-bit immediate has a range from 0x0000 to 0xFFFF, the largest positive value is 0x7FFF and the smallest negative value (largest in absolute value) is 0x8000. We shift the value to the left by two positions (adding two 0’s) to get the word addresses. 0x7FFF << 2 results in 0x1FFFC 0x8000 << 2 results in 0x20000

13 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?

14 MIPS Addressing Summary


Download ppt "CSCI206 - Computer Organization & Programming"

Similar presentations


Ads by Google