flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to use macro return val. in stdcall?/LocalVariable size?

Author
Thread Post new topic Reply to topic
Fr3m3n



Joined: 21 Apr 2006
Posts: 5
Fr3m3n
I have a macro:
Code:
macro hash tekst*
{
local c, _hash
_hash=0
virtual at 0
db tekst
b = $
repeat b
load c from 0+%-1
;hash = ((hash shl 5) or (hash shr 27))+c
_hash =((_hash shl 5) and 0xFFFFFFFF) or ((_hash shr 27) and 0xFFFFFFFF)+c
end repeat
end virtual
push _hash
}
    

1. Is this code possible:
stdcall somefunc,somearg,<hash "Alamakota">,somearg

without modifying pushd macro?
Just '_hash' alone (in last line of macro) don't work, neither do store macro (store dword _hash at $), store with conversion to ascii hex first, and dd _hash.

2. Can local variable have size, for example
local _hash:DWORD ;this don't work
In this macro i need _hash variable to act like dword - bits shifted beyond 31 bit must be 'lost'. 'and 0xFFFFFFFF' does the trick, but imho this is ugly.
Post 26 Dec 2006, 06:03
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
1. No, it's not possible without a modification to either "pushd" or "stdcall" macro. See also http://board.flatassembler.net/topic.php?t=4159

2. The "and 0xFFFFFFFF" is the only correct way.

In fact I'm thinking about making it signalize overflow error when you try to shift some bits beyond the available range, this would be more consistent with overall expression calculator's behavior...
Post 27 Dec 2006, 14:41
View user's profile Send private message Visit poster's website Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
Fr3m3n wrote:
In this macro i need _hash variable to act like dword - bits shifted beyond 31 bit must be 'lost'. 'and 0xFFFFFFFF' does the trick, but imho this is ugly.
Assembler constants/variables are always qwords but you could use the distributive law to get rid of one of the ands.

_hash = (((_hash shl 5) or (_hash shr 27)) and 0xFFFFFFFF)+c

This is equivalent but shorter. Actually, there's still a bug here - a small possibility that adding c could carry into bit 32. You should add c first, then do the and.

_hash = (((_hash shl 5) or (_hash shr 27)) + c) and 0xFFFFFFFF
Post 27 Dec 2006, 16:06
View user's profile Send private message Reply with quote
Fr3m3n



Joined: 21 Apr 2006
Posts: 5
Fr3m3n
Tomasz Grysztar wrote:

In fact I'm thinking about making it signalize overflow error when you try to shift some bits beyond the available range, this would be more consistent with overall expression calculator's behavior...

What about 'local a:DWORD' 'local b:BYTE' with default size of QWORD? This will maintain compatibility with old sources.
Is this what you are thinking of?

Goplat wrote:
Assembler constants/variables are always qwords but you could use the distributive law to get rid of one of the ands.

_hash = (((_hash shl 5) or (_hash shr 27)) and 0xFFFFFFFF)+c

This is equivalent but shorter. Actually, there's still a bug here - a small possibility that adding c could carry into bit 32. You should add c first, then do the and.

_hash = (((_hash shl 5) or (_hash shr 27)) + c) and 0xFFFFFFFF

You are right, thanks.
Post 27 Dec 2006, 23:20
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
Fr3m3n wrote:
What about 'local a:DWORD' 'local b:BYTE' with default size of QWORD? This will maintain compatibility with old sources.
Is this what you are thinking of?

The DWORD in "local a:DWORD" defines the size of data labelled by "a", not the size of (address) value stored in "a".
Post 27 Dec 2006, 23:25
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-2020, Tomasz Grysztar.

Powered by rwasa.