Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS334: Memory _ Mars simulator Lab 4(part2-2)

Similar presentations


Presentation on theme: "CS334: Memory _ Mars simulator Lab 4(part2-2)"— Presentation transcript:

1 CS334: Memory _ Mars simulator Lab 4(part2-2)

2 Control Structures in mips. Load / Store Instructions Add in hex.
Contents: Control Structures in mips. Load / Store Instructions Add in hex. Part2:memory. Exercise. Questions. Ins.Ebtesam AL-Etowi

3 Control Structures Branches
comparison for conditional branches is built into instruction. Jump to lable(target) if condition true else continue Ins.Ebtesam AL-Etowi

4 Cont……. Jumps j target # unconditional jump to program label target
Ins.Ebtesam AL-Etowi

5 Ins.Ebtesam AL-Etowi

6 Load / Store Instructions
RAM access only allowed with load and store instructions . all other instructions use register operands load: lw register_destination, RAM_source #copy word (4 bytes) at source RAM location to destination register. store word: sw register_source, RAM_destination #store word in source register into RAM destination Ins.Ebtesam AL-Etowi

7 Cont ….. load immediate li register_destination, value example:
#load immediate value into destination register example: lw $t0, var1 # load contents of RAM location into register $t0: $t0 = var1 li $t1, # $t1 = 5 ("load immediate") sw $t1, var1 # store contents of register $t1 into RAM: var1 = $t1 Ins.Ebtesam AL-Etowi

8 Add hex digit 3A49 + 4BA9 -------- 85F2
Before working with memory, you need to be able to add hex digits. Here is an example of adding 2 hex digits: 3A49 + 4BA9 85F2 Ins.Ebtesam AL-Etowi

9 Add hex digit 8* 16^3 + 5 * 16^2 + F * 16^1 + 2* 16^0 = 34290
Note that numbers without the 0x are decimal: Digit 0: 0x9 + 0x9 = = 18 = 0x12 (1 * 16^1 + 2 * 16^0). So, write down the 2 and carry the 1. Digit 1: 1 (carry) + 0x4 + 0xA = = 15 = 0xF. So, write down the F. There is no carry. Digit 2: 0xA + 0xB = = 21 = 0x15 (1*16^1 + 5 * 16^0). So, write down the 5 and carry the 1. Digit 3: 1 (carry) + 0x3 + 0x4 = = 8 = 0x8. So, write down the 8. 8* 16^3 + 5 * 16^2 + F * 16^1 + 2* 16^0 = 34290 34290=0x 85F2 Ins.Ebtesam AL-Etowi

10 Ins.Ebtesam AL-Etowi

11 Part 2: memory Now, let's look at memory. Start by entering the following into the simulator: .data A: .word 25, 3, 0x44, 0x33, 0x25, 0x3, 16, 0x22, 44, 33, 22 Ins.Ebtesam AL-Etowi

12 Ins.Ebtesam AL-Etowi Words
Hex Value (show the correct number of digits! 8 hex digits = 32 bits = 1 word) 25 3 0x44 0x33 0x25 0x3 16 0x22 44 33 22 Ins.Ebtesam AL-Etowi

13 Cont…. ".data" is an assembler directive (instruction to the assembler) that tells the assembler we are in the data segment of memory. ".word" is an assembler directive that tells the assembler to store the following into subsequent words in memory. The 0x values are in hex. The other values are in decimal. The data segment of memory begins at address 0x Ins.Ebtesam AL-Etowi

14 Cont..)) Questions Question 8:Now that you understand what you are looking at, fill out the above table (if you have already filled out that table, then you are done!) (show the correct number of digits! 8 hex digits = 32 bits = 1 word) Ins.Ebtesam AL-Etowi

15 Cont….. 25 0x 3 0x 0x44 0x 0x33 0x 0x25 0x 0x3 0x 16 0x 0x22 0x 44 0x C 33 0x 22 0x Ins.Ebtesam AL-Etowi

16 Questions Question 9: 2A8E + CBF3 ???? Answer: F681 Question 10: : Does each box shown in the data segment window represent a byte or a word? Please explain. Answer: A word. It packs four bytes into a word and shows it on each of the boxes. Ins.Ebtesam AL-Etowi

17 exercise to perform the following: If (n1>n2) n2= 0x5 true Else
Add it n1+n2 true in .data n1 =8 n2 =11 Ins.Ebtesam AL-Etowi

18 Exercise if the condition false
Ins.Ebtesam AL-Etowi

19 Execute Ins.Ebtesam AL-Etowi

20 Exercise if the condition true
Ins.Ebtesam AL-Etowi

21 Ins.Ebtesam AL-Etowi

22 ? ? ? Ins.Ebtesam AL-Etowi


Download ppt "CS334: Memory _ Mars simulator Lab 4(part2-2)"

Similar presentations


Ads by Google