CS334: Memory _ Mars simulator Lab 4(part2-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
Control Structures Branches comparison for conditional branches is built into instruction. Jump to lable(target) if condition true else continue Ins.Ebtesam AL-Etowi
Cont……. Jumps j target # unconditional jump to program label target Ins.Ebtesam AL-Etowi
Ins.Ebtesam AL-Etowi
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
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, 5 # $t1 = 5 ("load immediate") sw $t1, var1 # store contents of register $t1 into RAM: var1 = $t1 Ins.Ebtesam AL-Etowi
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
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 = 9 + 9 = 18 = 0x12 (1 * 16^1 + 2 * 16^0). So, write down the 2 and carry the 1. Digit 1: 1 (carry) + 0x4 + 0xA = 1 + 4 + 10 = 15 = 0xF. So, write down the F. There is no carry. Digit 2: 0xA + 0xB = 10 + 11 = 21 = 0x15 (1*16^1 + 5 * 16^0). So, write down the 5 and carry the 1. Digit 3: 1 (carry) + 0x3 + 0x4 = 1 + 3 + 4 = 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
Ins.Ebtesam AL-Etowi
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
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
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 0x10010000 Ins.Ebtesam AL-Etowi
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
Cont….. 25 0x00000019 3 0x00000003 0x44 0x00000044 0x33 0x00000033 0x25 0x00000025 0x3 0x00000003 16 0x00000010 0x22 0x00000022 44 0x0000002C 33 0x00000021 22 0x00000016 Ins.Ebtesam AL-Etowi
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
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
Exercise if the condition false Ins.Ebtesam AL-Etowi
Execute Ins.Ebtesam AL-Etowi
Exercise if the condition true Ins.Ebtesam AL-Etowi
Ins.Ebtesam AL-Etowi
? ? ? Ins.Ebtesam AL-Etowi