Я пишу программу сборки (x64), которая использует 3 MACROS (mGetHandles, mWriteFile, mReadFile). Я предполагаю произвести следующий вывод (пользовательский ввод в жирный шрифт ):
Как тебя зовут? Джон Смит Какой у Вас адрес? 54321 Main St., La Mesa Приятно с Вами познакомиться, Джон Смит 54321 Main St., La Mesa
Это мой код:
CONSOLE equ -11
KEYBOARD equ -10
CR equ 0dh
LF equ 0ah
extern GetStdHandle: PROTO
extern WriteFile: PROTO
extern ReadFile: PROTO
extrn ExitProcess: PROTO
.data
prompt1 byte 'What is your name? '
prompt2 byte 'What is your adress? '
hello byte 'Nice to meet you, ', CR, LF
myname byte 40 dup(' '), CR, LF, 0
myadress byte 40 dup(' ')
crlf byte CR, LF, 0 ;used to get a new line
.data?
stdin qword ? ;handle to console standard in
stdout qword ? ;handle to console standard out
numWrite qword ? ;number bytes actually written
numRead qword ? ;number bytes actually read
mGetStdHandle MACRO
;Get handle ID to console window
mov rcx, CONSOLE ;subsystem:console
call GetStdHandle ;handle in rax
mov stdout, rax ;save out handle
mov rcx, KEYBOARD ;keyboard code
call GetStdHandle ;handle in rax
mov stdin, rax ;save in handle
ENDM
mWriteFile MACRO
;Display message on console window
mov rcx, stdout ;parm1 = console handle
lea rdx, prompt1 ;parm2 = ascii message
mov r8, lengthof prompt1 ;# bytes to display (write)
lea r9, numWrite ;& to store #bytes written
call WriteFile ;display message
;Read ASCII from the keyboard
mov rcx, offset crlf ;cr, lf
mov rcx, stdin ;parm1 = keyboard handle
lea rdx, myname ;parm1 = ascii buffer
mov r8, lengthof myname ;# bytes of read
lea r9, numRead ;& to store #bytes actually read
call ReadFile ;get keystrokes
;Display message on console window
mov rcx, stdout ;parm1 = console handle
lea rdx, prompt2 ;parm2 = ascii message
mov r8, lengthof prompt2 ;# bytes to display (write)
lea r9, numWrite ;& to store #bytes written
call WriteFile ;display message
;Read ASCII from the keyboard
mov rcx, offset crlf ;cr, lf
mov rcx, stdin ;parm1 = keyboard handle
lea rdx, myadress ;parm1 = ascii buffer
mov r8, lengthof myadress ;# bytes of read
lea r9, numRead ;& to store #bytes actually read
call ReadFile ;get keystrokes
ENDM
mReadFile MACRO
mov rcx, stdout ;parm1 = console handle
lea rdx, hello ;parm2 = ascii message
mov r8, lengthof hello ;# bytes to display (write)
add r8, numRead ;& to store #bytes actually read
sub r8, 2
lea r9, numWrite ;& to store #bytes written
call WriteFile ;display message
mov rcx, stdout ;parm1 = console handle
lea rdx, myadress ;parm2 = ascii message
mov r8, lengthof myadress ;# bytes to display (write)
add r8, numRead ;& to store #bytes actually read
sub r8, 2
lea r9, numWrite ;& to store #bytes written
call WriteFile ;display message
ENDM
mBye MACRO retcode
mov rcx, retcode
callExitProcess
ENDM
.code
mainCRTStartup PROC
mGetStdHandle
mWriteFile
mReadFile
call ExitProcess
mainCRTStartup ENDP
END
Вывод, который я получаю («___» представляет пустое пространство): Приятно с Вами познакомиться, Джон Смит __________ 54321 Главная ул. Ла Меса Почему есть место перед "54321 Main St., La Mesa"?