0
.intel_syntax noprefix
.global _start
.text

_start:
mov     eax, 4
mov     ebx, 1
mov     ecx, msg
mov     edx, 15
int     0x80

mov     eax, 1
mov     ebx, 14 
int     0x80

.data
msg:
.ascii "Hello, World!\n"

I am trying to compile the above code via GNU AS using the following commands:

asad@Arcturus:~/Desktop/ZJNK$ as --32 -msyntax=intel code.S -o code.o
asad@Arcturus:~/Desktop/ZJNK$ ld -m elf_i386 code.o -o a.out
asad@Arcturus:~/Desktop/ZJNK$ ./a.out 
asad@Arcturus:~/Desktop/ZJNK$ 

But I cannot get any output on the terminal. However, the exit code is still readable:

asad@Arcturus:~/Desktop/ZJNK$ echo $?
14

I am using 64-bit Linux and am able to run the above code via nasm after required changes.

What could have gone wrong?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Kraken
  • 189
  • 5

1 Answers1

2

To load the address of msg, use

mov ecx, offset msg
prl
  • 11,716
  • 2
  • 13
  • 31
  • Thank you. I thought `offset` was a MASM thing only. – Kraken May 12 '18 at 16:29
  • Now, do I use BYTE PTR etc as well where needed? Also where can I find a good manual on GAS's flavor of intel syntax? – Kraken May 12 '18 at 16:31
  • 2
    @Kraken Check the [GNU as manual](https://sourceware.org/binutils/docs/as/). If you want to use Intel syntax, I recommend you to ditch GNU as in favour of nasm. – fuz May 12 '18 at 16:41
  • @Kraken: GAS `.intel_syntax` is MASM-like, not NASM. It might be documented somewhere, but most people use it as a read-only format. (e.g. I prefer NASM syntax, and `objdump -drwC -Mintel` is very readable for me even thought it's more like MASM than NASM. But if I was writing code for GAS instead of NASM/YASM, I'd use AT&T syntax because that's what most other projects do, e.g. glibc and the Linux kernel). – Peter Cordes May 12 '18 at 19:04