Assignment 9, due Oct 31
Part of
the homework for CS:2630 (22C:60), Fall 2014
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper Homework is due on paper at the start of class on the day indicated (usually Friday). 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!
Some of these symbols are absolute, some are relocatable. In order to answer the following, questions, you will need to work out which is which.EXT A INT B B: W 5 C = 5 D = . COMMON E,4
For each of the following expressions, is it legal? Yes or no. If it is legal and absolute, what is the value of the expression? If it is legal and relocatable, what is its value relative to what relocation base? If it is illegal, what is the problem? (0.2 points each)
a) A + 1
b) B + A
c) C - B
d) D + C
e) E - D
Note: This topic is discussed in Chapters 5 and 10 of the notes, and in Sections 2.3 and 4 of the SMAL manual.
; bigint.h ; interface specification for bigint.a, high precision integer arithmetic BIGINTSZ = 16 ; size in bytes of an bigint object ; note: this is set for 128 bit objects, ; but this can be changed for other versions EXT BIGADD ; bigadd(a,b,c): a = b + c EXT BIGSUB ; bigsub(a,b,c): a = b - c EXT BIGMUL ; bigmul(a,b,c): a = b * c EXT BIGDIV ; bigdiv(a,b,c): a = b / c ; ; uses R3 = pointer to operand a ; ; uses R4 = pointer to operand b ; ; uses R5 = pointer to operand c
Note that one thing you probably want to be able to do is write applications that use the bigint package and then, later, change BIGINTSZ when you discover that the size you were using wasn't big enough (or perhaps it was too big).
a) Write SMAL code to declare a global variable called X that is a bigint. (0.5 points)
b) Here is the SMAL code for an activation record of a subroutine:
;RETAD = 0 ; the return address INDEX = 4 ; a 32 bit integer ARSIZE = 8
Rewrite the activation record to include two local variables that hold bigints, one called Y and the other called Z. Your code should be resiliant enough that the activation record automatically rearranges itself if someone changes BIGINTSZ. (0.5 points)
c) Write SMAL Hawk code to call bigsub(x,y,z). Assume that R2 usage has not been optimized. The variables x, y and z are the variables you defined in parts a and b above. (0.5 points)
;RETAD = 0 ; the return address INDEX = 4 ; a 32 bit integer ARSIZE = 8
With a bit of cleverness, we could solve problem 2b above by writing activation records like this, instead:
NEWAR LOCAL INDEX,INTSIZE LOCAL Y,BIGINTSZ LOCAL Z,BIGINTSZ
The net effect of these macros should be that ARSIZE is set correctly and the identifiers INDEX, Y and Z are defined just as they were by your answer to problem 2b.
A Problem: Write the code for the macros NEWAR and LOCAL. (0.5 points)