I am VERY new to assembly and I know that this problem should be an easy fix. I have hit a dilemma though. I am trying to create a function that will simply print a message that is sent to it on screen. Essentially do,
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, message
mov edx, message length
int 0x80 ; execute
but some reason the length parameter is not sending right or I am not referencing it right. This should be a simple solution and any help would be great! :D
global _start
section .data
msg db "Hello, World!"
msgS equ $ - msg
section .text
_start:
push msg ;The first param. MESSAGE
push msgS ;The second param. MESSAGE SIZE
call print
mov eax, 1 ; sys_exit
mov ebx, 0 ; exit code is 0
int 0x80 ; execute
print:
push ebp ; Push ebp's old location onto the stack.
mov ebp, esp ; set ebp to be esp's current location.
mov eax, 4
mov ebx, 1
mov ecx, [esp+8] ;The first param. MESSAGE (we jump by 8 instead of 4 because we just pushed ebp into the stack.)
mov edx, [esp+4] ;The second param. MESSAGE SIZE
int 0x80
mov esp, ebp ; set esp back to what it was before this function
pop ebp ; set ebp back to what it was before this function
ret ; return back to before this function
When I run this code I do not get any results. I know that it has to be something wrong with the
mov edx, [esp+4]
code snippet because the string is 13 characters long. If I delete [esp+4]
and replace it with 13 and than delete the push msgS
before I called the function it works and prints the string.
I am very new to assembly and if you guys have any solution for me that would be awesome. I tried to google this, but I can not seem to find any results that work for me. I tried to rewrite and swap orders etc, but still did not work.
If I am doing a bad practice or something inside my code, correction is welcome.
P.S (Not concerning the question whatsoever). If you guys have any references where I can further study assembly (for newbie begineers) that would be great.