flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > The forever problem with procedures

Author
Thread Post new topic Reply to topic
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
Code:
;this doesn't works 
proc test,word,dword 
begin 
endp     


i can't pass a word and a dword as parameters...
anyone has macros that solve this problem ???
Post 30 Aug 2004, 07:34
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Gambino wrote:
Code:
;this doesn't works 
proc test,word,dword 
begin 
endp     


i can't pass a word and a dword as parameters...
anyone has macros that solve this problem ???


In Windows programming the stack should be dword aligned, so it is not a good idea to pass words as parameters. and actually I can't see any advantage of doing so. If you have some 16bit value, that you want to pass as argument, better pass it as dword and you can use only a part of it later in the procedure:

Code:
proc MyProc, argByte, argWord, argDWord
begin
     mov ax, word [argWord]
; or even:
     movsx  eax, word [argWord]
     movsx  ecx, byte [argByte]
     return
endp

; call:
; arguments:
;    al - some byte value
;    bx - some word value
;    ecx - some dword value
stdcall MyProc, eax, ebx, ecx
    


Of course macroses can be changed to allow different type of arguments, but it will make them more complex and hard to use, less readable, will slow down compilation, with very little gain of usefullness.
(IMHO of course)

Regards.
Post 30 Aug 2004, 08:26
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
I knew that i can pass the word as a dword and only use the 16 bit value from it but i wanted to pass 16bit and 32bit values...

Quote:
better pass it as dword and you can use only a part of it later in the procedure


That is not a solution...

I need that the macro really does what i say
Post 30 Aug 2004, 15:46
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
and do you realize what can it result in if you would be using such macro?
Post 30 Aug 2004, 18:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
Quote:
and do you realize what can it result in if you would be using such macro?


No i don't ! Razz

Will i break the proccessor in half if i run such a macro or what ?

I see that nobody has a solution for this...
Post 31 Aug 2004, 04:33
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 875
Location: Colombia
pelaillo
Gambino, no solution is needed for this.

The idea behind dword aligned is the performance:
If you have to work with a single word, your processor is not going to break in half, but the performance do in more than half Wink
A 32 bit processor spend the same clocks for an operation in full register than in a part of it in the best case.
Code:
mov eax,[.arg]
mov ax,[.arg]
mov al,[.arg]
    

The problems start when cache goes flushed when otherwise not needed, branch prediction cannot be performed because instructions need to be aligned for execution, usually you need to do tricky code to pack/unpack info and so on.
On the other hand, what would be the advantage?

Designed performance requires to work in multiple of 32 bits when processor is 32 bits.
Post 31 Aug 2004, 12:57
View user's profile Send private message Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
that's what i meant. Code will be slowed down greatly, even bugs may happen because of this under windoze, and no reason.
But it is possible to make macros that will in reality allocate 32bits, but set size of label to another size so only parto of 32bits will be used. would this be a solution?
Post 31 Aug 2004, 18:26
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
This is going really off-topic....
I just wanted to know if someone has or can make some proc macros that pass word and dword...
Nothing more.

I understand every risc implied... and i don't program for windoze...
I am programing an OS and i really need those macros...

Because Fasm dont has procedures built-in...like TASM I cant write procedures like i'm used to.
Post 31 Aug 2004, 21:43
View user's profile Send private message Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast
Gambino:

Please tell me, what is the purpose of passing a word value to the proc? It's very interesting.
Post 31 Aug 2004, 22:03
View user's profile Send private message Visit poster's website Reply with quote
Foamplast



Joined: 07 May 2004
Posts: 36
Location: Saratov, Russia
Foamplast
Gambino:

Suppose you are writing an OS for AMD64. Do you need the macro that passes a word using stack?
Post 31 Aug 2004, 22:06
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Gambino wrote:
I just wanted to know if someone has or can make some proc macros that pass word and dword...


OK, how you think will look the declaration syntax of such procedures and calls?

Btw, I had some plans to implement very universal macroses in Fresh library, but I decided not to make this, because every atempt to create universal StdCall library leads to unwanted decreasing of readability and compilation speed.
My suggestion is, if you need mixed code 16+32bit (note that in every reasonable application I can imagine - most probably OS loader) this code will be very very short, so you simply can write procedure in pure assembler without using "proc" macro. (you can replace "pushd" in "stdcall" macro with "push" in order to pass word arguments on calling)

Here: http://board.flatassembler.net/topic.php?t=1995 you can read more wide discussion about different syntaxes of StdCall macroses.

Regards.
Post 31 Aug 2004, 23:35
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
Procedure definition structure:

proc ProcedureName
.arg1 db ?
.arg2 dw ?
.arg3 dd ?

locals
.cloc1 dd ?
.cloc2 dw ?
endl

begin

locals
.loc1 dd ?
.loc2 dw ?
endl

locals
.loc3 db ?
.loc4 db ?
endl

endp

This should be everything i ever wanted from the procedure macro....
Post 01 Sep 2004, 04:56
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
Gambino wrote:
This should be everything i ever wanted from the procedure macro....


Imagine the tons of "dd ?" you have to type for every windows program. Also, the readability will be worse. Also, how you will call such procedures if someone type ".rect RECT" as an argument?

Anyway, if you are stubborn enough, refusing suggestions, you can use Fresh StdCallEx.inc as a base to write this variant. The arguments will use the approach now used for main local block (of course with different base (not "ebp-something", but "ebp+something")

Regards.
Post 01 Sep 2004, 06:31
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7108
Location: Slovakia
vid
gambino: yes, such macro can be writen, for example in this way
Code:
proc  some_proc,<arg1,dword>,<arg2,word>    

but i think nobody will ever write them because they are really useless. If you learn FASM's macrolanguage well enough maybe you 'll write such macros.
Post 01 Sep 2004, 20:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Gambino



Joined: 20 Jul 2003
Posts: 44
Location: Romania
Gambino
JohnFound

Please understand that i will not use this macros to write windows programs....
It will be used for OS programming.

And i am not stubborn, i am open to sugestions.
The only objection that i had is that i dont want to pass words like dwords and use only a word from that dword ( i think that creates confusion ).

Cool
Post 02 Sep 2004, 00:19
View user's profile Send private message Reply with quote
Dragontamer



Joined: 24 Aug 2003
Posts: 84
Dragontamer
By pretending words are dwords you gain advantages of speed and easiness. What more do you want?

Anyway, i guess it is possible if we play around with virtual so that you indead pass a dword, when you want a word, but it gets treated as a normal word Smile
Post 02 Sep 2004, 01:43
View user's profile Send private message 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-2019, Tomasz Grysztar.

Powered by rwasa.