0

So basically I'm trying to write a hello world program in assembly. The program exits as it should but no string is printed along the way. There are no errors anywhere either. I suspect that I am declaring or using the string wrong somehow.

    .intel_syntax noprefix

.data

msg:
    .ascii "Hello World"

.text

.globl _start

_start:
    mov eax, 4 #call write
    mov ebx, 1 #output into stdout
    mov ecx, msg #what to write
    mov edx, 11 #length of what to write
    int 0x80

    mov eax, 1 #exit
    mov ebx, 0
    int 0x80

I have also tried replacing

mov ecx, msg

with

mov ecx, [msg]

but it doesn't seem to make a difference.

2
  • 1
    What assembler are you using? Commented Oct 15, 2013 at 15:19
  • To be honest I'm unsure what an assembler actually is but to create the binary i use the commands "as -o HelloWorld.o HelloWorld.s" and "ld -o HelloWorld HelloWorld.o" Commented Oct 15, 2013 at 15:22

1 Answer 1

3

You need to use mov ecx, offset msg or lea ecx, msg. Also make sure you are assembling as 32 bit code in case you are on a 64 bit system.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.