Homework 6

22C:18, Summer 1997

Due Monday, July 14

Douglas W. Jones
Take a look again at the file
	/group/class/22c018/highlevel.h
and consider the options for extending this file to include B 5000 style instructions for doing arithmetic. We could even go beyond this and start adding control structure macros so that the assembly language programmer never has to use a label.

  1. Look at the notes on the B 5000. What are the most important features of this machine haven't been discussed? For example, I/O wasn't discussed. What other essential features are missing from this description?

  2. Consider the following (bad) idea: This would allow us to write macros such as the following (note the use of lower case to avoid conflict with predefined Hawk symbols):
    MACRO add
      ADDSI R4,-4
      LOADS R1,R4
      LOAD  R2,R4,-4
      STORE R2,R4,-4
    ENDMAC
    
    MACRO pushimm =c
      LIL    R1,c
      STORES R1,R4
      ADDSI  R4,-4
    ENDMAC
    
    Using the above macros as style guidelines, write out enough macros based on the B5000 instruction set that you can test the following function, based on the code presented in lecture 28:
    function multiply
      ; assume the caller the parameters above the mark
      ;  x is therefore local variable 0
      ;  y is therefore local variable 1
      pushlocal 0  ; get x
      bne else     ; see if it's nonzero
      pushimm 0
      funcreturn
    else:
      pushmark     ; setup to push parameters to call
      pushlocal 1  ; get y
      pushlocal 0  ; get x
      pushimm 1
      sub          ; we're passing x-1
      paramcall multiply, 2
      pushlocal 1  ; get y
      add          ; we're returning multiply(y,x-1)+y
      funcreturn
    
    Note that there are no Hawk instructions in the above function! Even the bne instruction (note the use of lower case) is based on the B 5000 instruction -- it pops the stack top and tests the value popped, rather than just testing a register.

  3. Make a more efficient version of pushlocal that uses the proper load immediate instruction depending on the value of its parameter.

  4. Write a main program to call the procedure written above. This main program should meet the following requirements:
    1. It should demonstrate the procedure by calling it more than once
    2. It should usd DSPDEC to display the results of the call
    The main program should not use the new macros you've written. Instead, it should operate entirely in terms of the basic Hawk instruction set (the macros in hawk.macs). This main program is responsible for setting up the stack pointer and other registers before each call to multiply and before each call to DSPDEC. Note! Both functions are recursive, and they use different calling sequences!