Skip to content

More Advanced Inline Assembly – Nope!

March 24, 2017

LCC1802 has a simple form of inline assembly: if you code asm(“foo”); you get “foo” directly emitted in the assembly output from the compiler. This is fine for the simplest cases (seq,req etc.) but it would be nice to be able to access local variables. I found a more advanced version of the assembly patch i used which seems to be meant to do exactly that.
This is from more than a decade ago but LCC itself is much older than that so that’s ok. I worked it into my working copy but the results so far are not encouraging:
The fragment below shows the C code and the resulting assembly code. The asm calls are just to get the substitutions for the variable names for a global:g, two parameters: p1 and p2, and two locals: L1,L2. The global g generates _g which is fine but i knew that! the locals L1 and L2 generate -4 and -6 instead of something like 2 and 0 or register references. The parameters generate 0 and 2 instead of (I would have hoped) referring to the registers or, worst case, offsets of 6 and 8 from the stack pointer. I may poke at this again and it may just be a matter of adding the frame size(which is actually 6) but in the end i question whether it’s worth it.

int g=7;
void turnqoff(int p1,int p2){
	int L1,L2;
	L1=42; L2=43;
	asm(";	L1:$L1)\n");
	asm(";	L2:$L2\n");
	asm(";	g:$g\n");
	asm(";	p1:$p1 p2:$p2\n");
*************compiled code follows**************
	dw 7
_turnqoff:		;framesize=6
	reserve 4
	st2 R12,'O',sp,(6+1)			
	inc memaddr	
	str2 R13,memaddr			
;void turnqoff(int p1,int p2){
;	L1=42; L2=43;
	st2I 42,'O',sp,(2+1); ASGNI2(addr,acon)
	st2I 43,'O',sp,(0+1); ASGNI2(addr,acon)
;	asm(";	L1:$L1)\n");
;	L1:-4)
;	asm(";	L2:$L2\n");
;	L2:-6
;	asm(";	g:$g\n");
;	g:_g
;	asm(";	p1:$p1 p2:$p2\n");
;	p1:0 p2:2

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: