-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathListing_3_3.txt
65 lines (49 loc) · 2.23 KB
/
Listing_3_3.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
includelib kernel32.lib ; Windows kernel interface
GetStdHandle proto ; Function to retrieve I/O handles
WriteConsoleA proto ; Function writes to command window
ReadConsoleA proto ; Function reads from command window
Console equ -11 ; Device code for console text output.
Keyboard equ -10 ; Device code for console text input.
ExitProcess proto
.code
; Main program that reads text message from user through command
; window keyin and displays it in same command window.
main proc
sub RSP,40 ; Reserve "shadow space" on stack.
; Obtain "handles" for console I/O streams
mov RCX,Console ; Console standard output handle
call GetStdHandle ; Returns handle in register RAX
mov stdout,RAX ; Save handle of console display.
mov RCX,Keyboard ; Console standard input handle
call GetStdHandle ; Returns handle in register RAX
mov stdin,RAX ; Save handle for keyboard input.
; Display the prompt message.
mov RCX,stdout ; Handle to standard output device
lea RDX,pmsg ; Pointer to prompt message
mov R8,lengthof pmsg ; Number of characters to display
lea R9,nbwr ; Number of bytes actually written.
call WriteConsoleA ; Write text string to command box.
; Read input line from user keyboard.
mov RCX,stdin ; Handle to standard input device
mov R8,20 ; Maximum length to receive
lea RDX,keymsg ; Memory address to receive input
lea R9,nbrd ; Number of bytes actually read.
call ReadConsoleA ; Read text string from command box.
; Echo the message input back to the user.
mov RCX,stdout ; Handle to standard output device
lea RDX,keymsg ; Pointer to message that was input
mov R8,nbrd ; Length (bytes) of input message
lea R9,nbwr ; Number of bytes actually written.
call WriteConsoleA ; Write text string to command box.
add RSP,40 ; Replace "shadow space" on stack
mov RCX,0 ; Set exit status code to zero.
call ExitProcess ; Return control to Windows.
main endp
.data
pmsg byte "Please enter text message: "
keymsg byte 20 DUP (?) ; Memory buffer for keyboard input
stdout qword ? ; Handle to standard output device
nbwr qword ? ; Number of bytes actually written
stdin qword ? ; Handle to standard input device
nbrd qword ? ; Number of bytes actually read
end