0

I'm just a noob trying to write a simple "Hello World" program in 32-bit Linux assembly (AT&T syntax). Here's my code:

.section .data
msg:
        .ascii "Text\n"
msgLen:
        .long 5

.section .text
.globl _start
_start:
        movl $4, %eax
        movl $1, %ebx
        movl msg, %ecx
        movl msgLen, %edx
        int  $0x80

        movl $1, %eax
        movl $0, %ebx
        int  $0x80

I assemble the program, link it, run it, and... nothing. I don't get any errors whatsoever; it just doesn't work and I don't get any output. I tried changing the value of msgLen, but nothing I do seems to work. It's driving me mad at this point. Any help would be greatly appreciated!

Update: So after looking at Peter Cordes's comment, I prepended $ before msg and msgLen, and my program successfully printed "Text" and a newline, but also other gibberish. This is the output I get:

Text
�`�@�` �`'�`print.omsgmsgLen__bss_start_edata_end.symtab.strtab.shstrtab.text.data@�"!�`�       ��      �,�'$
0xPictor
  • 63
  • 6
  • Run `strace ./a.out` to trace the system calls your program makes. You want `mov $msg, %ecx` to put the address in ECX, rather than doing a 4-byte load, – Peter Cordes May 06 '20 at 06:47
  • `mov $msgLen, %edx` passed the *address* as a length. That's a large integer. Again, use `strace`. If you want `msgLen` to be an assemble-time integer constant, define it with `.equ` or `msgLen = . - msg`, not by making it the address of an integer in memory. Then `mov $msgLen, %edx` *would* be the correct instruction. – Peter Cordes May 06 '20 at 07:15

0 Answers0