Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a procedure named BitwiseMultiply that multiplies any unsigned 3 2 - bit integer by EAX ( multiplier ) , using Only Shifting and Addition.

Write a procedure named BitwiseMultiply that multiplies any unsigned 32-bit integer by EAX(multiplier), using Only Shifting and Addition. Pass the unsigned 32-bit integer(multiplicand) 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.)
This is a fairly challenging program to write. One possible approach is to use a loop to shift the multiplier to the right, keeping track of the number of shifts that occur before the Carry flag is set. The resulting shift count can then be applied to the SHL instruction, using the multiplicand as the destination operand. Then, the same process must be repeated until you find the last 1 bit in the multiplier.
```
Test Cases :
1. multiplicand =6553110; multiplier =102910
2. multiplicand =69905010; multiplier =546110(Note: multiplicand in hex is 0A AAAAh and multiplier is 01555h - alternating 1's and 0's)
3. multiplicand =2110; multiplier =17895697010(Note: multiplicand in hex is 015h and multiplier is 0AAA AAAAh)
````
IMPORTANT: for this exercise, NOT allowable to use any one of these directives: .IF,.ELSE, .ELSEIF, .WHILE, .REPEAT, etc
#####################
Pseudo code:
> Use a loop to perform the summing and shifting:
>> a) Prior to the loop:
>>>> make a copy of the multiplier to a register;
>>>> initialize the sum to zero;
>>>> set the shift counter(a variable) to reflect the lowest bit of the multiplier
>> b) Loop body:
>>>> Look at the current bit of the multiplier, by right-shifting it; if the bit is set then:
>>>>>>1) Shift the copy of the multiplicand by the amount specified by the shift counter; the alternative method is to recursively left-shift(doubling) the
multiplicand, once per pass of the loop
>>>>>> Accumulate(add) the shift result to the sum
>>>> Increment the shift counter
>>>> if shift counter Not G.T.32, repeat the loop
###############################
my current code:
~~~~
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
INCLUDE Irvine32.inc
.data
multiplicand dword 65531h
multiplier dword 1029h
output dword ?
.code
BitwiseMultiply PROC
BitwiseMultiply ENDP
main PROC
invoke ExitProcess, 0
main ENDP
END main
~~~~Programming Exercise 2(20 pts)- Bitwise Multiplication
Write a procedure named BitwiseMultiply that multiplies any unsigned 32-bit integer by EAX(multiplier), using Only Shifting and Addition. Pass the
unsigned 32-bit integer(multiplicand) 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.)
This is a fairly challenging program to write. One possible approach is to use a loop to shift the multiplier to the right, keeping track of the number of
shifts that occur before the Carry flag is set. The resulting shift count can then be applied to the SHL instruction, using the multiplicand as the
destination operand. Then, the same process must be repeated until you find the last 1 bit in the multiplier.
Test Cases :
multiplicand =6553110; multiplier =102910
multiplicand =69905010; multiplier =546110(Note: multiplicand in hex is 0AAAAAh and multiplier is 01555h- alternating 1's and 0's)
multiplicand =2110; multiplier =17895697010(Note: multiplicand in hex is 015h and multiplier is OAAAAAAAh)
IMPORTANT: for this exercise, NOT allowable to use any one of these directives: .IF,.ELSE, .ELSEIF, .WHILE, .REPEAT, etc
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions