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?).

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"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.