CS 208: Computer Organization & Architecture

A multiplication subroutine

Hand in via Moodle as multiplication.asm

You may work alone or with a partner on this assignment. If you would like to work with a partner but want to be assigned one, let me know.

Goals

Background

MIPS has several integer multiplication instructions, typically optimized in the hardware to make them fast. That said, multiplication in a computer has some subtleties that aren't obvious at first glance, so there's quite a bit of value in implementing multiplication yourself, once. That's what you're going to do for this assignment: implement 32-bit signed multiplication in MIPS without using the built-in multiplication instructions.

The mult subroutine

Your multiplication subroutine must adhere to the following requirements:

The print subroutine

To test your mult subroutine, you will want to be able to print your results. Given that the product consists of two words (64 bits), and may also represent a two-word negative number, this is not as simple as calling print on the two separate words of the product. If you find it simpler, you may write a print subroutine that prints the results as a 16-digit hexadecimal number instead of a long base ten number. (Printing a two-word number in base ten might be interesting, however, so go ahead and do that if you prefer.)

Your print subroutine must adhere to the following requirements:

Since the print subroutine expects its parameters stored in $a1 and $a0, you'll need to move the results of mult from $v1/$v0 to $a1/$a0 before invoking print.

The main program

You may use the main program from bad_mult.asm, adapting the printing section as needed.

A sketch of the algorithm

Here's a rough description of the algorithm I want you to use. Note that for 32-bit integers, this algorithm may take up to 31 iterations of its loop, but no more than that. Thus, this is a vastly superior algorithm to the one in bad_mult.asm, which has the potential to require more than 2 billion iterations.

Note that the variables SIGN, PRODUCT, MULTIPLICAND, and MULTIPLIER are just my names for these numbers. In your code, all four of these quantities will be stored in registers.

Furthermore, note that PRODUCT and MULTIPLICAND must be 64-bit integers, so you'll need to use two registers to represent each of them. You might even want to write a subroutine for adding a 2-register integer to another 2-register integer.

Always good ideas...

Start early, ask questions, and have fun!