CS计算机代考程序代写 assembler Slide 1

Slide 1

Load Word and
R-Type Instructions
By Christopher Mar

Project 2 Demo on PLP Board
Available in Video Lecture

2

Load Word Instruction

Load Word Instruction
Load word copies value from memory to a register
lw $t3, 0($t4)
Memory Address
Destination

I/O Device: Switches

I/O Device: Switches
Each switch corresponds to a specific bit of a single value
Value located at the address, 0xf0100000

I/O Device: Switches
Each switch controls a bit position that is a representation of a power of 2
Switch 0 represents 20 (= 1)
Switch 1 represents 21 (= 2)
Switch 2 represents 22 (= 4)
Continues to switch 7 (27 = 128)

I/O Device: Switches
For example, what will the value at the switch address be if switches 0, 2, and 5 are set?
20 + 22 + 25 =
1 + 4 + 32 =
37

I-Type vs. R-Type Instructions
I-Type Instructions
Output destination:
Register
Inputs:
1 register
1 immediate value
R-Type Instructions
Output destination:
Register
Inputs:
2 register
Exception:
Shift instructions use one register and a shift amount (shamt)

I-Type Add
Add immediate instruction
addiu $t3, $t2, 29
Equivalent to the assignment statement:
$t3 = $t2 + 29

R-Type Add
Add instruction
addu $t6, $t4, $t5
Equivalent to the assignment statement:
$t6 = $t4 + $t5

Logical Shift Left
Shift value left by an indicated number of binary digits (bits)
sll $t2, $t3, 2
Equivalent to the assignment statement:
$t2 = $t3 << 2 Logical Shift Left For the previous instruction, suppose $t3 contained 0b00110101 (== 0x35 == 53) sll $t2, $t3, 2 0 0 1 1 0 1 0 1 Logical Shift Left First shift left by 1 bit 0 0 1 1 0 1 0 1 Logical Shift Left New least significant bit is a zero Old most significant bit is lost 0 1 1 0 1 0 1 0 0 0 1 1 0 1 0 1 Logical Shift Left Second shift left by 1 bit 0 1 1 0 1 0 1 0 Logical Shift Left Once again: New least significant bit is a zero Old most significant bit is lost 1 1 0 1 0 1 0 0 0 1 1 0 1 0 1 0 Shifts as Mathematical Operators A binary shift of a number left by x bits is the same as multiplying the number by 2x Just like multiplying a decimal number by 10 shifts the digits one position to the left Shifting right is equivalent to integer division by the same power of 2 Pseudo-Operations Similar to a macro Assembler replaces a pseudo-op with a set of one or more native instructions Load immediate (li) is a pseudo-op made up of two separate native instructions Takes two cycles to complete Branches