-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw5 version 2
214 lines (169 loc) · 3.28 KB
/
hw5 version 2
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
INCLUDE Irvine32.inc
.data
MAX = 80
charInput BYTE MAX+1 DUP (?)
countArray BYTE 62 DUP(0)
initialMessage BYTE "Please Enter A String",10,0
resultsMessage BYTE "The following characters have been counted",10,0
.code
main proc
mov edx, OFFSET initialMessage
call WriteString
;This portion of our code will read in the string from the user
mov edx, OFFSET charInput
mov ecx, MAX
call ReadString
;Initialize Data For Loop 1
mov ecx, MAX
mov esi, OFFSET charInput
L1: ;Lowercase Loop
mov al, [esi] ;This moves the content of the current element into the eax register
cmp al, 97
jge LARGERCASEONE
jmp FINISHCASEONE
LARGERCASEONE:
cmp al, 122
jle SMALLERCASEONE
jmp FINISHCASEONE
SMALLERCASEONE: ;Case - LOWERCASE character
sub al, 97
mov edi, OFFSET countArray
movzx ebx, al
add edi, ebx
add edi, 26
mov eax, [edi]
add eax, 1
mov [edi], eax
FINISHCASEONE:
inc esi
loop L1
;Initialize Data For Loop 2
mov ecx, MAX
mov esi, OFFSET charInput
L2: ;Uppercase Loop
mov al, [esi] ;This moves the content of the current element into the eax register
cmp al, 65
jge LARGERCASETWO
jmp FINISHCASETWO
LARGERCASETWO:
cmp al, 90
jle SMALLERCASETWO
jmp FINISHCASETWO
SMALLERCASETWO: ;Case - LOWERCASE character
sub al, 65
mov edi, OFFSET countArray
movzx ebx, al
add edi, ebx
mov eax, [edi]
add eax, 1
mov [edi], eax
FINISHCASETWO:
inc esi
loop L2
;Initialize Data For Loop 3
mov ecx, MAX
mov esi, OFFSET charInput
L3: ;Number Loop
mov al, [esi] ;This moves the content of the current element into the eax register
cmp al, 48
jge LARGERCASETHREE
jmp FINISHCASETHREE
LARGERCASETHREE:
cmp al, 57
jle SMALLERCASETHREE
jmp FINISHCASETHREE
SMALLERCASETHREE: ;Case - LOWERCASE character
sub al, 48
mov edi, OFFSET countArray
movzx ebx, al
add edi, ebx
add edi, 52
mov eax, [edi]
add eax, 1
mov [edi], eax
FINISHCASETHREE:
inc esi
loop L3
;DISPLAY RESULTS TO USER
mov edx, OFFSET resultsMessage
call WriteString
mov esi, OFFSET countArray
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ecx, 26
mov al, 65
L4:
mov bl, al
mov al, [esi]
cmp al, 0
jnz M1
mov al, bl
jmp Z1
M1:
mov al, bl
call WriteChar
mov bl, al
mov al,'-'
call WriteChar
mov al, [esi]
call WriteDec
mov al, 10
call WriteChar
mov al, bl
Z1:
inc al
inc esi
loop L4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ecx, 26
mov al, 97
L5:
mov bl, al
mov al, [esi]
cmp al, 0
jnz M2
mov al, bl
jmp Z2
M2:
mov al, bl
call WriteChar
mov bl, al
mov al,'-'
call WriteChar
mov al, [esi]
call WriteDec
mov al, 10
call WriteChar
mov al, bl
Z2:
inc al
inc esi
loop L5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ecx, 10
mov al, 48
L6:
mov bl, al
mov al, [esi]
cmp al, 0
jnz M3
mov al, bl
jmp Z3
M3:
mov al, bl
call WriteChar
mov bl, al
mov al, '-'
call WriteChar
mov al, [esi]
call WriteDec
mov al, 10
call WriteChar
mov al, bl
Z3:
inc al
inc esi
loop L6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke ExitProcess,0
main endp
end main