winapi - 汇编中输出前面的空间
问题描述
我正在编写一个使用 3 个宏(mGetHandles、mWriteFile、mReadFile)的程序集(x64)程序。我想产生以下输出(用户输入粗体):
你叫什么名字?约翰·史密斯
你的地址是什么?54321 Main St., La Mesa
很高兴认识你,
John Smith
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 Main St., La Mesa
为什么“54321 Main St., La Mesa”之前有空格?
解决方案
推荐阅读
- google-app-engine - TransientError:临时搜索服务错误 - Python Google App Engine 搜索
- xml - Augeas 对 XML 文件进行排序
- ios - iOS Widget 而不是 React Native 应用程序上的唯一 ID (UUID) 更改
- java - 在用户聊天活动中组织消息
- c# - C#- 在 datagrid-winforms 中动态填充单元格内的树视图
- c# - 从用户控制文件访问 MainWindow 标题
- robotframework - 如何在机器人框架中访问麦克风(相机)?
- python - Tornado 套接字服务器没有启动 Python
- java - 将购买的商品详细信息发送到 PayPal?
- python - pip 配置了需要 TLS/SSL 的位置