News:

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

Line to long

Started by ecube, June 16, 2009, 03:44:05 AM

Previous topic - Next topic

ecube

I got error line to long while trying to call a function similar to wsprintf with over 30 parameters. I used ,\ to try and help extend it, but it only let me add a few more lines using that. So my question is, is there any other way to make masm read the entire thing without complaining, or do I have to try and break the params up, and idk.

dedndave

instead of using invoke, try pushing the parameters, then using call
push the last parm first

ecube

thing is i'm using mostly local buffs, so I have only so many registers I can lea/mov offset into, I can't push offset since is local, so idk, makes it more tricky, sigh.

dedndave

they don't neccessarily have to be in register
also, you can use the same register over and over

push MemLabel                  ;parm4
push 20                            ;parm3
mov eax,50
push eax                           ;parm2
lea eax,MemLabel[ebx+20]
push eax                           ;parm1
call SomeFunction

you don't have to pop off the stack after the call - the proc takes care of that
if all else fails, post the line and i can show you how to push it onto the stack
if you do that, tell us which are locals

mitchi

Does it work in GoAsm cube?

hutch--

Cube,

Is there any way you can break the strings up and join more of them together before calling wsprintfA ? Apart from that Dave's suggestion is probably the only way to do it unless you want to try something exotic like stack forwarding. There is another way but its messy, set the entire stack manually like LOCALS are done then write the address of each component for wsprintfA directly to stack memory. Then you pass ESP to a manual call to wsprintfA.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Hi E^cube,

You can break the long line with the support of a macro :

include     Demo.inc

.data

format1     db 'Integers from 1 to 70 : ',13,10,13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10
            db '%d , %d , %d , %d , %d , %d ,%d',13,10           
            db '%d , %d , %d , %d , %d , %d ,%d',13,10,0           


.data?

buffer      db 512 dup(?)

.code

start:

    pushREV 36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,\
            55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70

    pushREV ADDR buffer,ADDR format1,1,2,3,4,5,6,7,\
            8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,\
            25,26,27,28,29,30,31,32,33,34,35
           
    call    wsprintf
    add     esp,72*4
           
    invoke  StdOut,ADDR buffer
    invoke  ExitProcess,0

END start

[attachment deleted by admin]

dedndave

lol - ok - i am gonna generate a lot of flack here but that's ok, i'm gettin used to it

this method has a lot of potential to generate some efficient code
the command strings may be re-used and/or modified
similar strings may be created to replace all invoke's
a modified version of my Relat routine could be used at initialization to further optimize the program
have fun with this one, guys

;command string exec
;by dedndave

;--------------------------------------------------------------------------

        INCLUDE    \masm32\masm32rt.inc

;--------------------------------------------------------------------------

        .DATA

;an example command "string"

CmdStr0 dd 4                 ;4 bytes worth of parms
        dd STD_INPUT_HANDLE  ;parm 1
        dd GetStdHandle      ;command
;end of CmdStr0

        .CODE

;--------------------------------------------------------------------------

_main   PROC

        mov     esi,offset CmdStr0   ;get std input handle
        call    Cmand

        print   uhex$(eax),13,10

        inkey
        exit

_main   ENDP

;--------------------------------------------------------------------------

Cmand  PROC

        pop     ecx
        cld
        lodsd
        sub     esp,eax
        shr     eax,1
        shr     eax,1
        xchg    eax,ecx
        mov     edi,esp
        rep     movsd
        push    eax
        lodsd
        jmp     eax

Cmand   ENDP

;--------------------------------------------------------------------------

        END     _main

the method could be extended to execute multiple invokes with one command
i.e. strings could be created to make several calls
the Cmand routine would have to be modified to run in a zero-terminated loop, as an example
the byte value (4 in this case) could be bumped up to 5 and decremented to find the end of the multi-invoke strings
well - that's one way to do it
by using procs in between api calls, the entire program could essentially be written this way
with a state-machine that controls the string source pointer