Answered step by step
Verified Expert Solution
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 bit integer by EAXmultiplier using Only Shifting and Addition. Pass the unsigned bit integermultiplicand 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 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 bit in the multiplier.
Test Cases :
multiplicand ; multiplier
multiplicand ; multiplier Note: multiplicand in hex is A AAAAh and multiplier is h alternating s and s
multiplicand ; multiplier Note: multiplicand in hex is h and multiplier is AAA AAAAh
IMPORTANT: for this exercise, NOT allowable to use any one of these directives: IFELSE, 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 countera variable to reflect the lowest bit of the multiplier
b Loop body:
Look at the current bit of the multiplier, by rightshifting it; if the bit is set then:
Shift the copy of the multiplicand by the amount specified by the shift counter; the alternative method is to recursively leftshiftdoubling the
multiplicand, once per pass of the loop
Accumulateadd the shift result to the sum
Increment the shift counter
if shift counter Not GT repeat the loop
###############################
my current code:
~~~~
model flat, stdcall
stack
ExitProcess PROTO, dwExitCode:DWORD
INCLUDE Irvineinc
data
multiplicand dword h
multiplier dword h
output dword
code
BitwiseMultiply PROC
BitwiseMultiply ENDP
main PROC
invoke ExitProcess,
main ENDP
END main
~~~~Programming Exercise pts Bitwise Multiplication
Write a procedure named BitwiseMultiply that multiplies any unsigned bit integer by EAXmultiplier using Only Shifting and Addition. Pass the
unsigned bit integermultiplicand 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 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 instruction, using the multiplicand as the
destination operand. Then, the same process must be repeated until you find the last bit in the multiplier.
Test Cases :
multiplicand ; multiplier
multiplicand ; multiplier Note: multiplicand in hex is AAAAAh and multiplier is alternating s and s
multiplicand ; multiplier Note: multiplicand in hex is and multiplier is OAAAAAAAh
IMPORTANT: for this exercise, NOT allowable to use any one of these directives: IFELSE, ELSEIF, WHILE, REPEAT, etc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started