2
votes

i am very new to assembly although i have lots of c and c++ experience. my assembly code is supposed to print hello world like all first programs in a new language. it prints out hello world but also prints out some extra text:

hello world!
.shstrtab.text.data

and here is my assembly program:

section .text
    global _start       ;for the linker
    
_start:
    mov edx, length     ; message length
    mov ecx, message    ; message to write
    mov ebx, 1      ; file descriptor stdout
    mov eax, 4      ; system call number
    int 0x80    ; call kernel
    
    mov eax, 1  ;system call number for sys_exit to exit program
    int 0x80    ; call kernel
    
section .data
message db "hello world!"
length DD 10

if you know how to fix this also explain why is this happening. thanks.

extra info: i am using nasm assembler with ld linker

1
You want mov edx,[length] to load the value. You are loading the address which is likely a big number so you are printing extra stuff. You could also do length equ 10 or similar, then you don't need the brackets. PS: run your code through strace.Jester

1 Answers

1
votes

so the problem is in adding length as it gives the address of length variable but not the value. the answer is to use move edx, [length]. thanks to Jester for pointing me that out