-
Notifications
You must be signed in to change notification settings - Fork 0
/
cApp_11.asm
230 lines (172 loc) · 4.81 KB
/
cApp_11.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
.386
.model flat, stdcall
option casemap:none
include std.inc
; Function prototypes
outputString proto :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
stringLength proto :DWORD
charUpper proto :DWORD, :DWORD
charLower proto :DWORD, :DWORD
strtok proto :DWORD, :DWORD
SData struc
dwNumber dd ?
SData ends
; Unitialized data section
.data?
szDestString db 104h dup (?)
; Data section
.data
szWindowTitle db "Aseshsoft ConsoleApp", 0h
szMessage db "This is a message", 0h
.code
start:
push ebp
mov ebp, esp
push offset szWindowTitle
call SetConsoleTitle
call main
mainMessageLoop:
push 1Bh
call GetAsyncKeyState
test eax, eax
jne exitMainLoop
push 64h
call Sleep
jmp mainMessageLoop
exitMainLoop:
leave
xor eax, eax
ret
main proc
local hConsoleHandle:DWORD
push STD_OUTPUT_HANDLE
call GetStdHandle
cmp eax, 0h
je _exit
mov hConsoleHandle, eax
; Set text color to red
mov eax, 4h
or eax, 8h
push eax
push hConsoleHandle
call SetConsoleTextAttribute
push offset szDestString
push offset szWindowTitle
call charLower
print str$(szDestString)
; Close the std output handle
push hConsoleHandle
call CloseHandle
_exit:
ret
main endp
;-----------------------------------------------------
; Name: outputString
; Desc: Output the specified string on the screen
;-----------------------------------------------------
outputString proc hConsoleOutput:DWORD, b:DWORD, d:DWORD, e:DWORD, f:DWORD
local dwHandle:DWORD ; File handle
test eax, 0h
jz _closeHandle
jnz _return
_closeHandle:
push dwHandle
call CloseHandle
_return:
ret
outputString endp
;-----------------------------------------------------
; Name: stringLength
; Desc: Return the string length
;-----------------------------------------------------
stringLength proc dwStringOffset:DWORD
local dwCharCount:DWORD ; Variable for holding character occurences in a string
mov dwCharCount, 0h
mov esi, dwStringOffset ; Move the offset of string argument into esi register
xor ecx, ecx ; Zero out ecx register
_scanString:
mov ecx, dwCharCount ; Move the character counter variable into ecx register
cmp byte ptr [esi + ecx], 0h ; Compute a character to see if it is a null character
je _final
jnz _increment
mov eax, dwCharCount ; Move the result into the eax register
je _exitLoop
_increment:
inc esi ; Increment the offset to string
inc dwCharCount ; Increment the char counter
jmp _scanString
_final:
mov eax, dwCharCount
ret
_exitLoop:
ret
stringLength endp
;-----------------------------------------------------
; Name: charUpper
; Desc: Conver lower case characters to uppercase
;-----------------------------------------------------
charUpper proc dwStringOffset:DWORD, dwDestStringOffset:DWORD
cmp byte ptr dwStringOffset, 0h ; Compute to see if it's a null character
je _exit
cmp byte ptr dwStringOffset, 41h
jg _gt_comp1
jmp _inc_offset
_gt_comp1:
_inc_offset:
inc dwStringOffset
_exit:
ret
charUpper endp
;-----------------------------------------------------
; Name: charLower
; Desc: Convert upper case character to lowercase
;-----------------------------------------------------
charLower proc dwStringOffset:DWORD, dwDestStringOffset:DWORD
xor eax, eax
xor esi, esi
_compute:
mov eax, dwStringOffset ; Move a character to the specified register
cmp byte ptr [eax], 0h ; Compute the first character to see if it's a NULL character
je _exit ; If it's a null character then exit
mov esi, eax ; Move the offset into the specified register
cmp byte ptr [eax], 41h ; Compute with 'A'
jl _inc_offset ; Increment the offset since it's not an alphabet
jge _gt_41h ; The input character is either 'A' or greater
_inc_offset:
inc byte ptr dwStringOffset ; Increment the string offset
jmp _compute ; Compute the incremented character
_gt_41h:
cmp byte ptr [eax], 5ah ; Compute the character with 'Z' (5a)
jg _inc_offset ; Jump if it's greater than 'Z'
jle _lower_Char ; Jump if less than 5a
_add_hex:
add esi, 20h
jmp _inc_offset
_lower_Char:
add esi, 20h
jmp _inc_offset
_exit:
mov [dwDestStringOffset], esi
xor eax, eax
ret
charLower endp
;-----------------------------------------------------
; Name: strtok
; Desc: Finds a token in a string and returns the
; remaining string
;-----------------------------------------------------
strtok proc szString:DWORD, szToken:DWORD
push ebp
mov ebp, esp
; Determine the length of the string
push offset szString
call StringLength
; Move the number of characters in the string into ecx
mov ecx, eax
_loop:
jecxz _loop
leave
xor eax, eax
ret
strtok endp
end start