Homework 8 - Computer Organization Due: 4/17/03 (Th)

The goal of this assignment is to provide you with experience in using the "Logical Instructions" (bit operations, e.g., and, or, & shifting instructions) and to help you understand Booth's multiplication algorithm. For this assignment, you are to implement Booth's algorithm on 32-bit two's complement numbers. You will need to use the "Logical Instructions" (bit operations, e.g., and, or, & shifting instructions) to implement Booth's algorithm. I want you to write a function

called "Multiply" that is passed two signed integers (x, y) and returns their 64-bit product (x * y) across registers a1 and a2. Be sure that you DO NOT use the any form of the multiply (e.g., MUL) assembly language instruction, and be sure to follow the ARM register convensions when implementing "Multiply."

Turn in the following:

1) The ARM assembly language programs (main and Multiply) for performing Booth's algorithm.

2) A snapshot of of your registers after return from your Multiply subprogram with for multiplying together 103 and -25.

Hints:

1) Typically, you use the "and" & "or" instructions to look at or set a specific bit position in an operand stored in a register. To do this you use a "mask" which indicates the bit positions of interest. For example, suppose that you want to know if the 3rd least significant

bit of register R8 is a "1". You can "and" a binary mask of 00000000000000000000000000000100 (or hexadecimal 0x00000004) with register R8, then check the result of the "and" operation to see if the result was a zero or not. In ARM, this example would look something like:

AND R9, R8, #0x4 ; saves the result of ANDing R8 with 0x00000004 in R9

If you don't really want the result of the AND, but just want to test whether any of the "1" in the

TST R8, #0x4 ;TST perform R8 AND #0x00000004 to set condition codes N,Z,C

BNE

2) Suppose that you want to set the most-significant bit (left-most bit) of register R8 to a 1 without changing any other bits in register R8. You could "or" (ORR instruction) the mask of 100000000000000000000000000000002 (0x80000000) with R8 to force its most-significant bit to be a 1. In ARM the code would be:

MOV R9, 0x80000000

ORR R8, R8, R9