In: Computer Science
Write a MASM program that uses a loop to multiply 2 numbers. Use the equal sign directive to define the two numbers. Save the product in the EAX register.
Hint
4 x 5 = 4 + 4 +4 + 4 + 4 = 5 + 5 + 5 + 5
Language (Assembly)
ASAP
Solution:-
The above task can be achieved using the load registers (LDR) and a loop to work around with the numbers.
The numbers can be represented as: (a) 4 = 00 00 00 04
(b) 5 = 00 00 00 05
Area prog, Code, readonly
Entry
Main
;Main block of the code
LDR R1, VALUE1
LDR R2, VALUE2
MOV R0, #0x00000000
LOOP
;Loop to add the number '4' 5 times
ADD R0, R0, R1
;Logic is R0 = R0 + R1
SUBS R2, R2, #1
;This is used to decrement
the loop value by 1
BNE LOOP
;This
command will check the R2 till it gets R2 = 0
MOV EAX, R0
;Move the
value in R0 to EAX
Area prog, data, readonly
;Initializing the data in here
VALUE1 = 00000004
;VALUE1 is initialize as 4
VALUE2 = 00000005
;VALUE2 is initialize as 5
END
;End the program
Note:- If you have any doubt on any of the command comment it below i will definitely help understand it.