29.2k views
0 votes
In this lab you will implement an algorithm for word-size signed integer division.

Given 4 word-size values N (numerator), D (denominator), Q (quotient), and R (remainder). Signed integer division has 4 cases:

N/D = QrR, -N/D = -Qr-R, N/-D = -QrR, -N/-D = QrR

The above can be implemented as follows:

Initialize sign case =0( positive N, positive D).


If N<0
then: apply 2's complement to make it positive increment sign case.

endif
If D<0
then: apply 2 's complement to make it positive sign case = sign case +2
endif
while (N≥D)
N=N−D
Increment Q
endw
R=N
if case =1
then: apply 2 's complement Q and R
elseif case =2
then: complement Q
endif




A word is made up of 2 bytes. To apply 2's complement to a word, complement each byte separately, then add 1. Create a special check for D=0. If D=0 then you can skip the while and write Q=0,N=0 to represent NaN (Not-a-Number). A similar check can be done for D=1 for faster/efficient programming. Recommendation: Start by implementing the above algorithm for integer byte. Submitting an integer bvte implementation of the assignment constitutes 85% effort.

User Snowcamel
by
8.6k points

1 Answer

4 votes

Final answer:

The question involves creating a signed integer division algorithm, accounting for sign, applying 2's complement, and managing special cases like division by zero (NaN) and one for efficiency.

Step-by-step explanation:

The question pertains to implementing an algorithm for word-size signed integer division, focusing on handling different sign cases for both the numerator and the denominator. In computing, such algorithms are crucial for ensuring accurate arithmetic operations.

The lab outlines steps involving checking the sign, applying 2's complement, and correctly calculating the quotient and remainder based on the value of the denominator. Special checks for division by zero (yielding NaN, Not-a-Number) and division by one for efficiency are also mentioned.

Additionally, rules for significant figures in division are highlighted, where the final result should be reported with the same number of significant figures as the number with the least in the operation.

User Acrophobia
by
8.2k points