-
Fixed point numbers. Complete the following table; all
numbers in each column share the same base, while all
numbers in each row have the same value, fill in the blanks.
(0.2 points per blank, 2.4 total.)
Base 2 Base 8 Base 10 Base 16
1110.1011 16.54 14.6875 D.B
101.010 ___.___ ___.___ ___.___
___.___ 12.34 ___.___ ___.___
___.___ ___.___ 57.75 ___.___
___.___ ___.___ ___.___ A.E
-
Floating point numbers: Consider a system with the following odd
floating point format. Numbers are 8 bits, represented using a
biased binary exponent (assume the obvious bias) and a two's
complement binary mantissa, normalized so that the most significant
non-sign bit of the mantissa is one, with the point immediately to
the left of that bit. The format is as follows, where exp is the
exponent, s is the sign of the mantissa, and man is the
the mantissa, except for the sign bit:
_ _ _ _ _ _ _ _
|_|_|_|_|_|_|_|_|
|s| exp | man |
Give the binary values and fixed point decimal equivalents for each of the
following numbers (0.4 each, 1.6 total):
The largest
positive number. _ _ _ _ _ _ _ _ ____________
The most negative
number. _ _ _ _ _ _ _ _ ____________
The smallest nonzero
positive number. _ _ _ _ _ _ _ _ ____________
The largest nonzero
negative number. _ _ _ _ _ _ _ _ ____________
-
Programming with fixed point arithmetic: Given that all variables in
the problem are represented as 16 bit fixed point two's complement
binary numbers with with 7 bits of fraction, write code to bridge the
gap between the indicated pre and postconditions:
(3 points)
; A is in D0.W.
; B is in memory, pointed to by A0.
; C is in field F of a record in memory,
; A1 points to the record,
; the symbol F gives the offset of the field.
____________________________
____________________________
____________________________
____________________________
____________________________
____________________________
____________________________
____________________________
____________________________
; D1.W contains A*B + 2*B + C
-
Procedures and functions! The following code is missing some key
comments that would help a caller understand how to call it. Give
them (2 points):
FIBO:
; function to compute the Nth fibonacci number.
; FIBO(N) = FIBO(N-1) + FIBO(N-2)
; FIBO(1) = 1
; FIBO(0) = 0
; accepts N in ______________________________________
;
; returns FIBO(N) in ________________________________
;
; destroys __________________________________________
;
; preserves or does not use _________________________
MOVEQ.L #1,D1
CMP.L D1,D0
BLE FIBQT
MOVE.L D0,-(SP)
SUBQ.L #1,D0
JSR FIBO
MOVE.L D0,D1
MOVE.L (SP),D0
MOVE.L D1,(SP)
SUBQ.L #2,D0
JSR FIBO
ADD.L (SP)+,D0
FIBQT: RTS
-
M68000 Programming: One way to do BCD arithmetic on a binary computer
was discovered back in the late 1950's. Each 4-bit BCD digit is packed
into a 6 bit field, so a 32 bit number holds 5 BCD digits with 2 bits to
spare. To add two numbers A and B in this format, do the following:
T1 = A + B + 06666666666;
T2 = T1 & 06060606060;
SUM = T1 - (T2 | (T2 >>3));
(The above code is given in C, where the & operator means bit-by-bit
Boolean and, the >>3 operator means right shift 3 bits, and a leading
zero on a constants means that the radix is octal.) Write a properly
commented M68000 procedure called BCDADD that uses this algorithm and
conforms to the header comments given. You do not need to understand
how or why the algorithm works to solve this problem!
(4 points)
BCDADD:
; add 2 5-digit BCD numbers, packed 1 digit per 6 bits
; given A and B in D0 and D1
; returns A+B in D0
; preserves all other registers
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________