Page 4 of 4

Re: desirable assembler features

Posted: Sun Jul 29, 2012 12:31 am
by GARTHWILSON
I managed to synthesize a stack in the C32 assembler (a way that could be done in nearly any assembler) so as to be able to nest program structures, and wrote up an article about structure macros, with accompanying source code (which I've tested but have not used extensively yet), at http://wilsonminesco.com/StructureMacros/index.html .

Re: desirable assembler features

Posted: Fri Nov 09, 2012 6:59 am
by Movax12
Hi,

I implemented some hl stuff with ca65 and come across this thread. It's easy to have a stack in ca65.

Code: Select all


.macro push stackname, value, sp   ; stackname, value to assign, stackpointer
	.ident( .sprintf("%s_%04X_",stackname,sp)) .set value
	sp .set sp + 1
.endmacro


.macro pop stackname, var, sp    ; stackname, identifier to assign value to, stackpointer
	sp .set sp - 1
	var  .set .ident( .sprintf("%s_%04X_",stackname,sp))	
.endmacro

These two macros give you as many stacks as you like, just identify which stack you are working with by name. I would like to write up better documentation, but there is some decent stuff here: http://mynesdev.blogspot.ca/2012/10/ca6 ... again.html

Although my goal is a NES project, this would work for any 6502 (just standard 6502 at this point since I am targeting the NES.)

Edit: Actually, I was thinking, it complicates these macros slightly, but makes for nicer code elsewhere - the macros should take care of the stack pointers too:

Code: Select all

.macro push stackname, value

	.ifndef ::.ident(.sprintf("_%s_POINTER", stackname))
		::.ident(.sprintf("_%s_POINTER", stackname)) .set 0
	.endif

	::.ident( .sprintf("%s_%04X_",stackname,::.ident(.sprintf("_%s_POINTER", stackname)))) .set value

	::.ident(.sprintf("_%s_POINTER", stackname))  .set ::.ident(.sprintf("_%s_POINTER", stackname))  + 1
.endmacro


.macro pop stackname, var ; puts a -1 in var if there is a problem
	 
	 .ifndef ::.ident(.sprintf("_%s_POINTER", stackname)) ; unknown stack pointer
			var .set -1 
			.exitmacro
	.endif
	
	 ::.ident(.sprintf("_%s_POINTER", stackname))  .set ::.ident(.sprintf("_%s_POINTER", stackname))  - 1
	 .if ::.ident(.sprintf("_%s_POINTER", stackname)) < 0 ; stackpointer is negative
		var .set -1 
	.else
		var  .set ::.ident( .sprintf("%s_%04X_",stackname,::.ident(.sprintf("_%s_POINTER", stackname))))	
	.endif
	
.endmacro