# Assignment 2, due Jan 31

## Solutions

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). 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!

1. Background: The following SMAL code, if assembled and then packed into the Hawk memory, can be interpreted as an ASCII character string:
```        W       #756E614A
H       8#071141
B       4#1321
B       4#0201
```

a) Convert the operand on each of the above SMAL directives to binary, using correct SMAL syntax for binary numbers. (0.5 points)

```                W       2#01110101011011100110000101001010
H       2#0111001001100001
B       2#01111001
B       2#00100001
```

Some students converted to binary without bothering to use the correct SMAL syntax for binary numbers.

b) Convert it to an equivalent series of 8 SMAL B (byte) directives, one per byte, expressing the value of each byte in binary. Warning: Check the first sections of Chapter 3 to get this right. (0.5 points)

```                B       2#01001010
B       2#01100001
B       2#01101110
B       2#01110101
B       2#01100001
B       2#01110010
B       2#01111001
B       2#00100001
```

Some students didn't bother keeping SMAL syntax here, although a strict reading of the question makes it clear that they should have done so. The TA was lenient here. Of more importance, the byte order within a word (or halfword) really matters here. Many students got the order wrong.

c) Convert the result of part B to a single SMAL ASCII directive. Hint: The character string is readable English. (0.5 points)

```                ASCII	"January!"
```

Some students didn't bother with the ASCII directive and just gave the string. The TA was lenient here. Students who had difficulty with byte order, naturally, had difficulty decoding this string.

2. Background: Express each of the following decimal numbers as an 8-bit two's complement binary number. (0.1 point each)

a) –100

b) +100

c) –1

d) +50

e) –75

a) –100 = 10011100

b) +100 = 01100100

c) –1 = 11111111

d) +50 = 00110010

e) –75 = 10110101

Most did well here.

3. Background: Express each of the following decimal numbers as an 8-bit one's complement binary number. (0.1 point each)

a) –99

b) +99

c) –0

d) +49

e) –74

a) –99 = 10011100

b) +100 = 01100100

c) –0 = 11111111

d) +49 = 00110001

e) –74 = 10110101

Most did well here, but –0 caused trouble for some, and others had more general problems with negative numbers.

4. Background: Compute the 2's complement of each of the 8-bit binary numbers given here, and express that as a positive decimal number. (0.1 point each)

a) 01011101

b) 11100010

c) 01101010

d) 11110011

e) 01111011

a) –01011101 = 10100010+1 = 10100011 = 163

b) –11100010 = 00011101+1 = 00011110 = 30

c) –01101010 = 10010101+1 = 10010110 = 150

d) –11110011 = 00001100+1 = 00001101 = 13

e) –01111011 = 10000100+1 = 10000101 = 133

A fair number gave negative answers even though the question asked for the positive unsigned interpretation of the two's complement.