Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSCI206 - Computer Organization & Programming Pseudo-Instructions and Addressing Data zyBook: 5.8, 5.9 Developed and maintained by the Bucknell University Computer Science Department - 2017 Pseudo-instructions 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 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 One more example li $t0, 0x8C828A43 Can be implemented as lui $at, 0x8c82 ori $t0, $at, 0x8a43 [let’s do the worksheet] Registers Addressing data in a register Encode the register number (0-31) in the machine instruction R/I formats Immediates Immediate data can be encoded in an I type instruction this data is implicitly addressed what are the limitations? 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 0000 0000 1111 1111 which is 0x00FFFF00 1111 1111 0000 0000 MIPS optimizes for the common case, small immediate values two instructions are handle the other (less common) cases. Basic Program Memory Map Local (automatic) variables inside functions; activation records (recursion); unsafe to share between functions / modules Dynamically allocated memory; safe to share between functions / modules Global variables Your program’s compiled machine code Dynamic (runtime) allocation Static (compile time) allocation 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 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). 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 +32767 or -32768 instructions) 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? MIPS Addressing