Assignment 4, due Feb 13

Part of the homework for CS:2630, Spring 2015
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

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!

  1. Background: Suppose the SMAL assembly language only had a B directive, with no support for H or W. You could write a macro to define H in terms of B as follows:
         MACRO H =x
           B x & #FF
           B x >> 8

    Note that the & operator used here in SMAL is defined identically in C, C++, Java, Python and Perl. It means bitwise and. The term is fully defined, with examples, in Wikipedia. Similarly, in all of these languages >> is the bitwise right-shift operator.

    a) Give a SMAL definition for the W macro using a sequence of 2 calls to the above H macro. (0.3 points)

    b) Give a SMAL definition for the W macro using a sequence of 4 B directives. (0.3 points)

    c) Suppose you were programming using SMAL. How could you tell if H and W were defined as built-in directives or defined using the macros discussed above? (Ignore the possibility of more sophisticated macros). There are at least three different things a programmer could observe that, independently, would reveal the answer; for full credit, give any two. (0.4 points)

  2. Background: Assume that the variable i is stored at memory address 65536 (decimal), and you have this program fragment in C (or Python, or Java, or ...):
    i = i + 12;

    A Problem: Write SMAL Hawk code that carries out the above assignment statement. (1 point)

    Note: To do this, you will probably need a sequence of Hawk instructions, including at least one instruction from each of the following categories of instructions: load immediate, add immediate, load, and store. There are several instructions in each of category.

  3. Background: Assemble the hello-world program from chapter 5 of the notes, look at the assembly listing for this program, and then link and run it. (You may need to run it several times, studying the display of the Hawk emulator.)

    Note that, when you start the Hawk emulator, the first time you hit the r key to run the program, it runs the boot code in our minimal operating system. It stops before running the hello-world program because that program contains the directive S MAIN which tells the emulator to stop when the program counter is equal to the value of the identifier MAIN. Hitting R again will run the hello-world program.

    a) When you run the working Hello World program, where in memory does the code actually get put? The first executable instruction of this program is STORES. If you look at the assembly listing for this program when it is about to execute that instruction, that instruction will not be at at location 0, even though the assembly listing shows the location as zero. (0.5 points)

    b) Look at the assembly listing again, and you will see that every value given in the right side of the listing that differs between what you see in the Hawk emulator display and what you see in the SMAL listing is marked in the listing. What is the mark? (0.5 points)