Data Computer
Data Computer
Loading…
Swapping Numbers
The act of swapping two variables refers to mutually exchanging the values of the variables.
Syntax :
MOV AL, [0600]
MOV BL, AL
MOV AL, [0601]
MOV [0600], AL
MOV [0601], BL
HLT
INPUT: 0600:05 0601:04
OUTPUT: 0600:04 0601:05
Swapping Number
•The following code in x86 assembly language uses the xor swap algorithm to swap the value in the
AX register with the value in the BX register without using a temporary buffer.
XOR AX, BX
XOR BX, AX
XOR AX, BX
•However, all x86 microprocessors have an XCHG instruction which does the same work on its
operands more efficiently than the above sequence of XORs.
Program to Swap Two numbers using Stack in assembly language
MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AX,'6'
MOV BX,'8'
PUSH AX
PUSH BX
POP AX
POP BX
MOV DX,AX
MOV AH,2
INT 21H
MOV DX,BX
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Program to swap two number:
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DB 05H
NUM2 DB 02H
.CODE
MOV AX , @DATA ; Initializing Data Segment
MOV DS , AXburning fuels, effective feedstocks for petrochemical operations, and more effective
lubricating oils. Only through hydro-cracking can heavy fuel oil components be
converted to transportation fuels and lubricating oils whose quality will meet tightening
environmental and market demands. Hydro-processing
; Storing Data
MOV BL , NUM1
MOV CL , NUM2
; Swapping
MOV NUM2 , BL
MOV NUM1 , CL