News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

call instead of invoke!

Started by LAS3R, February 12, 2005, 04:57:15 PM

Previous topic - Next topic

LAS3R

This question have problay already been posted here but i tried search but found nothing!

is there way to change invoke to call i masm? like tasm use, been using masm for while now but like old tasm "call" syntax instead!

pbrennick

There are many people who prefer call over invoke.  For me, either is okay, but to answer your question.  Push the parameters of an invoke statement, one at a time, in reverse order and then change invoke to call.  That is all it takes.

invoke  LoadString, hInst, Eax, Offset szWork, LengthOf szWork

becomes;

        Push LengthOf szWork            ; Size of our buffer
        Push Offset szWork              ; Buffer to load string into
        Push Eax                        ; Resource #
        Push hInst                      ; Instance
        Call LoadString                 ; Load the tip from STRINGTABLE


Hope this answers your question,
Paul

pbrennick

BTW:  Yo further amplify on what I have said, invoke is recommended over call because it is a macro that actually does the same thing but has the further advantage that the assembler can match the invoke with a proto statement to make sure you have all the parameters correct and correctly stated.  With the call statement it is too easy to make errors that are almost impossible to debug.

Paul

Alloy

If you are making a series of calls in the same procedure it can be considered a cheap optimization if the values pushed onto the stack are already in registers. I've used this doing a number of back to back bitblts.
We all used to be something else. Nature has always recycled.

MichaelW

And if you need to pass the address of a procedure parameter or local variable (from within a procedure), you need to use ADDR instead of OFFSET for invoke, and LEA for the call method. For example:

lea   eax, parm1
push  eax
lea   eax, local1
push  eax
...
call  ---

eschew obfuscation

pbrennick

Of course that type of optimization only is effective if you are making more than one call to the same procedure, otherwise the added overhead of loading the registers will slow down your code.  Once the data is in the registers thinks go faster on successive calls, just make sure you make use of the 'uses' option in the proc statement or you will be asking for trouble.

Paul

tenkey

LAS3R,

Which TASM call syntax are you talking about?

The simple CALL which takes only a destination address and represents exactly one x86 instruction? MASM has the simple call.

Or the extended CALL syntax which allows parameters similarly to INVOKE in MASM? In MASM, the extended call syntax exists only as INVOKE.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

Alloy

Quote from: pbrennick on February 12, 2005, 09:10:54 PM
Of course that type of optimization only is effective if you are making more than one call to the same procedure, otherwise the added overhead of loading the registers will slow down your code.  Once the data is in the registers thinks go faster on successive calls, just make sure you make use of the 'uses' option in the proc statement or you will be asking for trouble.

Paul

It seems to work without the USES directive. Its handy when the same parameters are reused alot to push them onto stack along with those that change. The registers save having to push from memory to memory and the routine cleans the stack with Call ___, Call ___, Call ___, .........
We all used to be something else. Nature has always recycled.

pbrennick

Actually, that is not correct if you are using ebx, esi or edi.  They must always be preserved.  Either by using the 'uses' option or push and pop instructions at the start and end of the procedure.  Anything else is asking for disaster.  With such a limitted amount of registters you are bound to need to use on e or more of them.

Paul

Alloy

I don't play with ebx, esi and edi when the stack is changing or have local variables. The optimization is solely from pushing constants that are in registers onto the stack before they get trashed by Windows' API calls.

We all used to be something else. Nature has always recycled.

pbrennick

That's good, other's follow our lead, that is why I felt I needed to clarify.  I am not finding fault with your methods.  I just want the newbies to know the rules they need to follow in order to generate safe code.

Paul

Alloy

I agree. I never assume any registers are preserved once the code flow is handed over to windows.

We all used to be something else. Nature has always recycled.

hutch--

Alloy,

It is probably worth disassembling what you write to see what TASM did with it. It will always reduce down to opcodes so it is better to undestand what the opcode production looks like than rely on a higher level procedure calling technique.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

LAS3R

what i meant was, i want same syntax as invoke but instead of "invoke whatever, push eax, push ebx, push edx" as example , i would be able use "call whatever, push eax, push ebx, push edx" , i know it's not tasm but just replace invoke to call!

so i mean:

call whatever, push eax, push ebx, push edx

and not, already know this one but like invoke beacuse got all on same line, but don't like invoke, want call :)

push edx
push ebx
push eax
call whatever

is it possible to change?

pbrennick

I already answered this question.
Paul