Assignment 4, due Feb 14
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
00001000: D4 12 3 LIS R4, #12 00001002: E5 654321 4 LIL R5, #654321 00001006: 32 45 5 ADD R2, R4, R5
A problem: This data fills memory locations 100016 to 100716, a total of 4 halfwords, but the assembler listing shows it as a sequence of 8-bit bytes and one 24-bit triple-byte. Show the data as a sequence of hexadecimal address-value pairs, where each value is a halfword. (0.8 points)
USE "hawk.h" ALIGN 2 ; we begin at an even address B #D3 B #01 B #13 B #C2 B #F4 B #F3
a) Disassemble this code -- that is, convert it from a sequence of B assembly directives to an equivalent sequence of SMAL Hawk machine instructions (things like ORIS R1,7 or LIL R5,7000, although neither of these is part of the answer). Assembling your sequence should load exactly the same result into memory. (0.6 points)
b) If you execute the above sequence of machine instructions, starting with the program counter pointing to the first byte and stopping after the last byte, what registers will have been changed, and to what values? (0.6 points)
Hint: You can solve this by reading and hunting through Chapter 4, or you can solve this by using the SMAL assembler to assemble the code and then loading it into the Hawk emulator and letting the emulator disassemble it and run it. You will learn the most if you do both, using one approach to check your work done using the other.
MACRO LI =dst, =const IF (const >= -#80) & (const <= #7F) LIS dst, const ELSEIF (const >= -#800000) & (c < #7FFFFF) LIL dst, const ELSE LIL dst, const >> 8 ORIS dst, const & #FF ENDIF ENDMAC
With this macro, a programmer could write LI R3, (A + B) and let the assembler decide which instruction or instruction sequence to use, depending on the value of the sum.
Note: The IF, ELSEIF, ELSE and ENDIF operations are fairly obvious. They control which part of the body of the macro gets assembled and which parts are skipped, depending on the values of the macro parameters. If that is insufficient, you are welcome to look at Chapter 5 of the SMAL32 manual for additional discussion.
Aside: So why isn't the LI macro in the hawk.h file? Because it, along with many similar macros, would raise the level of the language closer to a high level language, so you would learn less about machine architecture as you learned to program in what would end up being just a very clumsy middle-level programming language.
A problem: Write a similar macro called AI standing for add immediate. This macro would select between doing nothing (if the immediate constant was zero), using ADDSI, using ADDI or loading the constant into a register (user R1) and then using a plain ADD. Note that you may need to subdivide the "loading a constant" alternative depending on the value of the constant. Feel free to crib code for this purpose from the LI macro given above. (1 point)
Clarification: In response to a student question, the user might write AI R3,VALUE, and depending on the value of the second operand, the macro would expand to either ADDSI R3,VALUE or ADDI R3,R3,VALUE or something else.