Pseudo-Instructions: Assembler Psedudo-Instruction
Pseudo-Instructions: Assembler Psedudo-Instruction
Pseudo-Instructions: Assembler Psedudo-Instruction
These are simple assembly language instructions that do not have a direct machine language equivalent. During assembly, the assembler translates each psedudoinstruction into one or more machine language instructions.
The assembler will translate it to add $t0, $zer0, $t1 We will see more of these soon.
# if $s0 < $s1 then $t0 =1 else $t0 = 0 # if $t0 " 0 then goto label
Quite often, we would like to load a constant value into a register (or a memory location)
lui $s0, 42
New instruction
slt $t3, $s5, $zero bne $t3, $zero, Exit slt $t3, $s5, $t2 beq $t3, $zero, Exit
# if k < 0 then $t3 = 1 else $t3=0 # if k<0 then Exit # if k<4 then $t3 = 1 else $t3=0 # if k# 4 the Exit
L0
f=i+j J Exit
L1
f = g+h j Exit
Exit
MEMORY
add $t1, $s5, $s5 add $t1, $t1, $t1 add $t1, $t1, $t4 lw $t0, 0($t1) jr $t0 L0: add $s0, $s3, $s4 J Exit L1: add $s0, $s1, $s2 J Exit L2: sub $s0, $s1, $s2 J Exit L3: sub $s0, $s3, $s4 Exit: <next instruction>
# t1 = 2*k # t1 = 4*k # t1 = base address + 4*k # load the address pointed # by t1 into register t0 # jump to addr pointed by t0 #f=i+j
# f = g+h
# f = g-h
#f=i-j
10000
is represented as
2500
6-bits
26 bits
is represented as
16
17
16-bit offset
bne $t0, $s5, Exit add $s3, $s3, $s4 j Exit: 6 80000 80004 80008 80012 80016 80020 80024 80028 0 0 0 35 5 0 2 5 19 9 9 9 8 19 5 19 9 22 8 21 20 19 5 9 9 9 5 0 0 0 0 2 (why?) 0 32 6 32 32 32 Loop
20000 (why?)
Addressing Modes
Register addressing Operand is in register add $s1, $s2, $s3 means $s1 ! $s2 + $s3
Base addressing Operand is in memory. The address is the sum of a register and a constant. lw $s1, 32($s3) means $s1 ! M[s3 + 32]
Direct addressing
$s1 ! M[32]
Indirect addressing
$s1 ! M[s3]
Immediate addressing The operand is a constant. How can you execute $s1 ! 7?
addi $s1, $zero, 7 means $s1 ! 0 + 7 (add immediate, uses the I-type format)
PC-relative addressing The operand address = PC + an offset Implements position-independent codes. A small offset is adequate for short loops.
Pseudo-direct addressing Used in the J format. The target address is the concatenation of the 4 MSBs of the PC with the 28-bit offset. This is a minor variation of the PC-relative addressing format.