flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > BUG? "if ~defined"

Author
Thread Post new topic Reply to topic
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 20 Feb 2008, 07:33
I try compile this:
Code:
if ~defined SizeOfKernel
   SizeOfKernel = 10000
end if    

compiler say me:

Quote:
M:\KRYAZH\kernel\drivers.std>fasm memory.asm
flat assembler version 1.67.26 (437300 kilobytes memory)
error: code cannot be generated.


some help me?

PS: FASM for windows
Post 20 Feb 2008, 07:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20422
Location: In your JS exploiting you and your system
revolution 20 Feb 2008, 07:42
Code:
macro IfNotDef_Set labl,value {
  local here
  if ~defined labl | defined here
             labl = value
                here = 1
    end if
}

IfNotDef_Set SizeOfKernel, 10000    
Post 20 Feb 2008, 07:42
View user's profile Send private message Visit poster's website Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos 20 Feb 2008, 07:58
It does not approach (
Post 20 Feb 2008, 07:58
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386 20 Feb 2008, 23:01
.

> I try compile this:
> if ~defined
> compiler say me:
> error: code cannot be generated.

RTFM ... FASM.TXT , 2.2.6 , line 2590 Laughing

Anyway, wouldn't it be nice to have #if defined at preprocess level, working like in C ?

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 20 Feb 2008, 23:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 21 Feb 2008, 02:21
yup... we do have match, but that is at least a bit tricky to use. But i am not very sure if it would be "implementable" to current FASM.
Post 21 Feb 2008, 02:21
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 02 Mar 2008, 21:17
I use "if ~defined" in my code alot, it works just fine. What I think (don't wanna make a whole thread), is that the FASM pre-processor should check operands (constants) of certain instructions. for example, FASM actually allowed me to compile "shl eax,55". This is not alllowed to execute, yet FASM let it compile. Just like dividing by zero...
Post 02 Mar 2008, 21:17
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 02 Mar 2008, 23:46
Alex: you are mixing things. Preprocessor has nothing to do with instruction operands.

And FASM simply translates from human language to machine code, if instruction is encodeable in current mode, it is fine for FASM to allow it.

By the way, did you check that "shl eax, 55" causes exception? AFAIK shift value is truncated, and shift by contant larger than register is one of tricks to detect processor.
Post 02 Mar 2008, 23:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 03 Mar 2008, 00:04
hmm, I've debugged in Olly a program where I used a shift by more than 60, and Olly had a comment by it saying "value out of range", or something of the sorts. Maybe I'm wrong, but I thought that it doesn't execute when you try.

Yeah, I generalize when I think of pre-processor.
Post 03 Mar 2008, 00:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20422
Location: In your JS exploiting you and your system
revolution 03 Mar 2008, 00:46
shl reg,55 is a valid instruction so fasm should assemble it. Internally the CPU masks all shift and rotate counts to 5bits in 32bit modes and 6bit in 64bit modes. So shl reg,55 is the same as shl reg,23
Post 03 Mar 2008, 00:46
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 03 Mar 2008, 04:07
Some people hide data in extra bits of instructions - immediate shifts is one case of this. Selective encoding can also be a signature of code generation.

As to the thread topic, I found myself trying to do the same thing - even though I knew better - until I wrote these macros.
Code:
macro IFDEF nm,val {
  match =val,nm {
}
FEDFI fix }

macro IFNDEF nm {
  match =nm,nm {
}
FEDNFI fix }    
First one handles conditional assembly based on value of symbol, and the second one only assembles when the symbol is not defined (blank is defined).
Code:
IFNDEF DEBUG
  DEBUG equ int3
FEDNFI;DEBUG    
One problem is if the symbol is defined to itself then it is considered undefined. For example if "DEBUG equ DEBUG" then IFNDEF passes through the match.

Another possible problem exists if DEBUG is defined as a macro. match can't do anything with a macro definition - only works with symbols/constants.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 03 Mar 2008, 04:07
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.