Question
I'm having trouble with my code this is the instructions for MASM Irvine32 There will be a function called getdouble. This function will simply double
I'm having trouble with my code this is the instructions for MASM Irvine32
There will be a function called getdouble. This function will simply double any number which is currently in eax and store the result in eax.
There will be a function called gettriple. This function will simply triple any number which is currently in eax and store the result in eax.
There will be a function called getoddeven. This function will check if the value in eax is even. IF it is even, it will call the getdouble function. IF it is odd, it will get the gettriple function. (Note: edx stores remainder after you divide)
Your main program should ask the first user for a name as well as for a number. You should then call the getoddeven function. That function will either double or triple the initial value entered by the user. Display the name and the final result for this first user.
Your program will then do the same for a second user for a name as well as for a number. You will again call the getoddeven function which will either double or triple the value. Display the name and final result for this second user.
Finally, you will compare the two final results of each user and display the name of the one with the bigger final number as well as the number they have.
TITLE MASM Template
INCLUDE Irvine32.inc
.data name1 db "Enter first name: ",0 name2 db "Enter second name: ",0 num1 db "Enter first number: ",0 num2 db "Enter second number: ",0 output1 db "%s's final number is: %d",13,10,0 output2 db "%s's final number is: %d",13,10,0 output3 db "%s had the bigger number: %d",13,10,0
.code main PROC
; prompt user for first name and number mov edx, OFFSET name1 call WriteString mov edx, OFFSET num1 call WriteString call ReadInt ; call getoddeven function on first number push eax call getoddeven mov ebx, eax ; store result in ebx add esp, 4 ; clean up stack ; print first user's name and final number mov edx, OFFSET output1 mov ecx, OFFSET name1 call WriteString mov eax, ebx call WriteDec ; prompt user for second name and number mov edx, OFFSET name2 call WriteString mov edx, OFFSET num2 call WriteString call ReadInt ; call getoddeven function on second number push eax call getoddeven mov edx, eax ; store result in edx add esp, 4 ; clean up stack ; print second user's name and final number mov edx, OFFSET output2 mov ecx, OFFSET name2 call WriteString mov eax, edx call WriteDec ; compare final numbers and print winner
mov edx, OFFSET output3 mov ecx, OFFSET name1 cmp ebx, edx jg greater ; jump to greater label if ebx is greater than edx mov ecx, OFFSET name2 ; if not, use name2 instead mov ebx, edx ; and use edx as the number to print greater: call WriteString mov eax, ebx call WriteDec ; exit program exit ; getdouble function getdouble PROC mov ebx, eax ; store original value of eax in ebx shl eax, 1 ; double the value in eax by shifting left once ret ; return the result in eax getdouble ENDP
; gettriple function gettriple PROC mov ebx, eax ; store original value of eax in ebx mov ecx, 2 ; store the value 2 in ecx mul ecx ; multiply the value in eax by 2 add eax, ebx ; add the original value of eax to the result ret ; return the result in eax gettriple ENDP
; getoddeven function getoddeven: mov ebx, eax ; store original value of eax in ebx mov ecx, 2 ; store the value 2 in ecx mov edx, 0 ; set edx to 0 to prepare for division div ecx ; divide the value in eax by 2, storing the remainder in edx cmp edx, 0 ; compare the remainder to 0 to determine if it's even or odd jz even ; jump to even label if remainder is 0 (i.e., value is even) jmp odd ; jump to odd label if remainder is not 0 (i.e., value is odd) even: call getdouble ; call getdouble function if value is even ret ; return the result in eax odd: call gettriple ; call gettriple function if value is odd ret ; return the result in eax
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