• FEATURED POSTS
  • LATEST POSTS
  • SERVICES

Friday, 21 December 2012

Swapping Two Numbers In Assembly Programming

For those who read the previous post of assembly programming here is another treat for you. This is the program of swapping two numbers in assembly programming.

[code lang="HTML']

TITLE MASM Template (main.asm)

; Description:
;
; Revision date:
INTERGER=4;
INCLUDE Irvine32.inc
.data
prompt1 byte "Please Input Interger : ",0;
prompt2 byte "You Sum is: ",0;
integers word INTERGER DUP(0);
firstNum dword 56d;
secondNum dword 12d;
.code
main PROC
call swap;
mov eax,firstnum;
call writeint;
call crlf;
mov eax,secondnum;
call writeint;
call dumpregs;

exit
main ENDP

swap PROC
pushad
mov eax,firstNum;
mov edx,secondNum;
mov firstNum,edx;
mov secondNum,eax;
popad
ret
swap ENDP

end main[/code]

Remember that you must have MASM and Irvine32.lib installed to run this program. Otherwise you can see how the program is working and what is the logic behind the swapping function.

0 comments

Posts a comment

 
© 2011 myTestBlog
Designed by Blog Thiết Kế
Back to top