Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
section .data
arr db "ABCDE "
msg1 db "Enter 1. for non overlapping block transfer without string instruction",10
msg2 db "Enter 2. for non overlapping block transfer with string instruction",10
msg3 db "Enter 3. for overlapping block transfer without string instruction",10
msg4 db "Enter 4. for overlapping block transfer with string instruction",10
msg5 db "Enter 5. EXIT",10
msglen equ $-msg1
msg6 db "Enter an offset",10
msg6len equ $-msg6
msg7 db 10
msg7len equ $-msg7
section .bss
choice resb 2
off resd 1
%macro inout 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro
section .text
global _start
_start:
inout 1,1,msg1,msglen
inout 0,0,choice,2
cmp byte[choice],31H ;it is like switch case loop
je label1
cmp byte[choice],32H
je label2
cmp byte[choice],33H
je label3
cmp byte[choice],34H
je label4
cmp byte[choice],35H
je exit
label1: ;non overlapping without stirng ins
mov ecx,5H
mov esi,arr
mov edi,arr
add edi,5H
again: mov al,[esi]
mov [edi],al
inc esi
inc edi
dec ecx
jnz again
inout 1,1,arr,10
inout 1,1,msg7,msg7len
jmp exit
label2: ;overlapping with string ins
mov ecx,5H
mov esi,arr
mov edi,arr
add edi,5H
CLD ;clear direction flag DF=0
REP MOVSB ;repeat mov string byte if DF=0 si=si+1 di=di+1
inout 1,1,arr,10
inout 1,1,msg7,msg7len
jmp exit
label3: ;overlapping without string ins
inout 1,1,msg6,msg6len
inout 0,0,off,1
sub dword[off],30H
mov ecx,5H
mov esi,arr
mov edi,arr
add esi,4H
add edi,4H
add edi,dword[off]
up: mov al,[esi]
mov [edi],al
dec esi
dec edi
dec ecx
jnz up
inout 1,1,arr,10
inout 1,1,msg7,msg7len
jmp exit
label4: ;overlapping with string ins
inout 1,1,msg6,msg6len
inout 0,0,off,1
sub dword[off],30H
mov ecx,5H
mov esi,arr
mov edi,arr
add esi,4H
add edi,4H
add edi,dword[off]
STD ;set direction flag DF=1
REP MOVSB ;repeat mov string byte if DF=1 si=si-1 di=di-1
inout 1,1,arr,10
inout 1,1,msg7,msg7len
jmp exit
exit:
mov rax,60
mov rsi,0
syscall
data Segment
MESSAGE DB "ENTER CHARACTER : $"
NUM1 DB ?
NUM2 DB ?
NUM3 DB ?
NUM4 DB ?
BCD DW ?
data ENDS
code Segment
ASSUME DS:data ,CS:code
Start:
MOV AX ,DATA
MOV DS,AX
LEA DX,MESSAGE
MOV AH,9
int 21h
MOV NUM1,AL
SUB NUM1,30h
LEA DX,MESSAGE
int 21h
MOV NUM2,AL
SUB NUM2,30h
MOV AH,1
LEA DX,MESSAGE
int 21h
MOV NUM3,AL
SUB NUM3,30h
MOV AH,1
LEA DX, MESSAGE
int 21h
MOV NUM4,AL
SUB NUM4,30h
SUB AL,30h
MOV DH,00h
MOV DL,O1h
MOV DH,NUM1
ROL DH,4
Add DH,NUM2
MOV DL,NUM3
ROL DL,4
Add DL,NUM4
MOV BCD,DX
MOV AH,4Ch
int 21h
code ENDS
END START