;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
mov ebx,0
int 80h
%endm 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 10,13,"*****MENU*****"
db 10,13,"1.Non Overlap Block Transfer"
db 10,13,"2.Overlap Block Transfer"
db 10,13,"3.Exit"
db 10,13,"Enter Choice="
mnlen equ $-mn
msg0 db " "
msg0len equ $-msg0
msg1 db 10,13,"Array before bloktransfer"
len1 equ $-msg1
msg2 db 10,13,"Array after bloktransfer="
len2 equ $-msg2
msg3 db 10,13,"Source Array="
len3 equ $-msg3
msg4 db 10,13,"Dest Array="
len4 equ $-msg4
newln db 10,13,""
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,2
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,10
call display
disp msg4,len4
mov esi,destblk
mov ebp,10
call display
disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display
mov esi,srcblk
mov edi,destblk
mov ecx,10
cld
rep movsb
disp msg4,len4
mov esi,destblk
mov ebp,10
call display
jmp _start
over:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display
disp msg4,len4
mov esi,destblk
mov ebp,10
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,10
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
OUTPUT:
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ nasm -f elf over.asm
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ld -m elf_i386 -s -o over over.o
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ./over
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=1
Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=00 00 00 00 00 00 00 00 00 00
Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=2
Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A
Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 01 02 03 04 05
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=3
;(with and without string specific instructions).
;Block containing data can be defined in the data segment.
;Macro Deffination
;—————————————————————————————
%macro exit 0
mov eax,1
mov ebx,0
int 80h
%endm 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 10,13,"*****MENU*****"
db 10,13,"1.Non Overlap Block Transfer"
db 10,13,"2.Overlap Block Transfer"
db 10,13,"3.Exit"
db 10,13,"Enter Choice="
mnlen equ $-mn
msg0 db " "
msg0len equ $-msg0
msg1 db 10,13,"Array before bloktransfer"
len1 equ $-msg1
msg2 db 10,13,"Array after bloktransfer="
len2 equ $-msg2
msg3 db 10,13,"Source Array="
len3 equ $-msg3
msg4 db 10,13,"Dest Array="
len4 equ $-msg4
newln db 10,13,""
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,2
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,10
call display
disp msg4,len4
mov esi,destblk
mov ebp,10
call display
disp newln,lnlen
disp msg2,len2
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display
mov esi,srcblk
mov edi,destblk
mov ecx,10
cld
rep movsb
disp msg4,len4
mov esi,destblk
mov ebp,10
call display
jmp _start
over:
disp msg1,len1
disp msg3,len3
mov esi,srcblk
mov ebp,10
call display
disp msg4,len4
mov esi,destblk
mov ebp,10
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,10
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
OUTPUT:
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ nasm -f elf over.asm
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ld -m elf_i386 -s -o over over.o
swlab@swlab-Veriton-M200-H81:~/MICROPROCESSOR 2017-18$ ./over
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=1
Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=00 00 00 00 00 00 00 00 00 00
Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=2
Array before bloktransfer
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 06 07 08 09 0A
Array after bloktransfer=
Source Array=01 02 03 04 05 06 07 08 09 0A
Dest Array=01 02 03 04 05 01 02 03 04 05
*****MENU*****
1.Non Overlap Block Transfer
2.Overlap Block Transfer
3.Exit
Enter Choice=3
No comments:
Post a Comment