flat assembler
Message board for the users of flat assembler.

Index > Main > define sized constant

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 13:32
Hi!
From manual:
c8 = byte -1
c32 = dword -1
defines two different constants, the first one fits in 8 bits, the second one fits
in 32 bits.

But real code don't work:
tchar0 = byte 0
cmp [esi], tchar0

Error: operand size not specified.

Where I wrong?
Post 02 Sep 2010, 13:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 02 Sep 2010, 13:43
Use:
Code:
cmp byte[esi],tchar0    
Also declaring a constant with '=' will not preserve the size. You might want to use 'equ' instead.
Code:
tchar0 equ byte 0    
Post 02 Sep 2010, 13:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 13:52
Dimas wrote:
Hi!
From manual:
c8 = byte -1
c32 = dword -1
defines two different constants, the first one fits in 8 bits, the second one fits
in 32 bits.
These size operators are meant only to apply to the way the values are defined. In the first case the result value will be 0FFh, in the second case it will be 0FFFFFFFFh. But they are still just ordinary numbers, so that when using them in other places, you still have to provide enough context so that the size of operation will be known.
Post 02 Sep 2010, 13:52
View user's profile Send private message Visit poster's website Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 13:54
But on Unicode:
cmp word [esi], 0 (or cmp [esi], word 0)

if sizeof.TCHAR... like this:
macro stosc {
if sizeof.TCHAR = 1
stosb
else
stosw
end if
}
But on size prefics it's not work. Why?
Post 02 Sep 2010, 13:54
View user's profile Send private message Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 14:20
I wont make code universal for ANSI and Unicode, and include 'win32wx.inc' mast be enough for this. In this case I have numerical constant sizeof.TCHAR.
And this code wrong:
if sizeof.TCHAR = 1
tchar equ byte
else
tchar equ word
end if
cmp [esi], tchar 0

Good code:
if sizeof.TCHAR = 1
cmp [esi], byte 0
else
cmp [esi], word 0
end if

But size prefics may be present in thousand operands.
How make macro for this purpose?
Post 02 Sep 2010, 14:20
View user's profile Send private message Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 15:20
Main module:
...
eUnicode equ TRUE ;selector for Unicode _in one place_ !!!
include '..\_macro.asm'
...

macro.asm:
...
define eUnicode_ 0
match =FALSE, eUnicode {
tchar fix byte
include 'win32ax.inc'
define eUnicode_ 1
}
match =TRUE, eUnicode {
tchar fix word
include 'win32wx.inc'
include 'encoding\win1251.inc'
define eUnicode_ 1
}
match =0, eUnicode_ {display 'Define eUnicode constant'
err}
...

Thanks to all.

Last question. Why this code don't work for undefined constant:
match , eUnicode {err}
Post 02 Sep 2010, 15:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 02 Sep 2010, 15:29
Dimas wrote:
Last question. Why this code don't work for undefined constant:
match , eUnicode {err}
Use this:
Code:
match eUnicode,eUnicode {err}    
By definition undefined constants have no replacement so are simply text strings that match to themselves.
Post 02 Sep 2010, 15:29
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 15:47
revolution wrote:
Use this:
Code:
match eUnicode,eUnicode {err}    
Even better would be:
Code:
match =eUnicode,eUnicode {err}    
Post 02 Sep 2010, 15:47
View user's profile Send private message Visit poster's website Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 15:50
match eUnicode,eUnicode {err}

match TRUE always (then eUnicode defined or undefined).
Post 02 Sep 2010, 15:50
View user's profile Send private message Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 15:52
match =eUnicode,eUnicode {err}

Yes!!!
Post 02 Sep 2010, 15:52
View user's profile Send private message Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 15:59
from the foregoing it follows simple addon in macro.asm

Code:
match =FALSE, eUnicode {
        tchar fix byte
        include 'win32ax.inc'
        }
match =TRUE, eUnicode {
        tchar fix word
        include 'win32wx.inc'
        include 'encoding\win1251.inc'
        }
match =eUnicode, eUnicode {display 'Define eUnicode constant'
        err}    


Thanks!
Post 02 Sep 2010, 15:59
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 16:06
That's not the right way to use "fix" - it is interpreted with highest priority (before the actual preprocessing) and therefore is not affected by "match" directive.
Post 02 Sep 2010, 16:06
View user's profile Send private message Visit poster's website Reply with quote
Dimas



Joined: 02 Sep 2010
Posts: 17
Dimas 02 Sep 2010, 16:11
tchar equ byte
...
tchar equ word

That's right.
Post 02 Sep 2010, 16:11
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 02 Sep 2010, 18:06
Tomasz Grysztar wrote:
revolution wrote:
Use this:
Code:
match eUnicode,eUnicode {err}    
Even better would be:
Code:
match =eUnicode,eUnicode {err}    
Not simply "even better", probably "only true". This one can give unexpected result (yep, I'm pushing it to the limit, but match is so powerful ;-)
Code:
match 13, 10 { db "Hello, world!", 13, 10 }    
Post 02 Sep 2010, 18:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 18:11
baldr wrote:
Tomasz Grysztar wrote:
revolution wrote:
Use this:
Code:
match eUnicode,eUnicode {err}    
Even better would be:
Code:
match =eUnicode,eUnicode {err}    
Not simply "even better", probably "only true".
The one given by revolution would work if one wanted to check for variable defined with empty value, like:
Code:
match eUnicode,eUnicode { display 'A' } ; match
define eUnicode
match eUnicode,eUnicode { display 'B' } ; no match    
I use this trick sometimes.
Post 02 Sep 2010, 18:11
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 02 Sep 2010, 18:41
Tomasz Grysztar,

I've meant side effect of such match:
Code:
match a, a { match anything, a \{ db "a defined" \} }    
Post 02 Sep 2010, 18:41
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 18:48
What side-effect? This nesting seems redundant.

The way of using the trick I mentioned is perhaps better seen when it is written this way:
Code:
match anything,a { display 'a not defined' }
define a
match anything,a { display 'a not defined' }; now it is "defined" (that is: empty)    
The trick is to "define" something in sense of giving it an empty value.
Post 02 Sep 2010, 18:48
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 02 Sep 2010, 19:35
Tomasz Grysztar,

I've understood the trick first time, thanks. My example was bad indeed.
Code:
define c b
match b, a { match =b, c \{ display "matched" \} }    
Looks like that inner match should succeed… but it doesn't. Proper backslashing all the way. Wink
Post 02 Sep 2010, 19:35
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 02 Sep 2010, 19:49
baldr wrote:
Code:
define c b
match b, a { match =b, c \{ display "matched" \} }    
Looks like that inner match should succeed… but it doesn't. Proper backslashing all the way. Wink
Oh yes, one should be careful when choosing names.

Or...
Code:
define c b
match b, a { match =\b, c \{ display "matched" \} }    
Is that what you mean? Smile
Post 02 Sep 2010, 19:49
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 03 Sep 2010, 04:51
Tomasz Grysztar,

Almost. I mean that missing '=' can cause subtle errors:
Code:
match 1, UNICODE {
;...
  match 1, WIN32 \{    
My first high-level programming language was FORTRAN-IV so I can easily adopt the idea of literal constant's value being accidentally redefined; can anybody else? Wink
Post 03 Sep 2010, 04:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.