;***Guidelines for running program***
;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
;for type: command is type file1.txt
;for copy: command is copy file1.txt file2.txt
;for delete: command is delete file1.txt
;give first file name as file1.txt and second file name as file2.txt
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro iomodule 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro
%macro exit 0
mov rax,60
syscall
%endmacro
section .data
cmd db 10,13, "command menu"
db 10,13,"1.TYPE"
db 10,13,"2.COPY"
db 10,13,"3.DELETE"
db 10,13,"4.EXIT"
db 10,13,"Enter choice:"
len equ $ - cmd
entercmd db 10,13,"Enter command:------: "
cmdlen equ $ - entercmd
msg0 db 10,13,"Failed to open the file!!!"
len0 equ $ - msg0
msg1 db 10,13,"File opened successfully!!!"
len1 equ $ - msg1
msg2 db 10,13,"Failed to open the file!!!"
len2 equ $ - msg2
msg3 db 10,13, "Command not found!!!!"
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:
print cmd, len
accept 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:
print entercmd, cmdlen
accept 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:
print 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 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:
print entercmd, cmdlen
accept 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:
print entercmd, cmdlen
accept 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 2, name1, 2, 777
mov qword[fdis1], rax
iomodule 0, [fdis1], buffer, 200
mov qword[cnt1], rax
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
file1.txt
I am Prof. Dhokane R.M
file2.txt
I am Prof. Butkar U.D.
OUTPUT
swlab@swlab-H81-M1:~$ cd Desktop/
swlab@swlab-H81-M1:~/Desktop$ cd cmd/
swlab@swlab-H81-M1:~/Desktop/cmd$ nasm -f elf64 cmd.asm
swlab@swlab-H81-M1:~/Desktop/cmd$ ld -o cmd cmd.o
swlab@swlab-H81-M1:~/Desktop/cmd$ ./cmd
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1
Enter command:------: type file1.txt
I am prof Butkar U.D.
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1
Enter command:------: type file2.txt
I am prof Dhokane R.M.
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
2
Enter command:------: copy file1.txt file2.txt
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
3
Enter command:------: delete file1.txt
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
4
swlab@swlab-H81-M1:~/Desktop/cmd$
;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
;for type: command is type file1.txt
;for copy: command is copy file1.txt file2.txt
;for delete: command is delete file1.txt
;give first file name as file1.txt and second file name as file2.txt
%macro print 2
mov rax,1
mov rdi,1
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro accept 2
mov rax,0
mov rdi,0
mov rsi,%1
mov rdx,%2
syscall
%endmacro
%macro iomodule 4
mov rax,%1
mov rdi,%2
mov rsi,%3
mov rdx,%4
syscall
%endmacro
%macro exit 0
mov rax,60
syscall
%endmacro
section .data
cmd db 10,13, "command menu"
db 10,13,"1.TYPE"
db 10,13,"2.COPY"
db 10,13,"3.DELETE"
db 10,13,"4.EXIT"
db 10,13,"Enter choice:"
len equ $ - cmd
entercmd db 10,13,"Enter command:------: "
cmdlen equ $ - entercmd
msg0 db 10,13,"Failed to open the file!!!"
len0 equ $ - msg0
msg1 db 10,13,"File opened successfully!!!"
len1 equ $ - msg1
msg2 db 10,13,"Failed to open the file!!!"
len2 equ $ - msg2
msg3 db 10,13, "Command not found!!!!"
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:
print cmd, len
accept 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:
print entercmd, cmdlen
accept 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:
print 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 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:
print entercmd, cmdlen
accept 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:
print entercmd, cmdlen
accept 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 2, name1, 2, 777
mov qword[fdis1], rax
iomodule 0, [fdis1], buffer, 200
mov qword[cnt1], rax
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
file1.txt
I am Prof. Dhokane R.M
file2.txt
I am Prof. Butkar U.D.
OUTPUT
swlab@swlab-H81-M1:~$ cd Desktop/
swlab@swlab-H81-M1:~/Desktop$ cd cmd/
swlab@swlab-H81-M1:~/Desktop/cmd$ nasm -f elf64 cmd.asm
swlab@swlab-H81-M1:~/Desktop/cmd$ ld -o cmd cmd.o
swlab@swlab-H81-M1:~/Desktop/cmd$ ./cmd
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1
Enter command:------: type file1.txt
I am prof Butkar U.D.
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
1
Enter command:------: type file2.txt
I am prof Dhokane R.M.
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
2
Enter command:------: copy file1.txt file2.txt
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
3
Enter command:------: delete file1.txt
command menu
1.TYPE
2.COPY
3.DELETE
4.EXIT
4
swlab@swlab-H81-M1:~/Desktop/cmd$
No comments:
Post a Comment