Question

assembly language program to swap the values of two variables

assembly languageprogram to swap the values of two variables
0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*Hi, I will be using "//" and "/**/" for comments. This program iswritten in Pep8 which is a generic Instruction set that should beadequate for you tounderstand the process of what is goingon.*/
var1: .BLOCK 2 //make room for var1
var2: .BLOCK 2 //make room for var2
temp; .BLOCK 2 //make room for temp var
msg1: .ASCII "Input var1x00"
msg2: .ASCII "Input var2x00"
//beginning of the program with user prompts
main:STRO msg1,d
DECIvar1,d
STAvar1,d
STROmsg2,d
DECIvar2,d
STAvar2,d
//swapping portion - you must perform 3 variable swaps for anyswitch and you must use the register to do so
LDAvar2,d //load the register
STAtemp,d //store it
LDAvar1,d
STAvar2,d
LDAtemp,d
STAvar1,d
/*
this is equivalent to:
temp = var2;
var2 = var1;
var1 = temp;
in C++/Java
*/
.END

Add a comment
Answer #2
To move/swap two variable values using assembly language,wedo following assy lang programming
MOV EAX,A// first move value of A toregister EAXMOV EBX,B// move value of B to registerEBX
MOVB,EAX// move value ofregisterEAX toB
MOVA,EBX// move value ofregisterEBX toADon't forget to rate me!!!
answered by: kong
Add a comment
Know the answer?
Add Answer to:
assembly language program to swap the values of two variables
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT