I've never used inline assembly shockingly, and I'm just wondering how/if I can do something.

Bit of background; I'm coding a basic OS kernel, I have various subroutines written in assembly and amongst others I have a puts subroutine that is an attempt at mimicking puts in C. In order to call puts I move the address of my string to the esi register and call puts:

mov esi, strDATE
	call puts

I'm using the GCC compiler (and possibly in the future G++), how could I get puts to print a string from C? I guess I'm looking for something like...

char HW[] = "Hello World!";
	asm("mov HW, esi");
	asm("call puts");

(inverted code because GCC uses AT&T syntax I believe?).

6 Years
Discussion Span
Last Post by Auraomega

Just figured this out myself, couple of assumptions I made were wrong. Posting the fix here in-case anybody ever stumbles across this page.

char HW[] = "Hello World!";
	asm("call cls");
	asm("mov %0, %%esi" : : "r" (HW)); // this is the important line
	asm("call puts");

Basically my assumptions about inline assembly were incorrect, reading the GCC manual I discovered this is how it should be done:

asm("assembly here" : "output" (variable) : "input" (variable) : "registers"

Edited by Auraomega: Hit post before finished >.>

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.