-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu_Driven_String_Operations.txt
194 lines (166 loc) · 3.96 KB
/
Menu_Driven_String_Operations.txt
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; program for string operations
;=================================================================================================;
%macro write_string 2
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write);tell linker entry
mov ecx, %1 ;message to write
mov edx, %2 ;message length
int 0x80 ;call kernel
%endmacro
%macro accept 2
mov ebx,0
mov eax,3
mov ecx,%1
mov edx,%2
int 0x80 ;call kernel
%endmacro
;===================================================================================================;
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
write_string msg,len
accept ip_str,6
mov byte[cnt],al
write_string ip_str, 6
write_string newline, newl_len
write_string menu, menu_len
accept choice,1
write_string choice,1
cmp byte[choice],31h
je upper
cmp byte[choice], 32h
je lower
cmp byte[choice], 33h
je tog
cmp byte[choice], 34h
je conc
jmp myend
upper:
mov esi, ip_str
mov edi, str2
mov cl,[cnt]
nextcu:
mov ch,[esi]
cmp ch,'a'
jb next1
cmp ch,'z'
ja next1
sub ch,20h
next1:
mov [edi],ch
inc esi
inc edi
dec cl
jnz nextcu
write_string newline, newl_len
write_string msg1,len1
write_string str2,6
jmp myend
lower:
mov esi, ip_str
mov edi, str2
mov cl,[cnt]
nextcl:
mov ch,[esi]
cmp ch,'A'
jb next2
cmp ch,'Z'
ja next2
add ch,20h
next2:
mov [edi],ch
inc esi
inc edi
dec cl
jnz nextcl
write_string newline, newl_len
write_string msg2,len2
write_string str2,6
jmp myend
tog:
mov esi,ip_str
mov edi, str2
again:
mov al,[esi]
cmp al,'A'
jb copy
cmp al,'Z'
ja toggle3
add al,20h
jmp copy
toggle3:
cmp al,'a'
jb copy
cmp al,'z'
ja copy
sub al,20h
copy:
mov [edi], al
inc esi
inc edi
dec cl
jnz again
write_string newline, newl_len
write_string msg3,len3
write_string str2,6
jmp myend
conc:
write_string newline, newl_len
write_string msg4,len4
accept str2,6
dec al
mov byte[cnt1],al
mov dl, byte[cnt1]
mov cl, byte[cnt]
write_string str2,6
mov esi, ip_str
mov edi, str3
again2:
mov al,[esi]
mov [edi],al
inc esi
inc edi
dec cl
jnz again2
mov esi,str2
again3:
mov al, [esi]
mov [edi],al
inc esi
inc edi
dec dl
jnz again3
write_string newline, newl_len
write_string msg5,len5
write_string str3,12
myend: ; end program
mov eax, 1 ;system call number (sys_exit)
mov ebx,0
int 0x80 ;call kernel
;==============================================================================================;
section .data
msg db 'Given string is '
len equ $ - msg
menu db 'Choose: ',0ah,'1) Uppercase',0ah,'2) Lowercase ', 0ah, '3) Toggle',0ah,'4) Concatenate', 0ah
menu_len equ $ -menu
msg1 db 'The uppercase string is: '
len1 equ $ -msg1
msg2 db 'The lowercase string is: '
len2 equ $ -msg2
msg3 db 'Toggled output: '
len3 equ $ -msg3
msg4 db 'Enter another string to concatenate: '
len4 equ $ -msg4
msg5 db 'Concatenated string: '
len5 equ $ -msg5
newline db " ", 0xa
newl_len equ $ - newline
;=================================================================================================;
section .bss
ip_str: resb 6
str2: resb 6
str3: resb 12
cnt: resb 1 ; stores len of input string
cnt1: resb 1
choice: resb 1
;===================================================================================================;