0

Hi I had to write a AT&T x86 assembly to Intel assembly.

.section .data

str:    .ascii  "Hello world!\n"
    strlen = . - str

num:    .long   1337

.section .text

.global _start

_start:
    movl    $4, %eax
    movl    $1, %ebx
    movl    $str, %ecx
    movl    $strlen, %edx
    int $0x80

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

That's AT&T

.intel_syntax noprefix
.section .data

str:    .ascii  "Hello world!\n"
    strlen = . - str

num:    .long   1337

.section .text

.global _start

_start:
    mov eax, 4 
    mov ebx, 1
    mov ecx, offset str
    mov edx, strlen
    int 0x80

    mov eax, 1 
    mov ebx, 0
    int 0x80

Why do I need this offset. I found it in another Stack Overflow question.

Compiling with:

as --32 -o hello.o helloworld-a.asm

ld -m elf_i386 -o hello hello.o

./hello

When I don't use it, I have no output on console.

Thanks :)

Jester
  • 56,577
  • 4
  • 81
  • 125
Jan Wolfram
  • 145
  • 8
  • 2
    Because you want the address. Without that you get a memory reference in intel syntax mode. – Jester Oct 28 '19 at 21:27
  • Is it because of the label, because I saw also other code, where they define the string a different way like "hello db "Hallo Welt!",0xa" and did not use it – Jan Wolfram Oct 28 '19 at 21:32
  • That is not gnu assembler syntax though. – Jester Oct 28 '19 at 21:34
  • @JanWolfram: Presumably that was NASM syntax. NASM is a different flavour of Intel syntax where a bare symbol name is always the address; you'd need `mov edx, [str]` in NASM to do a 4-byte load from the label address. But GAS `.intel_syntax noprefix` is MASM-like. See https://stackoverflow.com/tags/intel-syntax/info for some about the differences. – Peter Cordes Oct 29 '19 at 01:16
  • PS: use a debugger and/or `strace` to see what args you're passing to system calls. Even an AT&T syntax disassembler would have shown you the problem, since you know the difference between `mov $str, %ecx` and `mov str, %ecx`. – Peter Cordes Oct 29 '19 at 02:41

0 Answers0