Assignment 4 Solutions
Part of
the homework for 22C:60, Fall 2010
|
Always write your name legibly as it appears on your University ID and on the class list!
001000: D1 001001: 01 001002: E2 001003: 02 001004: 00 001005: 00 001006: 33 001007: 12 001008: F4 001009: F1 00100A: 14 00100B: C3 00100C: F5 00100D: 62 00100E: 03 00100F: 00
a) Give equivalent SMAL/Hawk assembly notation for this sequence of instructions. (1 point)
This problem is worth a long discussion. It can be solved entirely by hand. You learn the most about the machine this way, and you'll need to do this on some of the exams. The first halfword in memory is at address 100016 and it has the value 01D116. When loaded in the instruction register, this would be shown as 1101 0001 0000 0001, to use the format for the instruction register used throughout the Hawk manual. Looking this up in the manual, we find that it is the instruction LIS R1,1. You can continue like this through the entire example.
It is also possible to use automated tools, the SMAL assembler and Hawk emulator, to help. The following SMAL code loads this sequence of bytes in memory:
. = #001000 ; Load starting here, and S . ; later, run starting here. B #D1,#01,#E2,#02 ; The data to load! B #00,#00,#33,#12 B #F4,#F1,#14,#C3 B #F5,#62,#03,#00
I could have typed the above one byte per line, but I was lazy, so I compacted the data by giving 4 bytes per line. Then, I assembled it and loaded it into the Hawk memory. Here is what the Hawk emulator displayed after I hit the "s" key 6 times to run the 6 instructions the emulator showed:
HAWK EMULATOR /------------------CPU------------------\ /----MEMORY----\ PC: 00001010 R8: 00000000 001000: LIS R1,#01 PSW: 00000000 R1: 00000001 R9: 00000000 001002: LIL R2,#000002 NZVC: 0 0 0 0 R2: 00000002 RA: 00000000 001006: ADD R3,R1,R2 R3: 00000003 RB: 00000000 001008: MOVE R4,R1 R4: 00000004 RC: 00000000 00100A: ADDSI R4,#3 R5: 00000005 RD: 00000000 00100C: LEACC R5,R2,#0003 R6: 00000000 RE: 00000000 ->001010: NOP R7: 00000000 RF: 00000000 001012: NOP
From the above, we can now answer parts a and b.
LIS R1,1 LIL R2,2 ADD R3,R1,R2 MOVE R4,R1 ADDSI R4,3 ADDI R5,R2,3b) What registers does this sequence of instructions change, and what values does it place in those registers? (1 point)
R1 = 1 R2 = 2 R3 = 3 R4 = 4 R5 = 5
There are many solutions. Here are a collection of them:
SHORTEST: LOAD R4,R3,4 LONGER: ADDI R4,R3,4 LOADS R4,R4 EVENLONGER: MOVE R4,R3 ADDSI R4,4 LOADS R4,R4 ANOTHER: LIS R4,4 ADD R4,R3,R4 LOADS R4,R4