Created
March 2, 2017 15:23
-
-
Save AjayKrP/c2485bcfbbca8d714b0c1eecc3646ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;**************************************************************************** | |
;Write X86/64 ALP to perform non-overlapped and overlapped block transfer | |
;(with and without string specific instructions). | |
;Block containing data can be defined in the data segment. | |
;Macro Deffination | |
;**************************************************************************** | |
%macro exit 0 | |
mov eax,1 | |
int 80h | |
%endmacro exit | |
%macro accept 2 ;macro for read | |
mov eax,3 ;system call for read | |
mov ebx,0 | |
mov ecx,%1 | |
mov edx,%2 ;format for collecting arguments(as buffer_name & buffer_size) | |
int 80h | |
%endmacro | |
%macro disp 2 ;macro for display | |
mov eax,4 ;system call for display | |
mov ebx,1 | |
mov ecx,%1 ;format for collecting arguments(as buffer_name & buffer_size) | |
mov edx,%2 | |
int 80h | |
%endmacro | |
section .data | |
srcblk db 01h,02h,03h,04h,05h,06h,07h,08h,09h,0Ah | |
destblk times 10 db 00 | |
mn db 0xa,'*****MENU*****' | |
db 0xa,'1.Non Overlap Block Transfer' | |
db 0xa,'2.Overlap Block Transfer' | |
db 0xa,'3.Exit' | |
db 0xa,'Enter Choice=' | |
mnlen equ $-mn | |
msg0 db ' ' | |
msg0len equ $-msg0 | |
msg1 db 0xa,'Array before bloktransfer' | |
len1 equ $-msg1 | |
msg2 db 0xa,'Array after bloktransfer=' | |
len2 equ $-msg2 | |
msg3 db 0xa,'Source Array=' | |
len3 equ $-msg3 | |
msg4 db 0xa,'Dest Array=' | |
len4 equ $-msg4 | |
newln db 0xa,'' | |
lnlen equ $-newln | |
cnt equ 10 | |
section .bss | |
cho resb 2 | |
chlen equ $-cho | |
ansfin resb 2 | |
ansfinlen equ $-ansfin | |
section .text | |
global _start | |
_start: | |
disp newln, lnlen | |
disp mn, mnlen | |
accept cho, chlen | |
cmp byte[cho], '1' | |
je nonover | |
cmp byte[cho], '2' | |
je ovr | |
disp newln, lnlen | |
exit | |
ovr: | |
call over | |
nonover: | |
disp msg1, len1 | |
disp msg3, len3 | |
mov esi, srcblk | |
mov ebp, cnt | |
call display | |
disp msg4, len4 | |
mov esi, destblk | |
mov ebp, cnt | |
call display | |
disp newln, lnlen | |
disp msg2, len2 | |
disp msg3, len3 | |
mov esi, srcblk | |
mov ebp, cnt | |
call display | |
mov esi, srcblk | |
mov edi, destblk | |
mov ecx, cnt | |
cld | |
rep movsb | |
disp msg4, len4 | |
mov esi, destblk | |
mov ebp, cnt | |
call display | |
jmp _start | |
over: | |
disp msg1, len1 | |
disp msg3, len3 | |
mov esi, srcblk | |
mov ebp, cnt | |
call display | |
disp msg4, len4 | |
mov esi, destblk | |
mov ebp, cnt | |
call display | |
disp newln, lnlen | |
disp msg2, len2 | |
disp msg3, len3 | |
mov esi, srcblk | |
mov ebp, cnt | |
call display | |
mov esi, srcblk | |
mov edi, destblk | |
mov ecx, 10 | |
cld | |
rep movsb | |
mov esi, srcblk | |
mov edi, destblk+5 | |
mov ecx, 5 | |
cld | |
rep movsb | |
disp msg4, len4 | |
mov esi, destblk | |
mov ebp, cnt | |
call display | |
jmp _start | |
numascii: | |
mov edi, ansfin+1 | |
mov ecx, 2 | |
l2: | |
mov edx, 0 | |
mov ebx, 16 | |
div ebx | |
cmp dl, 09h | |
jbe add30 | |
add dl, 07h | |
add30: | |
add dl, 30h | |
mov [edi], dl | |
dec edi | |
dec ecx | |
jnz l2 | |
disp ansfin, ansfinlen | |
ret | |
display: | |
l1: | |
mov eax, [esi] | |
call numascii | |
disp msg0, msg0len | |
inc esi | |
dec ebp | |
jnz l1 | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment