Assignment 11 Solutions
Part of
the homework for 22C:60 (CS:2630), Spring 2012
|
a) Why does the code use LOAD R4,PKBD instead of LIL R4,#FF100000? (0.4 points)
The LIL instruction can only load a 24 bit constant, while the constant we need is #FF100000, a value that requires 32 bits. We could also have used the LIW macro.
b) Rewrite the code of KBDGET so that it calls an external subroutine called BEEP whenever there is a read error from the keyboard. In the event of a read error, it should still return the character it read. The requirement to call BEEP does not change this basic requirement. Presumably, BEEP causes some kind of audible alert so that a touch typist will be warned of a potential error. (Note: This problem is as much about activation records and local variables as it is about I/O). (0.6 points)
;RETAD = 0 ARSIZE = 4 KBDGET: ; link through R1 ; returns R3 = keyboard ; uses R4 STORES R1,R2 LOAD R4,PKBD ; R4 = pointer to keyboard interface KBDPOLL: ; do { LOAD R3,R4,KBDSTAT BITTST R3,KSTATER BBR KBDNOER ; if ((kbdstat & kstater) != 0) { ADDSI R2,R2,ARSIZE LIL R1,BEEP JSRS BEEP ; beep ADDSI R2,R2,-ARSIZE LOAD R4,PKBD ; R4 = get pointer wiped out by beep LOAD R3,R4,KBDSTAT ; R3 = get status wiped out by beep KBDNOER: ; } BITTST R3,KSTATRD BBR KBDPOLL ; } while ((kbdstat & kstatrd) == 0); LOAD R3,R4,KBDDATA LOADS R1,R2 JUMPS R1 ; return kbddata;Note that the call to BEEP was the easy part. The harder part was recognizing that adding this call forced the use of an activation record and wiped out information that was already in registers.
![]()
The circuit is a flipflop. It remembers when the R and S inputs are zero. Putting a positive pulse on S sets the Q output to one (that input is named S because it sets the flipflop) and putting a positive pulse on R sets the Q output to zero (the input is named R because it resets the flipflop).
A Question: The second figure implements the behavior of the circuit shown in the first figure, but they are not the same! In the first figure, the Q output of the master stage is ignored by the slave stage, while in the second, the corresponding output is not ignored. This change involves an optimization. What was saved by using the Q output of the master stage? (0.4 points)
![]()
The above drawing shows what you would get by substituting the logic for a type-D latch in place of master and slave stages given in the first figure in the text. The difference from the second figure is marked above by a pair of asterisks. One marks a not gate that is not present in the second figure in the text, while the other marks a connection that was present in the second figure but is deleted above.
In effect, the second figure given in the text represents a slight optimization, deleting the not gate starred above because its output will always be equal to the Q output of the master stage of the flipflop.
h) The error flipflop given in the diagram for the Hawk keyboard status and control register in Chapter 12 of the notes gets reset whenever there is a keypress (or rather, a zero to one transition on the keypress input from the keyboard) and the ready bit was not already set at that instant. The keypress pulse from the keyboard will also set the ready bit.
o) The bitblt() operation takes, as parameters, the following:
- source array starting address
- source array width
- source array height
- x coordinate of area to copy in source array
- y coordinate of area to copy in source array
- destination array starting address
- destination array width
- destination array height
- x coordinate of area to copy in destination array
- y coordinate of area to copy in destination array
- width of area to copy
- height of area to copy
Nothing in the chapter specifies the order of these parameters, so that is not given here. The coordinates of the area to copy are also not clearly identified with any particular location on the area. They could be the coordinates of the center or the coordinates of some corner, probably the corner with the lowest-valued coordinates. However you do it, however, the total number of parameters adds up to 2 pointers and 10 integers.