Assignment 10 Solutions
Part of
the homework for 22C:60, Fall 2010
|
|23|22_21_20_19_18_17_16|15_14_13_12_11_10__9__8__7__6__5__4__3__2__1__0| |__|____________________|_______________________________________________| s exponent mantissa
a) Give the representation for 1.0 in this number system. (0.5 points)
0 1000001 1000000000000000 = + 0.5 × 21
The most widespread mistake here was to forget about biased numbers. When these were discussed at the start of the semester, there was a promise that they would come back to haunt us. 1000001 in the natural biased 7-bit binary number system is the representation for 1.
b) Give the representatin and equivalent decimal value of the smallest normalized number in this number system. (0.5 points)
0 0000000 1000000000000000 = + 0.5 × 2-128 = 2-129 = 1.4694 × 10-39
Note that the exponent 0000000 in the natural biased number system means -128, and note that mantissa has a precision of 16 bits or about 5 decimal digits, so it is inappropriate to give more than 5 significant figures in the decimal equivalent.
c) Give the representatin and equivalent decimal value of the smallest non-normalized non-zero number in this number system. (0.5 points)
0 0000000 0000000000000001 = + 2-16 × 2-128 = 2-144 = 4.4842 × 10-44
d) Given a floating point number in the format from problem 1 in the least-significant 24 bits of R3, write a sequence of instructions (not a subroutine, just a sequence of instructions) that computes the 2's complement integer exponent in R4 and the 2's complement binary fraction in R3. The point for this fraction should be just to the right of the sign bit. Use R4 and R5 if you need to use extra registers. (0.5 points)
MOVE R4,R3 ; copy exponent (and sign bit) TRUNC R3,16 ; extract mantissa SL R3,15 ; align mantissa as signed fraction BITTST R4,23 ; test saved sign bit BBR NOTNEG NEG R3,R3 ; if saved sign was negative, negate NOTNEG: SR R4,16 ; align exponent as an integer TRUNC R4,7 ; clean sign off of exponent ADDI R4,R4,-128 ; subtract bias from exponent
Assume the following I/O registers on the HAWK parallel port, which is designed to be far more general than the old Centronics standard:
a) When the Hawk system is powered up, the printer port control register is set to all zero, by the hardware. When the printer driver runs its initialization code, what values should it place in the printer port data and control registers assuming that you are trying to maintain compatibility with the old Centronics standard? (0.5 points)
M[FF10002416] = 0000 0000 0000 0011 0100 0011 1111 11102
M[FF10002016] = xxxx xxxx xxxx xx10 x1xx xxyy yyyy yy1x2In the above, the control register is specified first. Only the bits specifically documented as output bits are configured for output using one bits in this register. The data register is specified second. Here, the initial value of bits marked x do not matter because these bits are inputs and outside the control of the initialization routine. Bits marked y do not matter because the printer ignores these outputs when strobe is 1. Note that a printer driver could force a printer reset when the driver starts up, but that is not shown here.
It is unclear why so many students didn't try this problem, because it requires little more than clerical work.
b) Write a subroutine to output one character to a Centronics compatible printer. It will need to wait for the printer (several inputs from the printer must have specific values before an output cycle begins), then put the data into specific bits of the data register, and then manipulate one or more additional output bits while observing the printer's response. (0.5 points)
; parallel port addresses PP = #FF100020 ; DATA = #0 ; displacement to data register PPCTRL = #4 ; displacement to control register ; parallel port bit numbers PPSTROB = 1 ; output, normally 1 PPDATAB = 2 ; output, first of 8 bits PPACK = 10 ; input, normally 0 PPBUSY = 11 ; input, normally 1 PPPOUT = 12 ; input, normally 0 PPSEL = 13 ; input, normally 1 PPLF = 14 ; output, normally 1 PPERROR = 15 ; input, normally 0 PPRESET = 16 ; output, normally 0 PPPSEL = 17 ; output, normally 1 ; the print character routine PPPUTCH: ; expects R3 holds character to output ; uses R4 as pointer to parallel port ; uses R5 as temp register LIW R4,PP PPPOLL1: ; while ( -- wait for printer ready LOADS R5,R4 BITTST R5,PPACK BBS PPPOLL1 ; (ppdata.ack == 1) BITTST R5,PPBUSY BBR PPPOLL1 ; || (ppdata.busy == 0) BITTST R5,PPPOUT BBS PPPOLL1 ; || (ppdata.pout == 1) BITTST R5,PPSEL BBR PPPOLL1 ; || (ppdata.sel == 0) BITTST R5,PPERROR BBS PPPOLL1 ; || (ppdata.error == 1) ) do nothing LIL R5,(0<<PPSTROB)+(1<<PPLF)+(0<<PPRESET)+(1<<PPSEL) TRUNC R3,8 SL R3,PPDATAB ; -- construct output value with strobe OR R5,R3 STORES R5,R4 ; ppdata = constructed value PPPOLL2: ; while ( -- wait for printer acknowledge LOADS R5,R4 BITTST R5,PPACK BBR PPPOLL1 ; (ppdata.ack == 0) ) do nothing LIL R5,(1<<PPSTROB)+(1<<PPLF)+(0<<PPRESET)+(1<<PPSEL) OR R5,R3 ; (optionally keep data bits unchanged) STORES R5,R4 ; ppdata = reset strobe bit JUMPS R1 ; returnThe optional code included above to keep the data buts unchanged is optional because the value of the data bits when the strobe bit is one does not matter. The value in doing so is way outside the subject of this course -- it reduces radio frequency interference by reducing the number of unnecessary changes to the output bits.