flat assembler
Message board for the users of flat assembler.

Index > Main > Anyway to check defines after they've been declared?

Author
Thread Post new topic Reply to topic
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
sid123 09 Jul 2014, 09:20
Hi,
I'm writing a VM which uses my own executable format. It uses fasm as the assembler and all instructions are done through macros. What I want is to check for the stack size given by the programmer, and if it's not defined then fall back to default.
My programs look like this:
Code:
include 'cpu.inc'
DEFINE STACK_SIZE 200
..code....
    

"cpu.inc" contains the header for the programs and a few macros that define CPU instructions.
Basically I want to check if STACK_SIZE was defined by the programmer anywhere in the source code and then set the "stack_buf" entry manually in the header.
Something like:
Code:
ifdef STACK_BUF
dd _end_bss + STACK_BUF
else 
; Fall back to default stack size
dd _end_bss + 200
endif
    

Cheers,
sid123

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 09 Jul 2014, 09:20
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 09 Jul 2014, 10:54
Use assembling stage constants instead of preprocessor one:
Code:
STACK_SIZE = 200    
Then use:
Code:
if defined STACK_SIZE    
Post 09 Jul 2014, 10:54
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 09 Jul 2014, 11:54
You should follow JohnFound's suggestion, because for anything that is numeric and needs to be forward-referenced you should use the assembly-time variables.

But I'd like to show a little trick that demonstrates how to use some of the newest fasm's features to make it work with your "DEFINE STACK_SIZE" sources:
Code:
postpone { local S
           irpv s,STACK_SIZE \{ S = s \}
           if defined S
             STACK_BUF = S
           end if }

if defined STACK_BUF
  dd _end_bss + STACK_BUF
else
  ; Fall back to default stack size
  dd _end_bss + 200
end if    
This code defines the global STACK_BUF label with the last value of STACK_SIZE symbolic variable (in case when there was more than one DEFINE). STACK_BUF, as opposed to STACK_SIZE, is assembly-time variable and can be used with "if defined".
Post 09 Jul 2014, 11:54
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.