Please disable adblock to view this page.

← Go home

Overlap, Non-Overlap Block Transfer (Assembly x86)

April 23, 2016
Published By : Pratik Kataria
Categorised in: ,

section .data

msg db 10,13,”Entered Array is”
msg_l equ $-msg

msg1 db 10,13,”Select Operation:”
msg_l1 equ $-msg1

msg2 db 10,13,”1.Overlapped Transfer”
msg_l2 equ $-msg2

msg3 db 10,13,”2.Non-Overlapped Transfer”
msg_l3 equ $-msg3

msg6 db 10,13,”4.Non-Overlapped Transfer with String Instruction”
msg_l6 equ $-msg6

msg7 db 10,13,”3.Overlapped Transfer with String Instruction”
msg_l7 equ $-msg7

msg4 db 10,13,”5.Exit”
msg_l4 equ $-msg4

msg5 db 10,13,”Enter Overlap position”
msg_l5 equ $-msg5

msg0 db 10,13,”Transferred Array is”
msg_l0 equ $-msg0

nwline db 10

arr dd 11111111h,22222222h,33333333h,44444444h
newarr times 8 dd 0

section .bss
opt resb 2
pos resb 1
cnt resb 1
cnt1 resb 1
temp resb 1
disp_buff resb 8

%macro display 2
mov eax,4
mov ebx,1
mov ecx,%1
mov edx,%2
int 80h
%endmacro

%macro accept 2
mov eax,3
mov ebx,0
mov ecx,%1
mov edx,%2
int 80h
%endmacro

section .data
global _start
_start:

display msg1,msg_l1
display msg2,msg_l2
display msg3,msg_l3
display msg7,msg_l7
display msg6,msg_l6
display msg4,msg_l4

display nwline,1

accept opt,2

sub byte [opt],30h

cmp byte [opt],01h
je OVP

cmp byte [opt],02h
je NON_OVP

cmp byte [opt],03h
je OVP_S

cmp byte [opt],04h
je NON_OVP_S

cmp byte [opt],05h
je exit

call exit

;–OVP–

OVP:
display msg,msg_l

mov byte [cnt],4h
mov edi,arr
call original_to_ascii

call COPYNUM

call COPY

display msg0,msg_l0
mov al,[pos]
mov byte [cnt],al
mov edi,arr
call original_to_ascii

jmp _start
original_to_ascii:

push ecx
display nwline,1
pop ecx
mov ebx,[edi]
mov ecx,8
mov esi,disp_buff

l4:
rol ebx,4
mov dl,bl
and dl,0fh
cmp dl,09h
jbe l5
add dl,07h
l5:
add dl,30h
mov [esi],dl
inc esi
loop l4

add edi,4

display disp_buff,8
dec byte [cnt]
jnz original_to_ascii

display nwline,1

ret
COPYNUM:
mov esi,arr
mov edi,arr

mov byte [cnt],4h
pos_esi:
add esi,4
dec byte [cnt]
jnz pos_esi
sub esi,4

display msg5,msg_l5
display nwline,1
accept pos,2
sub byte [pos],30h

mov byte [cnt],4h
mov al,[pos]
add al,[cnt]
mov [cnt],al
dec byte [cnt]

mov [pos],al
dec byte [pos]

pos_edi:
add edi,4
dec byte [cnt]
jnz pos_edi
sub edi,4

ret

COPY:
mov byte [cnt1],4h
lnew:
mov eax,[esi]
mov [edi],eax
sub esi,4
sub edi,4
dec byte [cnt1]
jnz lnew

ret

;–NON_OVP–

NON_OVP:
display msg,msg_l

mov edi,arr
mov byte [cnt],4h
call original_to_ascii

call COPYNUMA

display msg0,msg_l0
mov byte [cnt],4h
mov edi,newarr
call original_to_ascii

jmp _start

COPYNUMA:
mov esi,arr
mov edi,newarr
mov byte [cnt1],4h

lnewA:
mov eax,[esi]
mov [edi],eax
add esi,4
add edi,4
dec byte [cnt1]
jnz lnewA

ret

;–OVP_STRING–
OVP_S:

mov edi,arr
mov byte [cnt],4h
display msg,msg_l
call original_to_ascii

call COPYNUM

display msg0,msg_l0
std
mov ecx,4
l1O:
movsd
loop l1O

mov al,[pos]
mov byte [cnt],al
mov edi,arr
call original_to_ascii

jmp _start

;–NON_OVP_STRING–

NON_OVP_S:

display msg,msg_l

mov edi,arr
mov byte [cnt],4h
call original_to_ascii

mov esi,arr
mov edi,newarr
mov ecx,4
l1S:
movsd
loop l1S

display msg0,msg_l0
mov byte [cnt],4h
mov edi,newarr
call original_to_ascii

jmp _start

;–EXIT–

exit:        mov eax,1
mov ebx,0
int 80h

View Article Page
Download

Pratik Kataria is a budding programmer, web designer and developer.