kevinpt / opbasm

Open PicoBlaze Assembler
http://kevinpt.github.io/opbasm/
MIT License
60 stars 13 forks source link

Using PUSH and POP from an INCLUDEd file doesn't work #27

Open evilactually opened 5 years ago

evilactually commented 5 years ago

I'm calling use_stack from top level file that includes multiple other files with subroutines. Those routines use stack operations like PUSH and POP to save registers. When I try to assemble I'm getting the error:

Stack is not initialized. Use use_stack() before any operation  stdin line 7
ERROR: m4 failure on file serial.psm

It seems to me like M4 pre-processor is ran on included files before the top file, so it doesn't recognize that I'm setting up the stack in in the top file. How can I reorganize my code so that I can use stack macros and still have it split up in multiple files? Is this an issue with macros or am I doing something wrong?

My code looks like this:

; program.psm:
namereg s3, SP      ; Protect s3 for use as the stack pointer
use_stack(SP, 0x3F) ; Start stack at end of 64-byte scratchpad

INCLUDE "subroutines.psm"
;subroutines.psm:
foo:
       PUSH(s7,s6)
       ...  
       POP(s7,s6)
       RETURN

EDIT: I'm working around it by adding use_stack at the top of all included files, not sure if that's actually a good idea, but it works.