Question: Can you make this answer into a asm code please. Your Task Now that you have seen the video, you should use what you have
Can you make this answer into a asm code please. Your Task
Now that you have seen the video, you should use what you have seen to create the following procedure:
swapValues
This procedure should take the address of two DWORD variables and swap the values around. You must push the address of the two variables on the stack and use call to call the swapValues procedure.
In main, create some code to test your functionality. You should enter two DWORD values and pass their address to the swapValues procedure through the stack. When the procedure returns, you should output the swapped values. Please note that this is more than simply printing the values out in the opposite order in which they were input. The values in the variables should be swapped.
In the swapValues procedure, if you use any registers, I expect you to restore them just before the procedure returns. It should also be noted that you must use indirect addressing to accomplish the task because you are dealing with addresses.
Sample Run
Enter a number
Enter a number
Your numbers swapped are
NOTE:
You are not to use any IF ELSE, WHILE, or ENDW instructions.
Do not use INVOKE for your procedures. You should push values onto the stack and reference them using the stack base. This means you should use call. Your procedures should also have a prologue.
The use of legacy directives like DB and DW is not allowed in this class. A deduction of will be given if you use them.
The use of indirect addressing around variables is NOT allowed in the class unless you are using indirect addressing. An example of this would be val Doing this will result in a reduction in your grade.
Also, note that you must use standard calling conventions to clean up the stack.
You must comment every line of code you write or your grade will be reduced by
Make sure to use writeInt, readInt, writeLine, and writeString.
This is what I got so far.
INCLUDE asmlib.inc
data
prompt BYTE "Enter a number:
outP BYTE "Your numbers swapped are:
var DWORD
var DWORD
code
main PROC
; Prompt for the first number
mov edx, OFFSET prompt
call writeLine
call readInt
mov var eax
; Prompt for the second number
mov edx, OFFSET prompt
call writeLine
call readInt
mov var eax
; Swapping the values of var and var using XOR
mov eax, var
xor eax, var
mov var eax
mov eax, var
xor eax, var
mov var eax
mov eax, var
xor eax, var
mov var eax
; Output the swapped values
mov edx, OFFSET outP
call writeString
mov eax, var
call writeInt
mov eax, var
call writeInt
exit
main ENDP
END main
Can you improve this please?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
