-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha5_p1.asm
138 lines (108 loc) · 1.75 KB
/
a5_p1.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%macro write 2
mov ecx, %1
mov edx, %2
mov eax, 4
mov ebx, 1
int 80h
%endmacro
%macro read 2
mov ecx, %1
mov edx, %2
mov eax, 3
mov ebx, 2
int 80h
%endmacro
section .data
fname db 'abc.txt',0
global sc,lc,cc,wc
sc db 0
cc db 0
lc db 0
wc db 0
msg : db 0Ah
db "1.space count ", 0x0A
db "2.line count ", 0x0A
db "3.char count",0x0A
db "4.word count",0x0A
db "5.exit",0x0A
db "Enter your Choice : "
len: equ $-msg
msg1: db "count: "
len1: equ $-msg1
msg2: db "character: "
len2: equ $-msg2
msg3: db "word: "
len3: equ $-msg3
msg4: db "length of word: "
len4: equ $-msg4
section .bss
global buffer,lenbuf,word1
fd resb 8
buffer resb 100
lenbuf resb 2
choice resb 2
character resb 2
word1 resb 10
wordlen resb 1
section .text
extern print,space,line,char,word,asst
global _start
_start:
mov rsi, 02
mov rdi, fname
mov rax, 02
mov rdx,0777
syscall
mov [fd],rax
mov rsi, buffer
mov rdi, [fd]
mov rax, 00
mov rdx, lenbuf
syscall
menu:
write msg,len
read choice,2
cmp byte[choice],31h
je case1
cmp byte[choice],32h
je case2
cmp byte[choice],33h
je case3
cmp byte[choice],34h
je case4
mov rax,1
int 80h
case1:
call space
write msg1,len1
mov edi,sc
call print
jmp menu
case2:
call line
write msg1,len1
mov edi,lc
call print
jmp menu
case3:
write msg2,len2
read character, 2
mov bl,byte[character]
call char
write msg1,len1
mov edi,cc
call print
jmp menu
case4:
write msg4,len4
read wordlen, 2
write msg3,len3
read word1, wordlen
lea rdi,[word1]
mov rcx,[wordlen]
sub rcx,30h
call asst
write msg1,len1
mov edi,wc
call print
jmp menu