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
|
.386
.model flat, stdcall
Include windows.inc
Include kernel32.inc
Includelib kernel32.lib
include user32.inc
includelib user32.lib
;-------------------------------------------------------------------------------------------------------------------
.data
msg BYTE "...: Hello binary World! :...",13,10,"Please enter a character : ",0
;-------------------------------------------------------------------------------------------------------------------
.data?
consoleInHandle DWORD ? ; handle to standard input device
consoleOutHandle DWORD ? ; handle to standard output device
buffer BYTE 512 DUP(?)
NbBytesWritten DWORD ? ; number of bytes written
CharAnswer BYTE ?
bytesRead DD ?
;-------------------------------------------------------------------------------------------------------------------
.code
start:
call Initialize
invoke WriteConsole,
consoleOutHandle, ; console output handle
offset msg, ; address of buffer to write characters from
sizeof msg, ; number of character cells to write to
0, ; coordinates of first cell to write to
0 ; address of number of cells written to
call ReadChar
mov CharAnswer, al
invoke WriteConsole,
consoleOutHandle, ; console output handle
offset CharAnswer, ; address of buffer to write characters from
sizeof CharAnswer, ; number of character cells to write to
0, ; coordinates of first cell to write to
0 ; address of number of cells written to
call ReadChar
invoke ExitProcess,0
;-------------------------------------------------------------------------------------------------------------------
Initialize PROC ; Get the standard console handles for input and output,
pushad
invoke GetStdHandle, STD_INPUT_HANDLE
mov [consoleInHandle],eax
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov [consoleOutHandle],eax
popad
ret
Initialize ENDP
;-------------------------------------------------------------------------------------------------------------------
ReadChar PROC ; Reads one character from standard input. The character is not echoed on the screen. Waits for the character if none is currently in the input buffer.
LOCAL saveFlags:DWORD
; Receives: nothing
; Returns: AL = ASCII code
pushad
;invoke GetConsoleMode,consoleInHandle,ADDR saveFlags ; Get & save the current console input mode flags:
;invoke SetConsoleMode,consoleInHandle,0 ; Clear all flags
invoke ReadConsole, ; Read a single character from input buffer:
consoleInHandle, ; handle of a console input buffer
ADDR buffer, ; address of buffer to receive data
1, ; number of characters to read
ADDR bytesRead, ; address of number of characters read
0 ; reserved
invoke SetConsoleMode,consoleInHandle,saveFlags ; Restore the previous flags state:
popad
mov al,buffer ; return the input character
ret
ReadChar ENDP
;-------------------------------------------------------------------------------------------------------------------
end start |
Partager