Lecture 04 - Instructions Language of the Computer
Lecture 04 - Instructions Language of the Computer
Instructions: Language
of the Computer
Compiling If Statements
n High-level language code:
if (i==j) f = g+h;
else f = g-h;
n f, g, … in $s0, $s1, …
n Compiled MIPS code:
bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit
Else: sub $s0, $s1, $s2
Exit: …
Assembler calculates addresses
n Result in $v0
n Result in $v0
lui $s0, 61 0000 0000 0011 1101 0000 0000 0000 0000
ori $s0, $s0, 2304 0000 0000 0011 1101 0000 1001 0000 0000
op rs rt constant or address
6 bits 5 bits 5 bits 16 bits
n PC-relative addressing
n Target address = PC + offset × 4
n PC already incremented by 4 by this time
Chapter 2 — Instructions: Language of the Computer — 21
Jump Addressing
n Jump (j and jal) targets could be
anywhere in text segment
n Encode full address in instruction
op address
6 bits 26 bits
Static linking