Exam 1: MidtermSolutions and Commentary
Part of
the homework for CS:2630, Summer 2018
|
Mean = 4.34 X X X X X X X X X X _________X_X_X_X_X_X_X_X_X_X_____X___X___X___ 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
Mean = 5.05 X X X X X X X X X ___X_____X___X_X_X_X_X_X_X_X_X_X___X_X___X___ 0 . 1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10
X Mean = 11.30 X X X X X X X X X X X X X _______X___X_____X___X___X_X_X___X___X_____X_ 0 . 2 . 4 . 6 . 8 . 10. 12. 14. 16. 18. 20
X Mean = 20.09 X X X X X X X X X X X X X X X X X _____X_____X_X___X___X_X_X_X_X_X_________X___ 0 . 4 . 8 . 12. 16. 20. 24. 28. 32. 36. 40
Bit pattern x | 0101011 | 0010110 | 1110011 | 1001011 | 0100001 |
---|---|---|---|---|---|
unsigned x in decimal | 43 | ___22___ | __115___ | ___75___ | ___33___ |
1's complement of x | _1010100 | 1101001 | _0001100 | _0110100 | _1011110 |
2's complement of x | _1010101 | _1101010 | 0001101 | _0110101 | _1011111 |
x as a 1's comp. number, in decimal | ___43___ | ___22___ | __-12___ | -52 | ___33___ |
x as a 2's comp. number, in decimal | ___43___ | ___22___ | __-13___ | __-53___ | 33 |
x as an ASCII character | + | __SYN___ | ____s___ | ____K___ | ____!___ |
. = 0 A = 'b' B: B A,B,C,D C = . - B ALIGN 4 D: ASCII "dc" ALIGN 4 W B H D |
|
1 did perfect work here, 5 made no attempt to answer the question, and 6 gave answers that were utterly unconnected to the assembly language source code. The remaining answers had detectable relationships to the source code and earned partial credit.
Very few seem to have carefully worked out the values of all of the identifiers before attempting to assemble the code. Doing so, you'd get a table like this:
A = 'b' = #62 B = 0 C = 4 D = 4
The ALIGN directive causes trouble for many students. Also, many made clerical errors such as mistaking the identifier B for the ASCII value 'B'. In general, student solutions to this problem disclosed the simple fact that on the order of half the class do not understand what it is that the assembler is doing, at the fundamental level of organizing the contents of memory.
SUBR: LIS R5,0 TESTR R3 BZS SUBQT SUBLP: ADD R5,R5,R4 ADDSI R3,-1 BZR SUBLP SUBQT: JUMPS R1 | scratch space |
|
Nobody did perfectly. 4 left it blank, 9 filled in lots of values that had no obvious connection to the problem. There were a smattering of clerical errors, not surprising on problems like this, but most of those earing partial credit had difficulty with branch displacements, and most were penalized for giving the bytes in reverse order.
b) What registers does it expect parameters in, what registers does it alter, and what does it return in what registers? Use a style appropriate for subroutine header comments. (2 points)
__Multiply subroutine__________________________________________________ __Expects R3, R4, two unsigned integers to multiply____________________ __Returns R5, the product (a nonstandard place for the return values)__ __Uses R3 (R4 remains unchanged)_______________________________________
MAINXLP: ; loop { -- per item in the row MOVE R3,R8 ; -- parameter x MOVE R4,R9 ; -- parameter y ADDI R2,R2,ARSIZE JSR R1,MULT ; prod = mult( x, y ) ADDI R2,R2,-ARSIZE ; -- parameter 1 already in R3 LIS R4,4 ; -- parameter 2 field width ADDI R2,R2,ARSIZE LIL R1,PUTDEC JSRS R1,R1 ; putdec( prod, 4 ) ADDI R2,R2,-ARSIZE ADDSI R8,1 ; x = x + 1 CMPI R8,10 BLE MAINXLP ; } while (x <= 10)
a) Some instructions above can be deleted with no damage to the program. Cross them out. (0.5 points)
12 did well. 2 earned no credit, 2 gave no answer. The remainder earned partial credit. Of these, three delted the pair of ADDI instructions surrounding the call to PUTDEC, two deleted the pair surrounding the call to MULT, and two deleted the LIS for the second parameter to PUTDEC. In addition, several deleted both lines crossed out in the above code but also crossed out one or both of the other ADDI instructions.
b) What addressing mode is used on the JSR instruction? (0.5 points)
___PC relative_________________________________________________________
10 did well, 4 earned no credit with answers that suggested that they were unfamiliar with the term addressing mode, and 1 left this blank. Among the remainder, several earned partial credit for calling this indexed addressing, and one each earned partial credit for omitting the word relative, for calling it displacement addressing, or other abuses of terminology.
c) Why can't that addressing mode be used to call PUTDEC? (0.5 points)
___PUTDEC is not defined in the same source file_______________________
4 did well, 12 gave answers that earned no credit, and 2 left this blank. Some earned partial credit with answers that were vague ("it's defined in another place" -- what kind of place?) or mentioned the monitor (that is "another place" but is the limitation specific to the monitor?).
d) For what likely values of ARSIZE could we use ADDSI instead of ADDI (0.5 points)
___4 and 8_____________________________________________________________
2 gave this answer, 4 earned no credit, and 2 left this blank. The most popular way to earn no credit was to assert that ADDSI allowed any 8-bit value. In fact, it only supports 4-bit constants. Correctly documenting the range as -8 to +8 excluding zero earned only partial credit because R2 is the activation record pointer and must remain word-aligned, and also because ARSIZE is the size of the activation record and must therefore be non-negative.