Department of Electrical and Computer Engineering Introduction to Computer Engineering I Assignment 5 Due: Monday, April 2nd at 5:00 pm Question 1: (50 points)
4
4
8
The figure shown above shows a datapath for a 4-bit x 4-bit unsigned binary multiplier adapted from the one shown in Patterson and Hennessy. The corresponding algorithm, taken literally from the text, is reproduced below. 0. Init. Place Multiplicand in Multiplicand register. Place Multiplier in lower half of Product register. Clear upper half of Product register 1. Test and Update . If the LSB of Product register is 1, add Multiplicand register to upper half of Product register and place result back in the upper half of Product register . 2. Shift. Product register shifted right one 1 bit . 3. Count. If 4th repetition then done else goto step 1.
Do the following: 1. Implement the datapath shown on the previous page in LogicWorks. The Multiplicand and Multiplier inputs are supplied using Hex keypads (i.e. there is no need for an explicit Multiplicand register). The Product register can be implemented using the Shift Reg-4 component and the ALU with the Adder-4. Since the multiplication is unsigned, you will need to take care of the carry out generated by the ALU. Logic will also have to be provided for initializing the Product register at the start of the sequence as well as latching the final product for display. Clearly identify your control lines. 2. A total of 9 clock pulses are necessary to compute the product from the 4-bit multiplier and multiplicand. You will need to synthesize a controller to supply the correct states for your control lines for each of the 9 clock pulses. Start by drawing the state diagram corresponding to this controller, and then produce the state transition table that will be used to generate the ROM program. Implement your controller and validate it with an appropriate LogicWorks simulation. 3. Combine your controller with the datapath and verify that the system functions correctly. Produce 4 examples – tracing the clock and the outputs of the product register. 4. Assume the following parameters: Tsu (reg) = 0.1 nS, Th (reg) = 0 nS, Tpd (reg) = 1 nS, Ta (ROM) = 5 nS, Tpd (ALU) = 10 nS, Tpd (all gates) = 0.1 nS. Determine the maximum frequency of operation of the circuit and produce a simulation, to scale, that validates the maximum clock frequency. Question 2 (50 points) Implement a binary division algorithm according to the following prototype, using the following convention for passing arguments on the stack. long div32(long divisor, long dividend, long *quotient, long *rmdr); addi $sp, $sp, -16 sw $4, 0($sp) sw $5, 4($sp) sw $6, 8($sp) sw $7, 12($sp) jal div32 addi $sp, $sp, 16
# # # #
divisor dividend pointer to quotient pointer to remainder
Even though argument passing on the stack has been specified, the function return is customarily placed in a register. Since there is the possibility of a divide by 0 error, the function should return a –1 in $7 if this occurs and 0 otherwise. Your algorithm must be implemented according to the datapath shown on Page 187 (Figure 3.13) of the text. Notice that the dividend is specified to be type long. We could have passed a 64- bit argument using an array (pointer), but this was avoided to keep the assignment to a
reasonable length. Implement the datapath exactly as specified in the text. When you load the remainder register, the upper 32-bits will be set to 0 and the dividend will be placed in the lower 32-bits. Your function must explicitly deal with signs. Follow a similar testing procedure to the one used in Assignment 4. Bonus (25 points) To make the algorithm more efficient, implement the Non Restoring Division (NRD) scheme outlined in the textbook (Problem 3.29 on Page 231). The basic idea behind NRD is fairly simple. If subtracting the divisor from the remainder is negative, the usual practice is to add back the divisor and shift the remainder register (left if we follow the datapath in the book). On the next iteration we again subtract the divisor. Combining these steps we get: (remainder + divisor) x 2 – divisor 2 x remainder + 2 x divisor – divisor = 2 x remainder + divisor
What this amounts to is we can skip the adding back (restore) step is we simply add instead of subtract on the NEXT iteration. As before, make sure that your algorithm functions correctly for a sufficient number of test cases. It is strongly suggested that you first prototype your algorithm in “C” to work the bugs out and then translate to assembler. Validate your algorithm by running the test set you used for Question 2. If everything is implemented correctly, you should get identical results. fpf/March 18, 2007
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Question 1 a) Datapath implementation using parts from the standard LogicWorks library.
There are 2 datapath control signals, Init and Ld, both of which are active 0. When Init is asserted (i.e. 0), the upper product register is cleared and the lower product register is loaded with the multiplier (lower hex keypad). Init is asserted on the first clock pulse, and de-asserted (1) for the remainder of the cycle. The Ld signal determines whether the product register shifts or loads. Ld is asserted on the first clock pulse (initialization), and then at each ALU operation (pulses 0, 1, 3, 5, 7). An additional D-FF is needed to save the carry out so that it can be shifted in to the product register on the subsequent clock pulse. By connecting P0 to the select line of the multiplicand register (i.e. the hex keypad), adding 0 or adding the multiplicand is handled automatically. Finally, we observe that the Init signal marks both the end of the current cycle and the start of a new one. Hence the Init signal is used to load the two display registers which latch the result from the product register.
ECSE 221 Introduction to Computer Engineering 1 Question 1 cont. b) Finite State Machine
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Question 1 cont. State Transition Table Q3 Q2 Q1 Q0 Q3^ Q2^ Q1^ Q0^ Ld Init ROM 0 0 0 0 0 0 0 1 0 0 04 0 0 0 1 0 0 1 0 0 1 09 0 0 1 0 0 0 1 1 1 1 0F 0 0 1 1 0 1 0 0 0 1 11 0 1 0 0 0 1 0 1 1 1 17 0 1 0 1 0 1 1 0 0 1 19 0 1 1 0 0 1 1 1 1 1 1F 0 1 1 1 1 0 0 0 0 1 21 1 0 0 0 0 0 0 0 1 1 03 d d d d d d d d d d 00 d d d d d d d d d d 00 d d d d d d d d d d 00 d d d d d d d d d d 00 d d d d d d d d d d 00 d d d d d d d d d d 00 d d d d d d d d d d 00 Implementation:
Implementation using ROM + register
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Question 1 cont. c) Multiplier Implementation
Controller + Datapath
4 examples 9 x 2 = 12
9 x A = 5A
7 x A = 46
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Question 1 cont. d) Timing Analysis and Demonstration Tclock = Tsu(max) + Tpd(max) + Tcl = 0.1 nS + 1 nS + Tcl Tcl = Tpd(Add) + Tpd(AND) = 10.1 ns Tclock = 11.2 nS
Fmax = 89.29 Mhz
Simulation: Scale by 10. Show correct function with Tclock = 112 units, and incorrect with 111.
Correct answer F x F = E1 with Tclock = 112 units
ECSE 221 Introduction to Computer Engineering 1 Question 1 cont. d) Multiplier simulation cont.
Incorrect answer F X F = C5 with Tclock = 111 units
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# Assignment 5, Question 2 #----------------------------------------------------------------------------#----------------------------------------------------------------------------# long div(long divisor, long dividend, long *quotient, long *remainder); # # Function: Implements restoring devision using the algorithm # and datapath described in Patterson and Hennessy. # Arguments are passed on the stack as follows: # # $sp+0 long divisor # $sp+4 long dividend # $sp+8 long *quotient # $sp+12 long *remainder # # Status is returned in $7 as follows: # # 0 success # -1 divide by 0 # # Date: April 7, 2004 # # November 30, 2005 - modified shifting of # rmdr(high) to correct potential sign change. # # March 21, 2007 # # Modified according to prototype in Winter # 2007 Assignment 5. # #----------------------------------------------------------------------------.text #----------------------------------------------------------------------------# Save context of caller #----------------------------------------------------------------------------div437: addi sw sw sw sw sw sw sw sw sw
$sp, $18, $19, $20, $21, $22, $23, $24, $25, $fp,
$sp, -36 0($sp) 4($sp) 8($sp) 12($sp) 16($sp) 20($sp) 24($sp) 28($sp) 32($sp)
# # # # # # # # # #
Allocate space for 9 registers Save $18 - divisor Save $19 - loop counter Save $20 - remainder high Save $21 - remainder low Save $22 - sign quotient Save $23 - scratch Save $24 - scratch Save $25 - sign remainder Save frame pointer
#----------------------------------------------------------------------------# Get a pointer to the stack frame and get arguments. #----------------------------------------------------------------------------addi lw
$fp, $sp, 36 $18, 0($fp)
# Point to base of stack frame # Get divisor
#----------------------------------------------------------------------------# Check for zero divisor and exit if it's 0.
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------li beq li
$6, -1 $18, $0, div_90 $6, 0
# Initialize status to FAIL # Exit if zero divisor # Initialize return status to SUCCESS
#----------------------------------------------------------------------------# Check for trivial case of zero dividend. #----------------------------------------------------------------------------li li lw beq move
$20, $21, $23, $23, $21,
0 0 4($fp) $0, div_80 $23
# # # # #
Rmdr high 0 #----------------------------------------------------------------------------li li b
$22, 0 $25, 0 div_25
# Quotient is positive # Remainder is positive # To main loop
#----------------------------------------------------------------------------# Case 2 - dividend > 0 and divisor < 0 #----------------------------------------------------------------------------div_05: li li neg b
$22, 1 $25, 0 $18, $18 div_25
# # # #
Quotient is negative Remainder is positive Negate the divisor To main loop
#----------------------------------------------------------------------------# Cases where the dividend is negative #----------------------------------------------------------------------------div_10: bltz
$18, div_15
# Determine sign of divisor
#----------------------------------------------------------------------------# Case 3 - dividend < 0 and divisor > 0 #----------------------------------------------------------------------------li li neg b
$22, 1 $25, 1 $21, $21 div_25
# # # #
Quotient is negative Remainder is negative Negate dividend To main loop
#----------------------------------------------------------------------------# Case 4 - dividend < 0 and divisor < 0 #----------------------------------------------------------------------------div_15: li
$22, 0
# Quotient is positive
ECSE 221 Introduction to Computer Engineering 1 li neg neg
$25, 1 $18, $18 $21, $21
Solutions Assignment 5
# Remainder is negative # Negate divisor # Negate dividend
#----------------------------------------------------------------------------# Initialize loop counter, remainder (pre-shift), shift flag. # Set sign flag to 0 (positive remainder). #----------------------------------------------------------------------------div_25: li sll li
$19, 32 $21, $21, 1 $23, 0
# Initialize loop counter # Since +ve, can't have 1 in msb # Shift flag 0 if last pass +ve
#----------------------------------------------------------------------------# Main body - restoring division. #----------------------------------------------------------------------------div_30: subu slt beq addu
$20, $23, $23, $20,
$20, $18 $20, $0 $0, div_40 $20, $18
# # # #
rmdr(high) -= divisor Negative? No, skip the restore Yes, restore
#----------------------------------------------------------------------------# Do not shift rmdr(high) on the last iteration. This gets # around the need to do a final right shift and also fixes a # sign bug. #----------------------------------------------------------------------------div_40: slti bne sll li and beq ori div_50: sll
$24, $24, $20, $24, $24, $24, $20, $21,
$19, 2 $0, div_50 $20, 1 0x80000000 $21, $24 $0, div_50 $20, 1 $21, 1
# # # # # # # #
Last iteration? Yes, skip rmdr(high) shift No, shift rmdr(high) left by 1 Get bit-31 mask Extract msb of rmdr(low) Skip bit fix if msb = 0 Set lsb of rmdr(high) Now shift rmdr(low) left 1
#----------------------------------------------------------------------------# Following the model of P&H, the quotient is incrementally shifted # into the lsw of the remainder. #----------------------------------------------------------------------------bne ori
$23, $0, div_60 $21, $21, 1
# Negative result? # No, so shift a 1 into the lsb
#----------------------------------------------------------------------------# End of loop processing #----------------------------------------------------------------------------div_60: addi bne
$19, $19, -1 $19, $0, div_30
# Decrement loop counter # Back to the top if not done yet
#----------------------------------------------------------------------------# Set the appropriate signs for quotient and remainder #----------------------------------------------------------------------------beq neg div_70: beq neg
$22, $21, $25, $20,
$0, div_70 $21 $0, div_80 $20
# # # #
Negate quotient? Yes Negate remainder? Yes
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# Transfer the result to the return registers, restore, and return. #----------------------------------------------------------------------------div_80: lw sw lw sw
$23, $21, $23, $20,
8($fp) 0($23) 12($fp) 0($23)
# # # #
Get pointer to quotient Store quotient at pointer location Get pointer to remainder Store remainder at pointer location
div_90: lw lw lw lw lw lw lw lw lw addi jal
$18, $19, $20, $21, $22, $23, $24, $25, $fp, $sp, $31
0($sp) 4($sp) 8($sp) 12($sp) 16($sp) 20($sp) 24($sp) 28($sp) 32($sp) $sp, 36
# # # # # # # # # # #
Restore $18 Restore $19 Restore $20 Restore $21 Restore $22 Restore $23 Restore $24 Restore $25 Restore frame pointer Restore $sp And return
#----------------------------------------------------------------------------# Division test program. Run through array of test cases and # compare against internally computed value. #-----------------------------------------------------------------------------
.globl main main:
la la li
$10, DividendA $11, DivisorA $12, 122
la $4, hdr1 li $2, 4 syscall
# Pointer to dividend array # Pointer to divisor array # Array size = 122 # Get banner # Print string code
#----------------------------------------------------------------------------# Main loop - get test values, call function, use internal # divide, print results. #----------------------------------------------------------------------------main10: lw lw
$13, 0($10) $15, 0($11)
# Get dividend # Get divisor
move $4, $13 li $2, 1 syscall
# Print dividend
la $4, dstr li $2, 4 syscall
# Print " / "
move li
# Print divisor
$4, $15 $2, 1
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
syscall la $4, estr li $2, 4 syscall
# Print " = "
#----------------------------------------------------------------------------# Set up call to division function #----------------------------------------------------------------------------addi sw sw la sw la sw jal addi
$sp, $sp, -16 $15, 0($sp) $13, 4($sp) $16, quot $16, 8($sp) $16, rmdr $16, 12($sp) div437 $sp, $sp, 16
# # # #
Allocate parameter block Divisor Dividend *quotient
# *rmdr # Execute call # Restore stack
#----------------------------------------------------------------------------# Divide by zero #----------------------------------------------------------------------------beq la li syscall b
$6, $0, main20 $4, dzero $2, 4
# To output processing # Print error message
main30
# To end of iteration
#----------------------------------------------------------------------------# Print results #----------------------------------------------------------------------------main20: la $16, quot lw $4, 0($16) li $2, 1 syscall
# Get quotient and print
la $4, rstr li $2, 4 syscall
# Print remainder header
la $16, rmdr lw $4, 0($16) li $2, 1 syscall
# Print remainder
la $4, cstr li $2, 4 syscall
# Print next header
#----------------------------------------------------------------------------# Compute quotient and remainder using native function #----------------------------------------------------------------------------div
$13, $15
# Do division
mflo li
$4 $2, 1
# Print quotient
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
syscall la $4, rstr li $2, 4 syscall
# Print remainder string
mfhi $4 li $2, 1 syscall
# Print remainder
la $4, crlf li $2, 4 syscall
# Print newline
#----------------------------------------------------------------------------# End of loop #----------------------------------------------------------------------------main30: addi addi addi bne
$10, $11, $12, $12,
$10, 4 $11, 4 $12, -1 $0, main10
# # # #
Point to next dividend Point to next divisor Decrement loop counter To top of loop
#----------------------------------------------------------------------------# Return to monitor #----------------------------------------------------------------------------li $2, 10 syscall
#----------------------------------------------------------------------------# Data segment #----------------------------------------------------------------------------.data hdr1: crlf: dstr: estr: rstr: dzero: cstr:
.asciiz .asciiz .asciiz .asciiz .asciiz .asciiz .asciiz
"Binary division using restoring method.\n" "\n" " / " " = " ", remainder " " ---> Divide by 0!\n" ", correct quotient = "
#----------------------------------------------------------------------------# Storage for local variables #----------------------------------------------------------------------------.align 2 quot: rmdr:
.word 0 .word 0
#----------------------------------------------------------------------------# Test data set (from question 1) #----------------------------------------------------------------------------.align 2
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# DIVIDEND ARRAY #----------------------------------------------------------------------------DividendA: #----------------------------------------------------------------------------# 1. Correct sign handling, division by 1 and 0 #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word
2147483647 -2147483647 2147483647 -2147483647 2147483647 -2147483647 2147483647 -2147483647 2147483647 0
#----------------------------------------------------------------------------# 2. Test on byte boundaries #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word
1 256 256 65536 1 1 16777216 2147483647 2147483647 2147483647 2147483647 2147483647
#----------------------------------------------------------------------------# 3. 100 random samples drawn from [0,2147483647] / [0,65536] #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
944443673 674776536 844475506 257153902 984831608 2006257647 344242357 510844071 2076374925 1869129020 294226502 923774556 1578203367 743269791 334175463 907207743 1052803830 989495678
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
967847003 1936192355 638673832 1488593688 2110950187 859151333 1342608973 807207925 901637773 1704826654 1814025612 1333160708 416382433 1222360039 503397988 2000560015 1407742221 1347148249 852946046 1407059088 798022172 1277029866 1538763080 1667308906 399226769 2110351082 1510900034 246129159 784634457 1217135320 1447293666 2065098459 773762347 562145871 105823692 1505079447 1611725630 927441033 1724485934 2030365876 1292758148 1875721321 1573355288 2064526351 1188434561 1842462614 1460726645 765911934 932953951 1324183793 1928980924 1698924126 1438822343 586452361 1152880235 191043924 878476109 1952039762 706426132 1282414483
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
Solutions Assignment 5
1781282389 1278929581 1744009735 1506443889 912442483 356813172 1800965051 2054285824 1868166741 953829806 2043737168 531132039 403427310 878909929 1311991283 674911782 375852979 528194936 1086741517 1162688299 733922057 660754810
#----------------------------------------------------------------------------# DIVISOR ARRAY #----------------------------------------------------------------------------DivisorA: #----------------------------------------------------------------------------# 1. Correct sign handling, division by 1 and 0 #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word
1 1 -1 -1 123456 123456 -123456 -123456 0 2147483647
#----------------------------------------------------------------------------# 2. Test on byte boundaries #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word
256 1 256 1 65536 16777216 1 2147483647 16777216 65536 32768 2147483647
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# 3. 100 random samples drawn from [0,2147483647] / [0,65536] #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
22285 23926 38766 2499 57008 17331 57203 42325 43577 651 53658 58348 45044 10881 12525 56097 53473 29973 27015 366 3222 42605 36220 13028 48062 647 49392 60290 24101 47925 59298 41405 35965 21967 25684 45815 27108 54892 27869 37076 33509 32070 45917 52864 31783 43572 9178 53937 65500 3858 35947 39148 37425 63065 48496
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
41567 5497 60027 16617 33646 27671 4722 19135 22004 3503 32657 36861 7428 49450 53409 13165 41041 3900 17780 31067 39076 31339 10581 62660 1884 39984 6042 24614 54601 29597 9644 50426 40673 41944 23115 32155 30378 4664 39871 40700 38493 30460 61756 26333 26973
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Binary division using restoring method. 2147483647 / 1 = 2147483647, remainder 0, correct quotient = 2147483647, remainder 0 -2147483647 / 1 = -2147483647, remainder 0, correct quotient = -2147483647, remainder 0 2147483647 / -1 = -2147483647, remainder 0, correct quotient = -2147483647, remainder 0 -2147483647 / -1 = 2147483647, remainder 0, correct quotient = -2147483647, remainder 0 2147483647 / 123456 = 17394, remainder 89983, correct quotient = 17394, remainder 89983 -2147483647 / 123456 = -17394, remainder -89983, correct quotient = -17394, remainder 89983 2147483647 / -123456 = -17394, remainder 89983, correct quotient = -17394, remainder 89983 -2147483647 / -123456 = 17394, remainder -89983, correct quotient = 17394, remainder 89983 2147483647 / 0 = ---> Divide by 0! 0 / 2147483647 = 0, remainder 0, correct quotient = 0, remainder 0 1 / 256 = 0, remainder 1, correct quotient = 0, remainder 1 256 / 1 = 256, remainder 0, correct quotient = 256, remainder 0 256 / 256 = 1, remainder 0, correct quotient = 1, remainder 0 65536 / 1 = 65536, remainder 0, correct quotient = 65536, remainder 0 1 / 65536 = 0, remainder 1, correct quotient = 0, remainder 1 1 / 16777216 = 0, remainder 1, correct quotient = 0, remainder 1 16777216 / 1 = 16777216, remainder 0, correct quotient = 16777216, remainder 0 2147483647 / 2147483647 = 1, remainder 0, correct quotient = 1, remainder 0 2147483647 / 16777216 = 127, remainder 16777215, correct quotient = 127, remainder 16777215 2147483647 / 65536 = 32767, remainder 65535, correct quotient = 32767, remainder 65535 2147483647 / 32768 = 65535, remainder 32767, correct quotient = 65535, remainder 32767 2147483647 / 2147483647 = 1, remainder 0, correct quotient = 1, remainder 0 944443673 / 22285 = 42380, remainder 5373, correct quotient = 42380, remainder 5373 674776536 / 23926 = 28202, remainder 15484, correct quotient = 28202, remainder 15484 844475506 / 38766 = 21783, remainder 35728, correct quotient = 21783, remainder 35728 257153902 / 2499 = 102902, remainder 1804, correct quotient = 102902, remainder 1804 984831608 / 57008 = 17275, remainder 18408, correct quotient = 17275, remainder 18408 2006257647 / 17331 = 115761, remainder 3756, correct quotient = 115761, remainder 3756 344242357 / 57203 = 6017, remainder 51906, correct quotient = 6017, remainder 51906 510844071 / 42325 = 12069, remainder 23646, correct quotient = 12069, remainder 23646 2076374925 / 43577 = 47648, remainder 18029, correct quotient = 47648, remainder 18029 1869129020 / 651 = 2871165, remainder 605, correct quotient = 2871165, remainder 605 294226502 / 53658 = 5483, remainder 19688, correct quotient = 5483, remainder 19688 923774556 / 58348 = 15832, remainder 9020, correct quotient = 15832, remainder 9020 1578203367 / 45044 = 35036, remainder 41783, correct quotient = 35036, remainder 41783 743269791 / 10881 = 68308, remainder 10443, correct quotient = 68308, remainder 10443 334175463 / 12525 = 26680, remainder 8463, correct quotient = 26680, remainder 8463 907207743 / 56097 = 16172, remainder 7059, correct quotient = 16172, remainder 7059 1052803830 / 53473 = 19688, remainder 27406, correct quotient = 19688, remainder 27406 989495678 / 29973 = 33012, remainder 27002, correct quotient = 33012, remainder 27002 967847003 / 27015 = 35826, remainder 7613, correct quotient = 35826, remainder 7613 1936192355 / 366 = 5290143, remainder 17, correct quotient = 5290143, remainder 17 638673832 / 3222 = 198222, remainder 2548, correct quotient = 198222, remainder 2548 1488593688 / 42605 = 34939, remainder 17593, correct quotient = 34939, remainder 17593 2110950187 / 36220 = 58281, remainder 12367, correct quotient = 58281, remainder 12367 859151333 / 13028 = 65946, remainder 6845, correct quotient = 65946, remainder 6845 1342608973 / 48062 = 27934, remainder 45065, correct quotient = 27934, remainder 45065 807207925 / 647 = 1247616, remainder 373, correct quotient = 1247616, remainder 373 901637773 / 49392 = 18254, remainder 36205, correct quotient = 18254, remainder 36205 1704826654 / 60290 = 28277, remainder 6324, correct quotient = 28277, remainder 6324 1814025612 / 24101 = 75267, remainder 15645, correct quotient = 75267, remainder 15645 1333160708 / 47925 = 27817, remainder 30983, correct quotient = 27817, remainder 30983 416382433 / 59298 = 7021, remainder 51175, correct quotient = 7021, remainder 51175 1222360039 / 41405 = 29522, remainder 1629, correct quotient = 29522, remainder 1629
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
503397988 / 35965 = 13996, remainder 31848, correct quotient = 13996, remainder 31848 2000560015 / 21967 = 91071, remainder 3358, correct quotient = 91071, remainder 3358 1407742221 / 25684 = 54810, remainder 2181, correct quotient = 54810, remainder 2181 1347148249 / 45815 = 29404, remainder 3989, correct quotient = 29404, remainder 3989 852946046 / 27108 = 31464, remainder 19934, correct quotient = 31464, remainder 19934 1407059088 / 54892 = 25633, remainder 12452, correct quotient = 25633, remainder 12452 798022172 / 27869 = 28634, remainder 21226, correct quotient = 28634, remainder 21226 1277029866 / 37076 = 34443, remainder 21198, correct quotient = 34443, remainder 21198 1538763080 / 33509 = 45920, remainder 29800, correct quotient = 45920, remainder 29800 1667308906 / 32070 = 51989, remainder 21676, correct quotient = 51989, remainder 21676 399226769 / 45917 = 8694, remainder 24371, correct quotient = 8694, remainder 24371 2110351082 / 52864 = 39920, remainder 20202, correct quotient = 39920, remainder 20202 1510900034 / 31783 = 47537, remainder 31563, correct quotient = 47537, remainder 31563 246129159 / 43572 = 5648, remainder 34503, correct quotient = 5648, remainder 34503 784634457 / 9178 = 85490, remainder 7237, correct quotient = 85490, remainder 7237 1217135320 / 53937 = 22565, remainder 46915, correct quotient = 22565, remainder 46915 1447293666 / 65500 = 22096, remainder 5666, correct quotient = 22096, remainder 5666 2065098459 / 3858 = 535276, remainder 3651, correct quotient = 535276, remainder 3651 773762347 / 35947 = 21525, remainder 3172, correct quotient = 21525, remainder 3172 562145871 / 39148 = 14359, remainder 19739, correct quotient = 14359, remainder 19739 105823692 / 37425 = 2827, remainder 23217, correct quotient = 2827, remainder 23217 1505079447 / 63065 = 23865, remainder 33222, correct quotient = 23865, remainder 33222 1611725630 / 48496 = 33234, remainder 9566, correct quotient = 33234, remainder 9566 927441033 / 41567 = 22311, remainder 39696, correct quotient = 22311, remainder 39696 1724485934 / 5497 = 313714, remainder 76, correct quotient = 313714, remainder 76 2030365876 / 60027 = 33824, remainder 12628, correct quotient = 33824, remainder 12628 1292758148 / 16617 = 77797, remainder 5399, correct quotient = 77797, remainder 5399 1875721321 / 33646 = 55748, remainder 24113, correct quotient = 55748, remainder 24113 1573355288 / 27671 = 56859, remainder 9899, correct quotient = 56859, remainder 9899 2064526351 / 4722 = 437214, remainder 1843, correct quotient = 437214, remainder 1843 1188434561 / 19135 = 62107, remainder 17116, correct quotient = 62107, remainder 17116 1842462614 / 22004 = 83733, remainder 1682, correct quotient = 83733, remainder 1682 1460726645 / 3503 = 416993, remainder 166, correct quotient = 416993, remainder 166 765911934 / 32657 = 23453, remainder 7313, correct quotient = 23453, remainder 7313 932953951 / 36861 = 25310, remainder 2041, correct quotient = 25310, remainder 2041 1324183793 / 7428 = 178269, remainder 1661, correct quotient = 178269, remainder 1661 1928980924 / 49450 = 39008, remainder 35324, correct quotient = 39008, remainder 35324 1698924126 / 53409 = 31809, remainder 37245, correct quotient = 31809, remainder 37245 1438822343 / 13165 = 109291, remainder 6328, correct quotient = 109291, remainder 6328 586452361 / 41041 = 14289, remainder 17512, correct quotient = 14289, remainder 17512 1152880235 / 3900 = 295610, remainder 1235, correct quotient = 295610, remainder 1235 191043924 / 17780 = 10744, remainder 15604, correct quotient = 10744, remainder 15604 878476109 / 31067 = 28276, remainder 25617, correct quotient = 28276, remainder 25617 1952039762 / 39076 = 49954, remainder 37258, correct quotient = 49954, remainder 37258 706426132 / 31339 = 22541, remainder 13733, correct quotient = 22541, remainder 13733 1282414483 / 10581 = 121199, remainder 7864, correct quotient = 121199, remainder 7864 1781282389 / 62660 = 28427, remainder 46569, correct quotient = 28427, remainder 46569 1278929581 / 1884 = 678837, remainder 673, correct quotient = 678837, remainder 673 1744009735 / 39984 = 43617, remainder 27607, correct quotient = 43617, remainder 27607 1506443889 / 6042 = 249328, remainder 4113, correct quotient = 249328, remainder 4113 912442483 / 24614 = 37070, remainder 1503, correct quotient = 37070, remainder 1503 356813172 / 54601 = 6534, remainder 50238, correct quotient = 6534, remainder 50238 1800965051 / 29597 = 60849, remainder 17198, correct quotient = 60849, remainder 17198 2054285824 / 9644 = 213011, remainder 7740, correct quotient = 213011, remainder 7740 1868166741 / 50426 = 37047, remainder 34719, correct quotient = 37047, remainder 34719 953829806 / 40673 = 23451, remainder 7283, correct quotient = 23451, remainder 7283 2043737168 / 41944 = 48725, remainder 15768, correct quotient = 48725, remainder 15768 531132039 / 23115 = 22977, remainder 18684, correct quotient = 22977, remainder 18684 403427310 / 32155 = 12546, remainder 10680, correct quotient = 12546, remainder 10680 878909929 / 30378 = 28932, remainder 13633, correct quotient = 28932, remainder 13633
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
1311991283 / 4664 = 281301, remainder 3419, correct quotient = 281301, remainder 3419 674911782 / 39871 = 16927, remainder 15365, correct quotient = 16927, remainder 15365 375852979 / 40700 = 9234, remainder 29179, correct quotient = 9234, remainder 29179 528194936 / 38493 = 13721, remainder 32483, correct quotient = 13721, remainder 32483 1086741517 / 30460 = 35677, remainder 20097, correct quotient = 35677, remainder 20097 1162688299 / 61756 = 18827, remainder 8087, correct quotient = 18827, remainder 8087 733922057 / 26333 = 27870, remainder 21347, correct quotient = 27870, remainder 21347 660754810 / 26973 = 24496, remainder 24202, correct quotient = 24496, remainder 24202
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# Assignment 5, Question 3 (Bonus) #----------------------------------------------------------------------------#----------------------------------------------------------------------------# long div(long divisor, long dividend, long *quotient, long *remainder); # # Function: Implements non-restoring devision using the algorithm # and datapath described in Patterson and Hennessy. # Arguments are passed on the stack as follows: # # $sp+0 long divisor # $sp+4 long dividend # $sp+8 long *quotient # $sp+12 long *remainder # # Status is returned in $7 as follows: # # 0 success # -1 divide by 0 # # Date: April 7, 2004 # # November 30, 2005 - modified shifting of # rmdr(high) to correct potential sign change. # # March 21, 2007 # # Modified according to prototype in Winter # 2007 Assignment 5. # #----------------------------------------------------------------------------.text #----------------------------------------------------------------------------# Save context of caller #----------------------------------------------------------------------------div437: addi sw sw sw sw sw sw sw sw sw
$sp, $18, $19, $20, $21, $22, $23, $24, $25, $fp,
$sp, -36 0($sp) 4($sp) 8($sp) 12($sp) 16($sp) 20($sp) 24($sp) 28($sp) 32($sp)
# # # # # # # # # #
Allocate space for 9 registers Save $18 - divisor Save $19 - loop counter Save $20 - remainder high Save $21 - remainder low Save $22 - sign quotient Save $23 - scratch Save $24 - scratch Save $25 - sign remainder Save frame pointer
#----------------------------------------------------------------------------# Get a pointer to the stack frame and get arguments. #----------------------------------------------------------------------------addi lw
$fp, $sp, 36 $18, 0($fp)
# Point to base of stack frame # Get divisor
#----------------------------------------------------------------------------# Check for zero divisor and exit if it's 0. #-----------------------------------------------------------------------------
ECSE 221 Introduction to Computer Engineering 1 li beq li
$6, -1 $18, $0, div_90 $6, 0
Solutions Assignment 5
# Initialize status to FAIL # Exit if zero divisor # Initialize return status to SUCCESS
#----------------------------------------------------------------------------# Check for trivial case of zero dividend. #----------------------------------------------------------------------------li li lw beq move
$20, $21, $23, $23, $21,
0 0 4($fp) $0, div_80 $23
# # # # #
Rmdr high 0 #----------------------------------------------------------------------------li li b
$22, 0 $25, 0 div_25
# Quotient is positive # Remainder is positive # To main loop
#----------------------------------------------------------------------------# Case 2 - dividend > 0 and divisor < 0 #----------------------------------------------------------------------------div_05: li li neg b
$22, 1 $25, 0 $18, $18 div_25
# # # #
Quotient is negative Remainder is positive Negate the divisor To main loop
#----------------------------------------------------------------------------# Cases where the dividend is negative #----------------------------------------------------------------------------div_10: bltz
$18, div_15
# Determine sign of divisor
#----------------------------------------------------------------------------# Case 3 - dividend < 0 and divisor > 0 #----------------------------------------------------------------------------li li neg b
$22, 1 $25, 1 $21, $21 div_25
# # # #
Quotient is negative Remainder is negative Negate dividend To main loop
#----------------------------------------------------------------------------# Case 4 - dividend < 0 and divisor < 0 #----------------------------------------------------------------------------div_15: li li
$22, 0 $25, 1
# Quotient is positive # Remainder is negative
ECSE 221 Introduction to Computer Engineering 1 neg neg
$18, $18 $21, $21
Solutions Assignment 5
# Negate divisor # Negate dividend
#----------------------------------------------------------------------------# Initialize loop counter, remainder (pre-shift), shift flag. # Set sign flag to 0 (positive remainder). #----------------------------------------------------------------------------div_25: li sll li
$19, 32 $21, $21, 1 $23, 0
# Initialize loop counter # Since +ve, can't have 1 in msb # Shift flag 0 if last pass +ve
#----------------------------------------------------------------------------# Main body - non restoring division. #----------------------------------------------------------------------------div_30: beq addu b
$23, $0, div_35 $20, $20, $18 div_40
# If last result +ve, subtract # else rmdr(high) += divisor # Proceed to set flag
div_35: subu
$20, $20, $18
# rmdr(high) -= divisor
div_40: slt
$23, $20, $0
# Set flag according to result
#----------------------------------------------------------------------------# Do not shift rmdr(high) on the last iteration. This gets # around the need to do a final right shift and also fixes a # sign bug. #----------------------------------------------------------------------------slti bne sll li and beq ori div_50: sll
$24, $24, $20, $24, $24, $24, $20, $21,
$19, 2 $0, div_50 $20, 1 0x80000000 $21, $24 $0, div_50 $20, 1 $21, 1
# # # # # # # #
Last iteration? Yes, skip rmdr(high) shift No, shift rmdr(high) left by 1 Get bit-31 mask Extract msb of rmdr(low) Skip bit fix if msb = 0 Set lsb of rmdr(high) Now shift rmdr(low) left 1
#----------------------------------------------------------------------------# Following the model of P&H, the quotient is incrementally shifted # into the lsw of the remainder. #----------------------------------------------------------------------------bne ori
$23, $0, div_60 $21, $21, 1
# Negative result? # No, so shift a 1 into the lsb
#----------------------------------------------------------------------------# End of loop processing #----------------------------------------------------------------------------div_60: addi bne
$19, $19, -1 $19, $0, div_30
# Decrement loop counter # Back to the top if not done yet
#----------------------------------------------------------------------------# If last pass resulted in a negative, we need to do a restore. #----------------------------------------------------------------------------beq addu
$23, $0, div_65 $20, $20, $18
# Skip restore is last +ve # Otherwise do it
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# Set the appropriate signs for quotient and remainder #----------------------------------------------------------------------------div_65: beq neg div_70: beq neg
$22, $21, $25, $20,
$0, div_70 $21 $0, div_80 $20
# # # #
Negate quotient? Yes Negate remainder? Yes
#----------------------------------------------------------------------------# Transfer the result to the return registers, restore, and return. #----------------------------------------------------------------------------div_80: lw sw lw sw
$23, $21, $23, $20,
8($fp) 0($23) 12($fp) 0($23)
# # # #
Get pointer to quotient Store quotient at pointer location Get pointer to remainder Store remainder at pointer location
div_90: lw lw lw lw lw lw lw lw lw addi jal
$18, $19, $20, $21, $22, $23, $24, $25, $fp, $sp, $31
0($sp) 4($sp) 8($sp) 12($sp) 16($sp) 20($sp) 24($sp) 28($sp) 32($sp) $sp, 36
# # # # # # # # # # #
Restore $18 Restore $19 Restore $20 Restore $21 Restore $22 Restore $23 Restore $24 Restore $25 Restore frame pointer Restore $sp And return
#----------------------------------------------------------------------------# Division test program. Run through array of test cases and # compare against internally computed value. #-----------------------------------------------------------------------------
.globl main main:
la la li
$10, DividendA $11, DivisorA $12, 122
la $4, hdr1 li $2, 4 syscall
# Pointer to dividend array # Pointer to divisor array # Array size = 122 # Get banner # Print string code
#----------------------------------------------------------------------------# Main loop - get test values, call function, use internal # divide, print results. #----------------------------------------------------------------------------main10: lw lw move
$13, 0($10) $15, 0($11)
# Get dividend # Get divisor
$4, $13
# Print dividend
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
li $2, 1 syscall la $4, dstr li $2, 4 syscall
# Print " / "
move $4, $15 li $2, 1 syscall
# Print divisor
la $4, estr li $2, 4 syscall
# Print " = "
#----------------------------------------------------------------------------# Set up call to division function #----------------------------------------------------------------------------addi sw sw la sw la sw jal addi
$sp, $sp, -16 $15, 0($sp) $13, 4($sp) $16, quot $16, 8($sp) $16, rmdr $16, 12($sp) div437 $sp, $sp, 16
# # # #
Allocate parameter block Divisor Dividend *quotient
# *rmdr # Execute call # Restore stack
#----------------------------------------------------------------------------# Divide by zero #----------------------------------------------------------------------------beq la li syscall b
$6, $0, main20 $4, dzero $2, 4
# To output processing # Print error message
main30
# To end of iteration
#----------------------------------------------------------------------------# Print results #----------------------------------------------------------------------------main20: la $16, quot lw $4, 0($16) li $2, 1 syscall
# Get quotient and print
la $4, rstr li $2, 4 syscall
# Print remainder header
la $16, rmdr lw $4, 0($16) li $2, 1 syscall
# Print remainder
la $4, cstr li $2, 4 syscall
# Print next header
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
#----------------------------------------------------------------------------# Compute quotient and remainder using native function #----------------------------------------------------------------------------div
$13, $15
# Do division
mflo $4 li $2, 1 syscall
# Print quotient
la $4, rstr li $2, 4 syscall
# Print remainder string
mfhi $4 li $2, 1 syscall
# Print remainder
la $4, crlf li $2, 4 syscall
# Print newline
#----------------------------------------------------------------------------# End of loop #----------------------------------------------------------------------------main30: addi addi addi bne
$10, $11, $12, $12,
$10, 4 $11, 4 $12, -1 $0, main10
# # # #
Point to next dividend Point to next divisor Decrement loop counter To top of loop
#----------------------------------------------------------------------------# Return to monitor #----------------------------------------------------------------------------li $2, 10 syscall
#----------------------------------------------------------------------------# Data segment #----------------------------------------------------------------------------.data hdr1: crlf: dstr: estr: rstr: dzero: cstr:
.asciiz .asciiz .asciiz .asciiz .asciiz .asciiz .asciiz
"Binary division using non-restoring method.\n" "\n" " / " " = " ", remainder " " ---> Divide by 0!\n" ", correct quotient = "
#----------------------------------------------------------------------------# Storage for local variables #----------------------------------------------------------------------------.align 2
ECSE 221 Introduction to Computer Engineering 1 quot: rmdr:
Solutions Assignment 5
.word 0 .word 0
#----------------------------------------------------------------------------# Test data set (from question 1) #----------------------------------------------------------------------------.align 2 #----------------------------------------------------------------------------# DIVIDEND ARRAY #----------------------------------------------------------------------------DividendA: #----------------------------------------------------------------------------# 1. Correct sign handling, division by 1 and 0 #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word
2147483647 -2147483647 2147483647 -2147483647 2147483647 -2147483647 2147483647 -2147483647 2147483647 0
#----------------------------------------------------------------------------# 2. Test on byte boundaries #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word
1 256 256 65536 1 1 16777216 2147483647 2147483647 2147483647 2147483647 2147483647
#----------------------------------------------------------------------------# 3. 100 random samples drawn from [0,2147483647] / [0,65536] #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word
944443673 674776536 844475506 257153902 984831608 2006257647 344242357 510844071 2076374925
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
1869129020 294226502 923774556 1578203367 743269791 334175463 907207743 1052803830 989495678 967847003 1936192355 638673832 1488593688 2110950187 859151333 1342608973 807207925 901637773 1704826654 1814025612 1333160708
.word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
416382433 1222360039 503397988 2000560015 1407742221 1347148249 852946046 1407059088 798022172 1277029866 1538763080 1667308906 399226769 2110351082 1510900034 246129159 784634457 1217135320 1447293666 2065098459 773762347 562145871 105823692 1505079447 1611725630 927441033 1724485934 2030365876 1292758148 1875721321 1573355288 2064526351 1188434561 1842462614 1460726645 765911934 932953951 1324183793
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
Solutions Assignment 5
1928980924 1698924126 1438822343 586452361 1152880235 191043924 878476109 1952039762 706426132 1282414483 1781282389 1278929581 1744009735 1506443889 912442483 356813172 1800965051 2054285824 1868166741 953829806 2043737168 531132039 403427310 878909929 1311991283 674911782 375852979 528194936 1086741517 1162688299 733922057 660754810
#----------------------------------------------------------------------------# DIVISOR ARRAY #----------------------------------------------------------------------------DivisorA: #----------------------------------------------------------------------------# 1. Correct sign handling, division by 1 and 0 #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word
1 1 -1 -1 123456 123456 -123456 -123456 0 2147483647
#----------------------------------------------------------------------------# 2. Test on byte boundaries #----------------------------------------------------------------------------.word 256 .word 1
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word
Solutions Assignment 5
256 1 65536 16777216 1 2147483647 16777216 65536 32768 2147483647
#----------------------------------------------------------------------------# 3. 100 random samples drawn from [0,2147483647] / [0,65536] #----------------------------------------------------------------------------.word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
22285 23926 38766 2499 57008 17331 57203 42325 43577 651 53658 58348 45044 10881 12525 56097 53473 29973 27015 366 3222 42605 36220 13028 48062 647 49392 60290 24101 47925 59298 41405 35965 21967 25684 45815 27108 54892 27869 37076 33509 32070 45917 52864 31783
ECSE 221 Introduction to Computer Engineering 1 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word
43572 9178 53937 65500 3858 35947 39148 37425 63065 48496 41567 5497 60027 16617 33646 27671 4722 19135 22004 3503 32657 36861 7428 49450 53409 13165 41041 3900 17780 31067 39076 31339 10581 62660 1884 39984 6042 24614 54601 29597 9644 50426 40673 41944 23115 32155 30378 4664 39871 40700 38493 30460 61756 26333 26973
Solutions Assignment 5
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
Binary division using non-restoring method. 2147483647 / 1 = 2147483647, remainder 0, correct quotient = 2147483647, remainder 0 -2147483647 / 1 = -2147483647, remainder 0, correct quotient = -2147483647, remainder 0 2147483647 / -1 = -2147483647, remainder 0, correct quotient = -2147483647, remainder 0 -2147483647 / -1 = 2147483647, remainder 0, correct quotient = -2147483647, remainder 0 2147483647 / 123456 = 17394, remainder 89983, correct quotient = 17394, remainder 89983 -2147483647 / 123456 = -17394, remainder -89983, correct quotient = -17394, remainder 89983 2147483647 / -123456 = -17394, remainder 89983, correct quotient = -17394, remainder 89983 -2147483647 / -123456 = 17394, remainder -89983, correct quotient = 17394, remainder 89983 2147483647 / 0 = ---> Divide by 0! 0 / 2147483647 = 0, remainder 0, correct quotient = 0, remainder 0 1 / 256 = 0, remainder 1, correct quotient = 0, remainder 1 256 / 1 = 256, remainder 0, correct quotient = 256, remainder 0 256 / 256 = 1, remainder 0, correct quotient = 1, remainder 0 65536 / 1 = 65536, remainder 0, correct quotient = 65536, remainder 0 1 / 65536 = 0, remainder 1, correct quotient = 0, remainder 1 1 / 16777216 = 0, remainder 1, correct quotient = 0, remainder 1 16777216 / 1 = 16777216, remainder 0, correct quotient = 16777216, remainder 0 2147483647 / 2147483647 = 1, remainder 0, correct quotient = 1, remainder 0 2147483647 / 16777216 = 127, remainder 16777215, correct quotient = 127, remainder 16777215 2147483647 / 65536 = 32767, remainder 65535, correct quotient = 32767, remainder 65535 2147483647 / 32768 = 65535, remainder 32767, correct quotient = 65535, remainder 32767 2147483647 / 2147483647 = 1, remainder 0, correct quotient = 1, remainder 0 944443673 / 22285 = 42380, remainder 5373, correct quotient = 42380, remainder 5373 674776536 / 23926 = 28202, remainder 15484, correct quotient = 28202, remainder 15484 844475506 / 38766 = 21783, remainder 35728, correct quotient = 21783, remainder 35728 257153902 / 2499 = 102902, remainder 1804, correct quotient = 102902, remainder 1804 984831608 / 57008 = 17275, remainder 18408, correct quotient = 17275, remainder 18408 2006257647 / 17331 = 115761, remainder 3756, correct quotient = 115761, remainder 3756 344242357 / 57203 = 6017, remainder 51906, correct quotient = 6017, remainder 51906 510844071 / 42325 = 12069, remainder 23646, correct quotient = 12069, remainder 23646 2076374925 / 43577 = 47648, remainder 18029, correct quotient = 47648, remainder 18029 1869129020 / 651 = 2871165, remainder 605, correct quotient = 2871165, remainder 605 294226502 / 53658 = 5483, remainder 19688, correct quotient = 5483, remainder 19688 923774556 / 58348 = 15832, remainder 9020, correct quotient = 15832, remainder 9020 1578203367 / 45044 = 35036, remainder 41783, correct quotient = 35036, remainder 41783 743269791 / 10881 = 68308, remainder 10443, correct quotient = 68308, remainder 10443 334175463 / 12525 = 26680, remainder 8463, correct quotient = 26680, remainder 8463 907207743 / 56097 = 16172, remainder 7059, correct quotient = 16172, remainder 7059 1052803830 / 53473 = 19688, remainder 27406, correct quotient = 19688, remainder 27406 989495678 / 29973 = 33012, remainder 27002, correct quotient = 33012, remainder 27002 967847003 / 27015 = 35826, remainder 7613, correct quotient = 35826, remainder 7613 1936192355 / 366 = 5290143, remainder 17, correct quotient = 5290143, remainder 17 638673832 / 3222 = 198222, remainder 2548, correct quotient = 198222, remainder 2548 1488593688 / 42605 = 34939, remainder 17593, correct quotient = 34939, remainder 17593 2110950187 / 36220 = 58281, remainder 12367, correct quotient = 58281, remainder 12367 859151333 / 13028 = 65946, remainder 6845, correct quotient = 65946, remainder 6845 1342608973 / 48062 = 27934, remainder 45065, correct quotient = 27934, remainder 45065 807207925 / 647 = 1247616, remainder 373, correct quotient = 1247616, remainder 373 901637773 / 49392 = 18254, remainder 36205, correct quotient = 18254, remainder 36205 1704826654 / 60290 = 28277, remainder 6324, correct quotient = 28277, remainder 6324 1814025612 / 24101 = 75267, remainder 15645, correct quotient = 75267, remainder 15645 1333160708 / 47925 = 27817, remainder 30983, correct quotient = 27817, remainder 30983 416382433 / 59298 = 7021, remainder 51175, correct quotient = 7021, remainder 51175 1222360039 / 41405 = 29522, remainder 1629, correct quotient = 29522, remainder 1629
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
503397988 / 35965 = 13996, remainder 31848, correct quotient = 13996, remainder 31848 2000560015 / 21967 = 91071, remainder 3358, correct quotient = 91071, remainder 3358 1407742221 / 25684 = 54810, remainder 2181, correct quotient = 54810, remainder 2181 1347148249 / 45815 = 29404, remainder 3989, correct quotient = 29404, remainder 3989 852946046 / 27108 = 31464, remainder 19934, correct quotient = 31464, remainder 19934 1407059088 / 54892 = 25633, remainder 12452, correct quotient = 25633, remainder 12452 798022172 / 27869 = 28634, remainder 21226, correct quotient = 28634, remainder 21226 1277029866 / 37076 = 34443, remainder 21198, correct quotient = 34443, remainder 21198 1538763080 / 33509 = 45920, remainder 29800, correct quotient = 45920, remainder 29800 1667308906 / 32070 = 51989, remainder 21676, correct quotient = 51989, remainder 21676 399226769 / 45917 = 8694, remainder 24371, correct quotient = 8694, remainder 24371 2110351082 / 52864 = 39920, remainder 20202, correct quotient = 39920, remainder 20202 1510900034 / 31783 = 47537, remainder 31563, correct quotient = 47537, remainder 31563 246129159 / 43572 = 5648, remainder 34503, correct quotient = 5648, remainder 34503 784634457 / 9178 = 85490, remainder 7237, correct quotient = 85490, remainder 7237 1217135320 / 53937 = 22565, remainder 46915, correct quotient = 22565, remainder 46915 1447293666 / 65500 = 22096, remainder 5666, correct quotient = 22096, remainder 5666 2065098459 / 3858 = 535276, remainder 3651, correct quotient = 535276, remainder 3651 773762347 / 35947 = 21525, remainder 3172, correct quotient = 21525, remainder 3172 562145871 / 39148 = 14359, remainder 19739, correct quotient = 14359, remainder 19739 105823692 / 37425 = 2827, remainder 23217, correct quotient = 2827, remainder 23217 1505079447 / 63065 = 23865, remainder 33222, correct quotient = 23865, remainder 33222 1611725630 / 48496 = 33234, remainder 9566, correct quotient = 33234, remainder 9566 927441033 / 41567 = 22311, remainder 39696, correct quotient = 22311, remainder 39696 1724485934 / 5497 = 313714, remainder 76, correct quotient = 313714, remainder 76 2030365876 / 60027 = 33824, remainder 12628, correct quotient = 33824, remainder 12628 1292758148 / 16617 = 77797, remainder 5399, correct quotient = 77797, remainder 5399 1875721321 / 33646 = 55748, remainder 24113, correct quotient = 55748, remainder 24113 1573355288 / 27671 = 56859, remainder 9899, correct quotient = 56859, remainder 9899 2064526351 / 4722 = 437214, remainder 1843, correct quotient = 437214, remainder 1843 1188434561 / 19135 = 62107, remainder 17116, correct quotient = 62107, remainder 17116 1842462614 / 22004 = 83733, remainder 1682, correct quotient = 83733, remainder 1682 1460726645 / 3503 = 416993, remainder 166, correct quotient = 416993, remainder 166 765911934 / 32657 = 23453, remainder 7313, correct quotient = 23453, remainder 7313 932953951 / 36861 = 25310, remainder 2041, correct quotient = 25310, remainder 2041 1324183793 / 7428 = 178269, remainder 1661, correct quotient = 178269, remainder 1661 1928980924 / 49450 = 39008, remainder 35324, correct quotient = 39008, remainder 35324 1698924126 / 53409 = 31809, remainder 37245, correct quotient = 31809, remainder 37245 1438822343 / 13165 = 109291, remainder 6328, correct quotient = 109291, remainder 6328 586452361 / 41041 = 14289, remainder 17512, correct quotient = 14289, remainder 17512 1152880235 / 3900 = 295610, remainder 1235, correct quotient = 295610, remainder 1235 191043924 / 17780 = 10744, remainder 15604, correct quotient = 10744, remainder 15604 878476109 / 31067 = 28276, remainder 25617, correct quotient = 28276, remainder 25617 1952039762 / 39076 = 49954, remainder 37258, correct quotient = 49954, remainder 37258 706426132 / 31339 = 22541, remainder 13733, correct quotient = 22541, remainder 13733 1282414483 / 10581 = 121199, remainder 7864, correct quotient = 121199, remainder 7864 1781282389 / 62660 = 28427, remainder 46569, correct quotient = 28427, remainder 46569 1278929581 / 1884 = 678837, remainder 673, correct quotient = 678837, remainder 673 1744009735 / 39984 = 43617, remainder 27607, correct quotient = 43617, remainder 27607 1506443889 / 6042 = 249328, remainder 4113, correct quotient = 249328, remainder 4113 912442483 / 24614 = 37070, remainder 1503, correct quotient = 37070, remainder 1503 356813172 / 54601 = 6534, remainder 50238, correct quotient = 6534, remainder 50238 1800965051 / 29597 = 60849, remainder 17198, correct quotient = 60849, remainder 17198 2054285824 / 9644 = 213011, remainder 7740, correct quotient = 213011, remainder 7740 1868166741 / 50426 = 37047, remainder 34719, correct quotient = 37047, remainder 34719 953829806 / 40673 = 23451, remainder 7283, correct quotient = 23451, remainder 7283 2043737168 / 41944 = 48725, remainder 15768, correct quotient = 48725, remainder 15768 531132039 / 23115 = 22977, remainder 18684, correct quotient = 22977, remainder 18684 403427310 / 32155 = 12546, remainder 10680, correct quotient = 12546, remainder 10680 878909929 / 30378 = 28932, remainder 13633, correct quotient = 28932, remainder 13633
ECSE 221 Introduction to Computer Engineering 1
Solutions Assignment 5
1311991283 / 4664 = 281301, remainder 3419, correct quotient = 281301, remainder 3419 674911782 / 39871 = 16927, remainder 15365, correct quotient = 16927, remainder 15365 375852979 / 40700 = 9234, remainder 29179, correct quotient = 9234, remainder 29179 528194936 / 38493 = 13721, remainder 32483, correct quotient = 13721, remainder 32483 1086741517 / 30460 = 35677, remainder 20097, correct quotient = 35677, remainder 20097 1162688299 / 61756 = 18827, remainder 8087, correct quotient = 18827, remainder 8087 733922057 / 26333 = 27870, remainder 21347, correct quotient = 27870, remainder 21347 660754810 / 26973 = 24496, remainder 24202, correct quotient = 24496, remainder 24202