Presentation is loading. Please wait.

Presentation is loading. Please wait.

Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday.

Similar presentations


Presentation on theme: "Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday."— Presentation transcript:

1 Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday

2 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

3  Use this instruction when the byte is regarded as an 8-bit two’s complement integer in the range -128...+127 and you want a 32-bit version of it.  Of course, the value of the integer does not change. lb

4  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. lbu 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 ? 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 ?

5 lb example Which type of instruction is this ?

6 lb examples (decimal vs hex) lb $8, 0x60($10) lb $8, 96($10) lb $8, 0xFFF8($10) lb $8, -8($10) 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.

7  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. 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 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 ?  Sometimes the instruction after the lb is a useful instruction.  Sometimes it’s a dangerous one  $11 is damaged by the byte came from the memory  Always try to use simple NOP instead of complex useful instruction in delay slots. Filling Load delay slot

10 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 ?  Sometimes the instruction after the lb is a useful instruction.  Sometimes it’s a dangerous one  $11 doesn’t contain yet the byte came from the memory Filling Load delay slot

11 Storing a Single Byte

12 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 0x10000000 srl $9,$9,8 sb $9,1($8) # Save 0xab at 0x10000001 srl $9,$9,8 sb $9,2($8) # Save 0x34 at 0x10000002 srl $9,$9,8 sb $9,3($8) # Save 0x12 at 0x10000003 lb, lbu, sb examples 1 23 4a bc d 1 00 $9 $8 c da b3 41 2 0x10000000

13 Example continues. Delay Slots ? 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)  Where are NOPs in delay slots ?  Does this work properly without NOPs ? What is the difference between upper and lower pairs of instructions’ results ?


Download ppt "Home Assignment 5 Assigned. Deadline 2016 March 2, Wednesday."

Similar presentations


Ads by Google