Last active
April 16, 2017 14:46
-
-
Save AjayKrP/3f2af80653d25fc82d18d40b875b127f 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
%include "Assembly/Exam/macro.asm"; use your own macro | |
;create two file with name file1.txt and file2.txt | |
;first you have to enter your choice i.e. 1 or 2 or 3.... | |
;then enter commands | |
;give first file name as file1.txt and second file name as file2.txt | |
section .data | |
cmd db 0xa, "command menu" | |
db 0xa,"1.TYPE" | |
db 0xa,"2.COPY" | |
db 0xa,"3.DELETE" | |
db 0xa,"4.EXIT",0xa | |
len equ $ - cmd | |
entercmd db 0xa,"Enter command:------: " | |
cmdlen equ $ - entercmd | |
msg0 db 0xa,"Failed to open the file!!!" | |
len0 equ $ - msg0 | |
msg1 db 0xa,"File opened successfully!!!" | |
len1 equ $ - msg1 | |
msg2 db 0xa,"Failed to open the file!!!" | |
len2 equ $ - msg2 | |
msg3 db 0xa, "Command not found!!!!",0xa | |
len3 equ $ - msg3 | |
section .bss | |
buffer resb 200 | |
bufferlen resb 8 | |
choice resb 50 | |
chlen equ $ - choice | |
fdis1 resb 200 | |
fdis2 resb 200 | |
cnt1 resb 2 | |
ch1 resb 2 | |
name1 resb 20 | |
name2 resb 20 | |
size resb 200 | |
section .text | |
global _start | |
_start: | |
iomodule 1, 1, cmd, len | |
iomodule 0, 0, ch1, 2 | |
mov rsi, ch1 | |
cmp byte[rsi], '1' | |
je TYPE | |
cmp byte[rsi], '2' | |
je COPY | |
cmp byte[rsi], '3' | |
je DELETE | |
cmp byte[rsi], '4' | |
exit | |
jmp error | |
TYPE: | |
iomodule 1, 1, entercmd, cmdlen | |
iomodule 0, 0, choice, chlen | |
mov rsi, choice | |
mov byte[size], al | |
dec byte[size] | |
mov al, byte[rsi] | |
nd: | |
cmp al, 't' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'y' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'p' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'e' | |
jne error | |
inc rsi | |
dec byte[size] | |
jmp success | |
error: | |
iomodule 1, 1, msg3, len3 | |
jmp _start | |
success: | |
inc rsi | |
dec byte[size] | |
mov rdi, name1 | |
top: | |
mov al, byte[rsi] | |
mov [rdi], al | |
inc rdi | |
inc rsi | |
dec byte[size] | |
jnz top | |
;iomodule 1, 1, name1, 50 | |
iomodule 2, name1, 2, 777 | |
mov qword[fdis1], rax | |
bt rax, 63 | |
jc error | |
iomodule 0, [fdis1], buffer, 200 | |
mov qword[cnt1], rax | |
iomodule 1, 1, buffer, qword[cnt1] | |
mov rax, 3 | |
mov rdi, name1 | |
syscall | |
jmp _start | |
DELETE: | |
iomodule 1, 1, entercmd, cmdlen | |
iomodule 0, 0, choice, chlen | |
mov byte[size], al | |
dec byte[size] | |
mov al, byte[rsi] | |
nd1: | |
cmp al, 'd' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'e' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'l' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'e' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 't' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'e' | |
jne error | |
inc rsi | |
dec byte[size] | |
jmp success1 | |
success1: | |
inc rsi | |
dec byte[size] | |
mov rdi, name2 | |
top1: | |
mov al, byte[rsi] | |
mov [rdi], al | |
inc rdi | |
inc rsi | |
dec byte[size] | |
jnz top1 | |
mov rax, 87 | |
mov rdi, name2 | |
syscall | |
jmp _start | |
COPY: | |
iomodule 1, 1, entercmd, cmdlen | |
iomodule 0, 0, choice, chlen | |
mov byte[size], al | |
dec byte[size] | |
mov al, byte[rsi] | |
nd2: | |
cmp al, 'c' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'o' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'p' | |
jne error | |
inc rsi | |
dec byte[size] | |
mov al, byte[rsi] | |
cmp al, 'y' | |
jne error | |
inc rsi | |
dec byte[size] | |
jmp success2 | |
success2: | |
inc rsi | |
dec byte[size] | |
mov rdi, name1 | |
mov rcx, 9 | |
nsp: | |
mov al, [rsi] | |
mov [rdi], al | |
inc edi | |
inc rsi | |
dec byte[size] | |
loop nsp | |
inc rsi | |
dec byte[size] | |
xor rdi, rdi | |
mov rdi, name2 | |
nnl: | |
mov al, [rsi] | |
mov [rdi], al | |
inc rdi | |
inc rsi | |
dec byte[size] | |
jnz nnl | |
;iomodule 1, 1, name1, 10 | |
iomodule 2, name1, 2, 777 | |
mov qword[fdis1], rax | |
iomodule 0, [fdis1], buffer, 200 | |
mov qword[cnt1], rax | |
;iomodule 1, 1, buffer, [cnt1] | |
;iomodule 1, 1, name2, 50 | |
iomodule 2, name2, 2, 777 | |
mov qword[fdis2], rax | |
iomodule 1, [fdis2], buffer, qword[cnt1] | |
mov rax, 3 | |
mov rdi, name1 | |
syscall | |
mov rax, 3 | |
mov rdi, name2 | |
syscall | |
jmp _start | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment