Technische Informatik

 

Fixed Point Arithmetic in Java

Kontakt  

Initial User Hints


To use and understand the different visualization steps some adaptation will be required. From the start page two choices are offered: either open directly one of the four algorithmic procedures or address first a common input page providing also decimal input. In both cases four different micro procedures can be selected: fixed-point multiplication or division, either in sign/ magnitude or two’s complement representation. Since a register length of 8 bits has been provided, corresponding fields for data input on the input page represent the contents of the A, M and Q registers. Notice that A . M produce a double length product in A.Q, whereas the dividend in A.Q divided by the contents of M produce the quotient in Q and leave the remainder in A.

Therefore, the visualization pages for the 4 cases show each block diagram together with its microprogram. Additional flag registers provide control information necessary: sign of the operands as well as of the intermediate and final result components.

On the input page data may be entered either in decimal form with an optional leading plus or minus sign, or in binary form restricted to binary digits. Illegal input characters invalidate the corresponding input number flushing the field. Due to incompatibilities in keyboards it may be necessary to try input of the minus sign from the digit keys block or use "return" instead of "enter": some key will work. Incomplete entries will be extended to full word length, new entries flush the result fields. From the input page the button "direct result" triggers a microprogram run without visualization. An "error" result will appear if either the operation cannot be performed or the result cannot be represented as in case of divide by zero or number range overflow.

"Start of visualization" opens the page containing one of the four arithmetic procedures copying the data input if any. Again 6 different buttons offer choices of control. "Step" triggers the next microoperation and highlights the corresponding line in the microprogram, "clock" the next counter cycle, and "result" triggers an automatic run up to the end result. There is also a "delay" field (1000 ms) which can be increased or decreased in half second steps to adapt to the visualization speed preferred. After completion new input data may be entered, and "restart" triggers a new run of the microprogram. "Table" opens an additional tabular representation of the microoperations. This may be helpful for a detailed study of the parallel 8-bit addition or subtraction steps, as well as the auxiliary adder input register showing the temporary contents of the A register. "End" finally returns to the data input page, from where a different algorithm or other input data my be selected.


Explanations And Special Cases


Remember that the fixed print number representation used assumes the binary (or decimal) point between the sign and the first bit position. All numbers are thus between -1 and +1 excluding both values. There is only one zero representation in two’s complement form, sign/magnitude provides for either +0 or -0. If the number range is violated, an error situation will be indicated. There are four sign combinations possible determining in advance the sign of the result. Notice that a multiplication of valid inputs always produces a valid output of double length, more precisely of 15 bits, hence bit 16 will always be zero. This is not the case for division where illegal results can be produced if the divisor is smaller than the dividend.


Examples And Their Interpretation


While multiplication in all different cases of input will be easily understood, division is certainly more complicated and requires the interpretation of some example cases. Notice that the multiplication procedures are also much simpler as can be already concluded from the length of the microprograms. However, in order to be consistent with practical applications multiplication will be skipped if there is at least one factor of zero value.

Remember that under division the operation terminates if the quotient has been determined. If a remainder is nonzero its value can be calculated performing the division by the divisor. Apparently this results in a value which cannot be represented in the Q register because it is too small, hence the quotient is approximated only to its accuracy given by the register length. 8-bit registers may contain the smallest quantity of 2-7 = 1/128. The remainder, therefore, determines a correction value of the contents of the A register divided by the divisor and by 128.

An example is demonstrating this effect in detail. Enter directly in decimal notation and trigger direct result:

0.6875 : 0.9375 = 0.7265625 remainder 0.8125

In binary form this is

0.1011 000 : 0.1111 000 = 0.1011 101 remainder 0.1101 000

This is a correct result accurate to 7 binary places. Interpretation will increase the accuracy of the result:

(0.8125 : 0.9375) : 128 = 0.006770833..

Added to the quotient + 0.7265625

results in 0.733333333..

which indeed is the correct result 11/16 : 15/16 = 11/15 to be expected.

Fixed-point member representations permit an arbitrary selection of the binary point position. Hence also integer operations easily can be demonstrated. The same numbers of the example interpreted as multiples of 128 are

DVD : DVR = 11/15 = 88/120 = 93/128 + R

Solving this equation with respect to R results in

R = 88/128 — 93/128 = 13/1920 = 0.00677083

Added to the integer part 93/128 = 0.7265625 the final result can be calculated as above. (Remember: shifting the binary point both in numerator and denominator does not influence the result.)

Much easier are results without remainder, e.g.

11/16 . 14/16 = 154/256 = 77/128

0.6015625 : 0.875 = 0.6875 remainder zero

01001101 : 01110 000 = 01011 000 remainder zero

This result is accurate without correction and can also be interpreted by integer numbers.

Easy to interpret are single bit numbers representing position dependent powers of 2:

2-7: 0.5 = 2-6 remainder zero or

2-9 : 0.5 = 0 remainder 0.25

In the latter case the result is smaller than 1/128, hence there are zero 128th as a quotient. The remainder again has to be divided by the divisor resulting in 0.5 . 2<-7which is the expected result 2-8.


Signed Number Results


Changing one or both inputs to a negative number leads to a respective sign of the result according to the sign rule (plus times minus = minus, minus times minus = plus, a.s.o.). Notice, however, that a division remainder has always the sign of the dividend since it has to be divided by the divisor before being usable for correction. Hence, correction always increases the result magnitude because the Q register contains the largest representable magnitude.

back

© asfour@ira.uka.de

KIT Logo Logo Informatikfakultät top-link top