# Exam 1: Midterm

## Solutions and Commentary

### Exam 1

```Mean   = 6.69                    X   X
Median = 6.9                     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
^ ^
```

### Machine Problems 1 and 2

```                                               X
X
X
Mean   = 8.50                                  X
Median = 9.0                                   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
^ ^
```

### Homework Problems 1 to 6

```Mean   = 11.94
Median = 13.0                                          X
X                     X         X       X         X
___X_______X___X_______X_____X_X_X_X_X___X_X_X_X_X_X_X_X_____X___
. 3 . 4 . 5 . 6 . 7 . 8 . 9 . 10. 11. 12. 13. 14. 15. 16. 17. 18.
^   ^
```

### Overall Total Scores

```Mean   = 27.12
Median = 29.0                                  X X
X     X   X X
_____X_____X_____X_X_X___X_X_____X___X_X_X_X_X_X_X___X_X_X__
. 10. 12. 14. 16. 18. 20. 22. 24. 26. 28. 30. 32. 34. 36. 38.
^   ^
```

### Exam Scores vs Machine Problem Scores

```     |
10 |
9 |                    3
8 |                  1 1
7 |          1     1   4     Conclusion:
6 |        1         2 2
EX 5 |                2   2     Effort put into doing the
4 |        1                 machine problems pays off
3 |        1   1   1         on the exams.
2 |
1 |
0_|_______________________
|0 1 2 3 4 5 6 7 8 9 10
MP
```

## Exam Solutions

1. Fill in the following table; values in the blanks in each column derive from the given values in that column, all values in each row are derived from the given values using the same rules. (4 points)
```Bit Pattern x         011000      101000      110110     000010     110111

Unsigned decimal     ___24___    ___40___       54      ____2___   ___55___

1's complement of x  _100111_     010111     _001001_   _111101_   _001000_

2's complement of x   101000     _011000_    _001010_   _111110_   _001001_

x as a 1's comp num  ___24___    __-23___    ___-9___   ____2___      -8

x as a 2's comp num  ___24___    __-24___    __-10___       2      ___-9___
```

13 had perfect scores, 5 or more had trouble with each of the one's complement numbers, positive or negative, while 2 or more had trouble with the negative two's complement numbers.

2. Translate the following brief useless SMAL code to a sequence of bytes loaded in memory. The spaces to the right are labeled with a word and byte in word addresses; fill in the hexadecimal value that goes in that byte; leave uninitialized bytes blank. The result of assembling the first lines are given. (2 points)
```    . = 0                       ||  Address    3    2    1    0
H     #4567,#0123       ||          |----|----|----|----|
; --solved to here--        ||  000000: | 01 | 23 | 45 | 67 |
A:  W     #89ABCDEF         ||          |----|----|----|----|
ALIGN 4                 ||  000004: |(89 | AB | CD | EF)|
B:  B     C                 ||          |----|----|----|----|
C:  H     #2468             ||  000008: |    |(24 | 68)|(09)|
ALIGN 2                 ||          |----|----|----|----|
D:  B     #C,"C"            ||  00000C: |    |    |(43 | 0C)|
ALIGN 4                 ||          |----|----|----|----|
B     D,C,B,A           ||  000010: |(04)|(08)|(09)|(0C)|
END                     ||          |----|----|----|----|
||  000014: |    |    |    |    |
|----|----|----|----|
```

6 did perfect work, 2 earned no credit at all. 5 or more had difficulty with questions byte order. 5 or more had difficulty with the aligh directives. The translation of ASCII "C" posed problems for 6 or more. The label C posed special problems for at least 4.

3. a) A sequence of memory addresses and the halfwords they hold are given below in base 16. These are HAWK machine instructions. Give a symbolic representation of these machine instructions, in Hawk assembly language notation. The first line is worked for you. (1.5 points)
```                            ||   Label    Opcode     Operands
001000: 00D3        ||             LIS        R3,0
||   _____    ______     ________________
001002: E400        ||             BR         (way back somewhere)
||   _____    ______     ________________
001004: 0603        ||             BVS        (forward just beyond)
||   _____    ______     ________________
001006: 3533        ||    L:       ADD        R3,R3,R5
||   _____    ______     ________________
||   _____    ______     ________________
00100A: FD0E        ||             BGT        L
||   _____    ______     ________________
```

1 did perfect work, 5 earned no credit (2 of which left the problem blank). 8 or more had trouble with all of the branches. The ADDSI posed problems for 6. 4 gaven +15 instead of -1 as the operand on the ADDSI.

Note that there was an error in the preparation of this exam leading to an incorrect problem statement in the first two instructions. As a result, the code did not make as much sense as it was supposed to.

b) What does this do? (The answer is very short.) (0.5 points)

```__Add_up_some_numbers_or_branch_away_around_this_nonsense__
```

Most left this blank or wrote nonsense that had little connection to their answers to part a. One noticed that there was a loop adding up some numbers, the other commented correctly that, because of the error, the code began with a branch to somewhere else.

4. The following SMAL Hawk code is related to MP3 and contains several errors. The comments are correct. The program worked before it was carefully broken. Find and correct the errors. (2 points)
```        SUBTITLE "PLOT routine"
; activation record of plot
XCOORD  =       4       ; x coordinate
YCOORD  =       6       ; y coordinate  ;#### 6; should be 8
ARSIZE  =       8                       ;#### 8; should be 12

PLOT:   ; plot a recursively defined series of x marks
;   expects R3,R4 - x and y coordinate
;   conforms to usual calling conventions
STORES  R1,R2
STORE   R3,R2,XCOORD
STORE   R4,R2,YCOORD

LIL     R1,DSPAT
JSRS    R1,R1                   ; dspat( xcoord, ycoord )

LIS     R3,"x"
LIL     R1,DSPCH
JSRS    R1,R1                   ; dspch( 'x' )
ADDI    R2,R2,ARSIZE            ; #### 13; should be -ARSIZE

LOADCC  R3,R2,XCOORD            ; if ((xcoord > 0)
BLE     PLOTQT                  ; #### 3; should be BGT PLOTON
BLE     PLOTQT                  ; ||  (ycoord > 0)) {
PLOTON: