Lab 6
Conditional Branching
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 ~N D = Qr R, D =~Qr - R, ~D = ~Qr R ~D = Qr R
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 an integer byte. Submitting an integer byte implementation of the assignment constitutes 85% effort: