Assignment 1 for CSCI 431

  1. In this problem you are asked to write some low-level code using a very simple hypothetical machine language. You will use a fairly standard assembly language notation to represent machine code instructions.

    The hypothetical computer has instructions of the form (using assembly language notation)

    op r,d(b)
    where r and b are registers and d is a nonnegative number. The register r is an operand register, and d(b) represents the memory address (b) + d, where (b) denotes the contents of register b.

    The instruction set (op codes) is:

    ld - load the word at (b)+d into register r

    st - store the contents (word) in register r at address (b)+d

    a - add the integer at (b)+d to the integer in register r

    m - multiply the integer in register r by the integer at (b)+d

    Thus, for example, the instructions

    ld r1,4(r2)
    st r1,16(r2)
    would copy the word at (r2)+4 to (r2)+16. Assume that there are up to eight general purpose registers (r1 ... r8) to work with.

    Exercise: What code could a compiler generate for the C code

    x = y + 5;
    y = n + m;
    if the following represents the current environment (at the time the above instructions are executed), where each memory cell represents a word of 4 bytes and each byte has an address?
    
    
          ___________          |            |
         |           |         |____________|
     r1: |      -------------->|            |
         |___________|      x: |            |
                               |____________|
                               |            |
                            y: |            |
                               |____________|
                               |            |
                               |         5  |
                               |____________|
                               |            |
                            p: |         -------
                               |____________|   \
                               |            |    \       |            |
                               |            |     \      |____________|
                                                   ----->|            |
                                                      n: |            |
                                                         |____________|
                                                         |            |
                                                      m: |            |
                                                         |____________|
                                                         |            |
    

  2. For each of the following binding times for programming language components, give an example of a property in C that has the binding time.

    Language definition

    Language implementation

    Translation

    Link edit

    Load

    Execution