CPTR-215 Assembly Language Programming HW#9 Due Wednesday
Finish reading chapter 6 if you have not already done so.
Suppose you need to divide two integer numbers. Some CPUs do not have
division instructions (ARM is one of those). A simple way to do division
is to repeatedly subtract a positive divisor from a positive dividend
while counting the number of times this can be done before the result
is negative. The quotient is the number of subtractions performed.
Note: to confirm understanding of the algorithm, use pencil and paper to divide
10 by 3. Starting with 10, repeatedly subtract 3 and make a list of the results
until the result becomes negative. Count the number of subtractions before
the negative result. Observe that in a program you will need to do an extra
subtraction before you know that a negative result has occurred. Your
program can then correct the results accordingly.
Write a short assembly program to demonstrate division via subtraction as
defined above. Register r1 should be loaded with the dividend and r2 with
the divisor. When the program finishes, r3 should contain the quotient and
r4 the remainder. Before writing the assembly code, design the program,
document it with either NS diagrams or a flow chart. Then code it (i.e.
create the assembly language file), assembly it, and test it.
This method requires large run times if a large number is divided by a
small number. Test your program. In particular, test it using the
following cases:
- 0x00001000 divided by 0x00000008
- 0x0f0f0f0f divided by 0x00000000
- 0x0f0f0f0f divided by 0x0000000e
Turn in: a copy of your design document and a hardcopy of your source
file (.s file). On it report if the program worked or not and if or not you
were able to use the debugger to monitor program operation. Comments
about your experience, trials, tribulations, unexpected successes, etc.
are welcome.
Larry Aamodt PhD, PE
Professor of Engineering and Computer Science
Walla Walla College
Contact:
via email: AamoLa (at) wallawalla.edu
via phone: x2058