NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: yvz on January 06, 2014, 08:49:45 PM
-
Before starting, I want to denote that it's my first post here so if I made any mistake that violates forum rules, apologizes.
Well, I need to handle a very simple task yet my lack of knowledge about assembly programming prevents me to achieve. But I need to solve and understand this to continue to learning so here it is.
I got a c code without main, but only a function definition.
#include <stdio.h>
extern void hello_world();
void hello_world(){
printf("Hello World!");
}
And I need to call it within assembly. There'r many examples around web including here like this (http://forum.nasm.us/index.php?topic=1029.0). But I wont take any arguments I just need to call it and see it working. I coded this which is not working
section .data
section .text
global _start
global main
extern hello_world
_start :
call main
mov eax,1
int 80h
main :
;push ebp
;mov ebp, esp
call hello_world
;pop ebp
ret
My terminal commands are
gcc -c callee.c
nasm -f elf caller.asm
ld -s -o call callee.o caller.o -lc -I/lib/ld-linux.so.2
./call
All works without error but nothing happens. I'm trying to understand concept so I would come up with more questions :) Thanks in advance.
-
Hi yvz,
Only thing I can think of:
printf("Hello World!\n");
There's a "dirty little secret" to printf - it doesn't print anything until the buffer is flushed. The linefeed will flush the buffer. Exiting the program ought to flush the buffer also, so this probably won't work. When you do get it to print, it'll look better with the linefeed anyway. :)
I can't see anything wrong with what you've done, and unfortunately I'm still not in a position to test it. Maybe I'll fix that soon... I keep saying...
Best,
Frank
-
Wow, that's it. It works now. Thanks Frank. This was ridiculously simple and easy yet took almost a week for me jumping around forums, articles and examples.