-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathConsole_Output_MASM_32.asm
More file actions
47 lines (40 loc) · 1.25 KB
/
Console_Output_MASM_32.asm
File metadata and controls
47 lines (40 loc) · 1.25 KB
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
; Console Output
; Materials - MASM (32-bit)
; Copyright (c) 2017 Hall & Slonka
; Solution must use system call information from Chapter 10
; Use the CONSOLE subsystem (in project properties)
; Build, then run in a console window
.386
.MODEL FLAT, stdcall
.STACK 4096
GetStdHandle PROTO, nStdHandle:DWORD
WriteConsoleA PROTO,
hConsoleOutput:DWORD, ; output handle
lpBuffer:PTR BYTE, ; pointer to buffer
nNumberOfCharsToWrite:DWORD, ; size of buffer
lpNumberOfCharsWritten:PTR DWORD, ; num bytes written
lpReserved:DWORD ; not used (NULL)
ExitProcess PROTO, dwExitCode:DWORD
.data
bytesWritten DWORD 0 ; for WriteConsoleA
stdHandle DWORD 0 ; for WriteConsoleA
s1 BYTE "Hello Universe", 13, 10, 0
lenS1 = ($ - s1)
.code
_main PROC
print:
; get STDOUT handle
push -11 ; request STD_OUTPUT_HANDLE (-11)
call GetStdHandle ; call WinAPI to get console handle
mov stdHandle, eax ; save stdHandle
push 0 ; reserved, push NULL
push OFFSET bytesWritten ; bytes written
mov eax, lenS1
push eax ; bytes to write
push OFFSET s1 ; string address
push stdHandle ; STD_OUPUT_HANDLE
call WriteConsoleA ; call win api to write text to console
done:
INVOKE ExitProcess, 0
_main ENDP
END