# Assignment 11, due Apr 18

## 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: Consider this specification for a digital logic circuit, given in Boolean algebra:

d = bc

Assume that each logic element, and, or, nand, nor and not has a propagation delay of exactly one nanosecond, where this matters.

a) Draw a logic circuit for this, using the conventional graphic notation for and, or, nand, nor and not gates. Neatness, proportion and organizaiton all count. (0.5 points)

b) Complete this timing diagram, showing the output of the above circuit in response to changes in its inputs:

```  | ._._._. . . . . . . . . ._._._._._._. . . ._._._._._._._._._._
a |_|     |_________________|           |_____|
| . . . . . . ._._._. . . . . . ._._._._._._._._._. . . ._._._._
b |_____________|     |___________|                 |_____|
| . ._._._. . . . . . . . . ._._._._._._. . . . . . . ._._._._._
c |___|     |_________________|           |_____________|
| . . . . . . . ._._._. . . . . . . . . . ._._._._._. . . . . .
d |_______________|     |___________________|         |___________
|_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
|             TIME -------> (each dot is one nanosecond)
```

Lines c and d above were blank in the original.

You may photocopy, cut and paste, or copy (with ruler) or use graph paper, but neatness matters. The grader will discount illegible work. (0.5 points)

c) Identify the connections to this circuit that would be conventionally labeled R, S, R, S, Q or Q if any. (0.5 points)

a is R,

b is S,

c is Q, and

d is Q.

2. Background: The Hawk monitor has separate putat and putchar routines. Consider instead this video output interface routine that combines both functions as putchat(ch,x,y). The implementation of this will begin with the following code:
```    PUTCHAT:; expects R3 = ch, a character to be plotted on the screen
;         R4 = x, the unsigned integer x coordinate
;         R5 = y, the unsigned integer y coordinate
```

The following SMAL definitions are useful in accessing the Hawk display:

```    ; memory mapped display interface
DISPBASE    = #FF000000  ; base memory address of the display interface
DISPLINES   = 0          ; - displacement of the lines interface register
DISPCOLS    = 4          ; - displacement of the columns interface register
DISPTEXT    = #100       ; - displacement to the start of video RAM
```

a) Write code to load the base address of the display interface into R6. (0.3 points)

```        LIW     R6,DISPBASE     ; there are many other solutions.
```

b) Given that the y coordinate to be used is in R5, the base address of the display interface is in R6, and R7 is available as a scratch register, write code to check that the y coordinate is on screen and branch to OFFSCR if it is not. (0.3 points)

Using unsigned comparisons gives the simplest solution:

```        LOAD    R7,R6,DISPLINES
CMP     R5,R7
BGEU    OFFSCR
```

Using signed comparisons is more complicated but equivalent so long as the number of lines on the display is under 2 billion (this seems very likely):

```        LOADCC  R7,R6,DISPLINES
CMP     R5,R7
BGE     OFFSCR
TESTR   R5
BNS     OFFSCR
```

c) Given that the base address of the display interface is in R6, write the best possible code to load the starting address of the video RAM in R8. (0.3 points)

```        LEA     R8,R6,DISPTEXT
```

Or, equivalently:

```        ADDI    R8,R6,DISPTEXT
```

d) Given that the address of the video RAM is in R8, the base address of the display interface is in R6, and the y coordinate is in R5, write code to compute the starting address in video RAM of the display line at that y coordinate and leave that address in R8. This will involve a call to the TIMESU monitor routine. (0.3 points)

```        LOAD    R4,R6,DISPCOLS