【问题标题】:How to ignore enter-key NASM win32如何忽略输入键 NASM win32
【发布时间】:2021-07-29 00:47:43
【问题描述】:

我需要忽略输入时的输入以进一步将输入字符串与其他字符串进行比较。

下面是代码输入输出片段

;get output handle
    push dword STD_OUTPUT_HANDLE
    call GetStdHandle
    mov [hstdout],eax
    mov eax, 1000h


    ;get input handle
    push dword STD_INPUT_HANDLE
    call GetStdHandle
    mov [hstdin],eax

    ;Read
    push 0
    push actlen2 ;Pointer to a DWORD for number of characters read to be returned
    push 11
    push string
    push dword [hstdin]
    call ReadConsoleA

    ;Write
    push 0
    push actlen
    push 11
    push string
    push dword [hstdout]
    call WriteFile

字符串有换行符
Image

【问题讨论】:

  • 你有输入的长度,所以检查最后一个字符是否是换行符。如果是,请用0 覆盖它。 (或者只是无条件地这样做,假设它是一个换行符。或者 CR LF 如果这个环境在输入时给你一个 2 字节的换行符序列。)就像在使用 Linux 系统调用的How do I ignore line breaks in input using NASM Assembly? 中一样;您的 WinAPI 调用的想法相同。
  • 感谢帮助,我知道了

标签: string assembly input nasm


【解决方案1】:

我想通了
我刚刚编写了从字符串

中删除 0x0d 和 0x0a 的代码
    mov ecx,11; str len(and num of loop iterations)
    mov eax,string
    jmp ignore_enter
change_byte:
    mov bl,0
    mov byte[eax+ecx],bl;change byte to 0
ignore_enter:
    cmp byte[eax+ecx], 0x0a; compare ecx byte of string with 0x0a
    je change_byte; if equal change_byte
    cmp byte[eax+ecx], 0x0D; compare ecx byte of string with 0x0d
    je change_byte; if equal change_byte
    loop ignore_enter
    

【讨论】:

  • 我是菜鸟,这是愚蠢的解决方案,但它有效
猜你喜欢
  • 2011-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-03
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
相关资源
最近更新 更多