Submit one MIPS assembly language file (as an attachment replying to
the official email announcing this assignment). Name your file as
mult_div_
yourname.s
where
yourname is either your username or the name you generally go
by. (I do not care which - as long as I can easily distinguish your
programs. For example, mine could be mult_div_msiff.s
or
mult_div_mike.s
.)
Before proceeding further you should review the algorithms for multiplication and division described in the course text. (Sections 3.3 and 3.4 - pp. 183-194. Particularly figures 3.4, 3.5, 3.9, 3.11.)
Your task is to write MIPS assembly procedures to multiply and divide two 32-bit integers and test it using MARS. The scaffolding code I have provided will prompt the user to enter two integers and the compute sixteen results (based on the various combinations of negative and positive operands, and the lower- and higher-order parts of the 64-bit results) as in:
enter x (multiplicand/dividend): 41
enter y (multiplier/divisor): 5
41 * 5 (high) = 0
41 * 5 (low) = 205
41 / 5 = 8
41 % 5 = 1
-41 * 5 (high) = -1
-41 * 5 (low) = -205
-41 / 5 = -8
-41 % 5 = -1
41 * -5 (high) = -1
41 * -5 (low) = -205
41 / -5 = -8
41 % -5 = 1
-41 * -5 (high) = 0
-41 * -5 (low) = 205
-41 / -5 = 8
-41 % -5 = -1
and:
enter x (multiplicand/dividend): 65537
enter y (multiplier/divisor): 65537
65537 * 65537 (high) = 1
65537 * 65537 (low) = 131073
65537 / 65537 = 1
65537 % 65537 = 0
-65537 * 65537 (high) = -2
-65537 * 65537 (low) = -131073
-65537 / 65537 = -1
-65537 % 65537 = 0
65537 * -65537 (high) = -2
65537 * -65537 (low) = -131073
65537 / -65537 = -1
65537 % -65537 = 0
-65537 * -65537 (high) = 1
-65537 * -65537 (low) = 131073
-65537 / -65537 = 1
-65537 % -65537 = 0
For your assembly code, start with this MIPS program. It assembles and nominally runs in MARS, though it is not yet close to working correctly.
You need to implement at least:
multiplyt: takes two arguments (multiplicand and
multiplier) and returns their product in $v0
and
$v1
(high order and low order). Input arguments can be any
thirty-two-bit integer (meaning your procedure must work on negative
numbers as well as non-negative ones).
divide: takes two arguments (dividend and divisor) and
returns their integer quotient in $v0
and remainder in
$v1
. Input arguments can be any thirty-two-bit integer
(meaning your procedure must work on negative numbers as well as
non-negative ones).
You should use MARS early and often to test your code.
Unless otherwise indicated you should confine your programs to the following MIPS commands:
beq bne slt slti
add addi sub
sll srl sra
and andi or ori nor xor
j jal jr
lw sw
plus the pseudoinstructions (li
and
move
).
Your assembly-language program should be well documented - that could mean a short comment after almost every line and, certainly, larger comments as a prologue to each function.