Download presentation
Presentation is loading. Please wait.
Published bySteven Greer Modified over 6 years ago
1
Loading a Single Byte There are two instructions that load a byte from a memory address. The instructions differ in how the 8-bit byte is put into the 32-bit register. lb – load two’s complement byte lbu – load unsigned byte
2
lb Why is done the sign extension?
Use this instruction when the byte is regarded as an 8-bit two’s complement integer in the range and you want a 32-bit version of it. Of course, the value of the integer does not change.
3
lbu Why is done the zero extension?
The lbu instruction fills bits 8-31 of the register with zeros. Use this instruction when the byte is regarded as an ascii character or 8-bit unsigned integer.
4
lb, lbu examples 1. 0x77777777F 2. 0x7F0000000 3. 0xFFFFFFF7F
What will be in register $8 after loading the byte 0x7F By lb ? What will be in register $8 after loading the byte 0x7F By lbu ? What will be in register $8 after loading the byte 0x8F By lb ? What will be in register $8 after loading the byte 0x8F By lbu ? 1. 0x F 2. 0x7F 3. 0xFFFFFFF7F 4. 0x F 5. 0x FF 1. 0x F 2. 0x8F 3. 0xFFFFFFF8F 4. 0x F 5. 0x FF
5
lb example Which type of instruction is this ?
6
lb examples (decimal vs hex)
The assembler translates below assembly instruction pairs into exactly the same machine instructions. The second instruction in pairs uses signed decimal notation to specify numbers. That is much easier to use by human. lb $8, 0x60($10) lb $8, 96($10) lb $8, 0xFFF8($10) lb $8, -8($10)
7
Load delay slot There is a “one instruction delay” before the data from memory is available after load instructions. Reaching outside of the processor chip into main memory takes time. But the processor does not wait and executes one more instruction while the load is going on. This is the load delay slot. lb $11, 3($8) # after lb byte comes to Reg. # after one instruction # The data is not yet available # This is “delay slot” or $13,$0,$11 # in Reg. $11 the byte is now # available
8
Filling Load delay slot
Sometimes the instruction after the lb is a no-operation instruction. lb $11, 3($8) # after lb byte comes to Reg. # after one instruction sll $0,$0,0 # The data is not yet available # This is “delay slot” or $13,$0,$11 # in Register $11 the byte is # now available
9
Filling Load delay slot
Sometimes the instruction after the lb is a useful instruction. Sometimes it’s a dangerous one lb $11, 3($8) # after lb byte comes # after one instruction ori $11, $0, 1 # wrong usage of the # register in delay slot or $13,$0,$11 # What is the problem here ? $11 is damaged by the byte came from the memory Always try to use simple NOP instead of complex useful instruction in delay slots.
10
Filling Load delay slot
Sometimes the instruction after the lb is a useful instruction. Sometimes it’s a dangerous one lb $11, 3($8) # after lb byte comes # after one instruction or $12,$0,$11 # wrong usage of the # register in delay slot or $13,$0,$12 # What is the problem here ? $11 doesn’t contain yet the byte came from the memory
11
Storing a Single Byte
12
lb, lbu, sb examples ori $9,$0, 0x1234 # Prepare data sll $9,$9,16 ori $9,$9, 0xabcd ori $8,$0, 0x1000 # Prepare the address sll $8,$8,16 # in base register sb $9,0($8) # Save 0xcd at 0x srl $9,$9,8 sb $9,1($8) # Save 0xab at 0x sb $9,2($8) # Save 0x34 at 0x sb $9,3($8) # Save 0x12 at 0x $9 1 2 3 4 a b c d $8 1 0 0 0 0x c d a b 3 4 1 2
13
Example continues. Delay Slots ?
Where are NOPs in delay slots ? Does this work properly without NOPs ? lb $11, 3($8) # Positive values lb $12, 2($8) lb $16, 1($8) # Negative Values lb $17, 0($8) lbu $18, 1($8) # Unsigned load lbu $19, 0($8) What is the difference between upper and lower pairs of instructions’ results ? 0x c d a b 3 4 1 2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.