Homework P&H Ch. 2


Answer the following questions about Patterson and Hennessy, Chapter 2. You only need to turn in those that have a point count assigned.

  1. What are the five categories of machine instructions in modern processors? Give an example of each.
  2. In general terms, describe how a while loop is implemented in assembly language. How does a do-while loop differ?
  3. (1 point) In general terms, describe how an if-else statement is implemented in assembly language.
  4. (1 point) Suppose that your program has a simple subprogram with label mySubprogram.
    1. What does the calling code need to do first?
    2. What is the MAL code to call the subprogram?
    3. What is the MAL code to return from the subprogram?
  5. (1 point) The following questions concern a MAL subprogram that uses a run-time stack.
    1. What kinds of information can the run-time stack contain?
    2. How does the subprogram allocate space on the run-time stack?
    3. What must the subprogram do before returning?
  6. (1 point) Suppose you have a struct in assembly language that is declared as follows:
      struct:   double  0.0   # struct.d
                float   1.0   # struct.f
                word    15    # struct.i
                byte    'x'   # struct.c
            
    1. What is the total size of struct?
    2. If the address of struct is in $t0 what is the MAL code for loading struct.d into $f2?
    3. If the address of struct is in $t0 what is the MAL code for storing $f4 into struct.f?
    4. If the address of struct is in $t0 what is the MAL code for loading struct.i into $t1?
    5. If the address of struct is in $t0 what is the MAL code for storing $t2 into struct.c?
  7. (1 point) An array with 120 entries is declared statically in MAL by the following code:
          A:        double  1.0:120
            
    1. What is the MAL code to put the base address of A into $t0?
    2. If an entry's index is in $t1 what is the MAL code to put the address of the entry into $t2?
    3. What is the MAL code to load the entry into $f4?