简体   繁体   中英

Single char not printing. x86-32 intel assembly

I am trying to print a single byte from my buffer into stdout, but I am not getting any output, I have looked up how to print a single byte, and it IS in fact getting stored/moved as expected (Used gdb to debug). the byte even gets saved to ecx at the end but there isn't any output. What could be the issue? I am new to assembly and have been banging my head for several hours now. Thank you for the help.

`

global _start

section .data
    buffer: times 100 db 0

section .start
_start:
    mov eax, 3
    mov ebx, 0
    mov ecx, buffer                ; Enter input, example: 12345
    mov edx, 10
    int 80h

    movzx esi, byte [buffer+1]     ; Extract one byte from the input buffer: Successful
    push esi                       ; Byte is successfully pushed

print:
    pop edi                        ; Byte gets successfully popped

    mov eax, 4
    mov ebx, 1
    mov ecx, edi                   ; Here's the issue, it gets saved to ecx but no output
    mov edx, 15
    int 80h

exit:
    mov eax, 1
    mov ebx, 0
    int 80h

` As is aid, if i input "12345" the byte "2" (or 0x32) IS getting pushed/popped/moved correctly, it's just not printing Thank you

mov ecx, edi; Here's the issue mov ecx, edi; Here's the issue Exactly. Function sys_write expects ecx to point at the string but you loaded ecx=0x00000032 which doesn't point anywhere.

Replace mov ecx, edi with mov ecx, buffer+1 and mov edx, 15 with mov edx,1 to print just one character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM