0

NASM code:

section .text
        global _start


_start:
        mov eax,22


printDecimal:
        push eax
printDecimalSub:
        mov edx,0
        mov ecx,10
        div ecx

        push eax
        mov eax,4
        mov ebx,1
        mov ecx,edx
        add ecx,48
        mov edx,1
        int 80h
        pop eax

        cmp eax,0
        jne printDecimalSub

printBinary:

exit:
        mov eax,1

The code works but nothing is displayed on screen.
I don't understand where I made a mistake. I am on linux.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
suiciyom
  • 21
  • 5
  • 1
    `write` wants a pointer to a char, not a character by value, even when EDX=1. The canonical duplicate about this uses x86-64 with `syscall`, not 32-bit with `int 0x80`, but adapt as necessary or use the 32-bit code in [Add 2 numbers and print the result using Assembly x86](https://stackoverflow.com/a/28524951) – Peter Cordes Oct 06 '22 at 01:40
  • Once you make ECX point to the character (instead of being the character), you'll see that the number gets displayed in reverse! The value 123 appears on screen as "321". – Sep Roland Oct 06 '22 at 18:01
  • @SepRoland I know. I wanted to test whether the code I have written so far is correct. – suiciyom Oct 06 '22 at 18:03
  • @suiciyom Well it isn't! Solve the issue that @PeterCordes told you about with something like: `div ecx` `add edx, 48` `PUSH EDX` `MOV ECX, ESP` `push eax` `mov eax,4` `mov ebx,1` `mov edx,1` `int 80h` `pop eax` `POP EDX` – Sep Roland Oct 06 '22 at 18:14

0 Answers0