Assembly Language
Homework 5, Due 2010/5/10
Problem 1
Fast multiplication (Page 222, Problem 5)
Write a procedure named FastMultiply that multiplies any unsigned 32-bit integer by EAX, using only shifting and addition. Pass the integer to the procedure in the EBX register, and return the product in the EAX register. Write a short test program that calls the procedure and displays the product. (We will assume that the product is never
larger than 32 bits.)
Problem 2
Greatest common divisor (GCD) (Page 222, Problem 6)
The greatest common divisor of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves integer division in a loop, described by the following C++ code:
int GCD(int x, int y)
{
x = abs(x); // absolute value
y = abs(y);
do {
int n = x % y;
x = y;
y = n;
} while y > 0;
return y;
}
Implement this function in assembly language and write a test program that calls the function several times, passing it different values. Display all results on the screen.
ftp your homework to
in the directory \HW6
by the following format:
檔案名稱:hw#_學號.zip
例如:資工同學,作業4
檔案名稱:hw4_a09755xx.zip. (注意:檔案名稱不能有中文)
The password is given in class.