Search code examples
stringassemblyinputnasm

How to ignore enter-key NASM win32


I need to ignore the enter on input to further compare the input string with other strings.

Bellow fragment of code input and output

;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

String has newline
Image


Solution

  • I figured out
    I just wrote the code that removes 0x0d and 0x0a from the string

        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