Assembly print on screen using pop ecx

399 views Asked by At

I want to print out the word 'hi' on the screen but pop ecx is not working . When I change it to mov ecx, esp then the word 'hi' is printing.

Can someone explain me why pop ecx is not working?

global _start

section .bss

    output resb 2

section .text

_start:

    mov ecx, 0x6968
    mov [output], ecx
    mov ecx, [output]
    push ecx
display:

    mov eax, 0x4
    mov ebx, 0x1
    pop ecx
    mov edx, 2
    int 0x80

    xor eax, eax
    mov eax, 0x1
    xor ebx, ebx
    int 0x80
1

There are 1 answers

1
Jester On

The write system call expects an address. You should replace mov ecx, [output] with mov ecx, output (notice the missing brackets) to load the address. Then it should work with the push/pop as-is.

PS: next time please review your question and fix the formatting if you see it's broken.