Looking around, I finally found something that explains a little about linking asm to C. (found something here which led to a bigger page elsewhere)
I found this (after adapting to Nasm):
#include <stdio.h>
int maxofthree(int, int, int);
int main() {
printf("%d\n", maxofthree(1, -4, -7));
printf("%d\n", maxofthree(2, -6, 1));
printf("%d\n", maxofthree(2, 3, 1));
printf("%d\n", maxofthree(-2, 4, 3));
printf("%d\n", maxofthree(2, -6, 5));
printf("%d\n", maxofthree(2, 4, 6));
return 0;
}
and
global maxofthree
section .text
maxofthree:
mov eax, [esp+4]
mov ecx, [esp+8]
mov edx, [esp+12]
cmp eax, ecx
cmovl eax, ecx
cmp eax, edx
cmovl eax, edx
ret
Which makes sense to me.
But this one works but I don't understand the message: part
$ cat helloworld.asm
; ----------------------------------------------------------------------------
; helloworld.asm
;
; This is a Win32 console program that writes "Hello, World" on one line and
; then exits. It needs to be linked with a C library.
; ----------------------------------------------------------------------------
global main
extern printf
section .text
main:
push message
call printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0
Is the message part proper syntax for Nasm? It seems to lack a name.
I saw several other examples with a data part like that