News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Actual assembly question

Started by Magnum, February 27, 2016, 03:20:45 PM

Previous topic - Next topic

Magnum

This is an actual assembly question. :-)

Wine under Linux claims to run 100s of programs.

It can not run this fireworks program. (and every program that I have written and/or modified.)

I filed a bug report with Wine.

They asked for the source code and the exe.

And this was their last response.

(And boy are they a bit anal retentive.)

QuotePlease don't paste such long source, attach it instead.

While firework2.exe downloaded from the above mentioned site work under
Windows XP it crashes under Windows 7 almost same way as under Wine.

Looks like a stack corruption caused by hand written floating point/MMX code.

Can someone test it under Win 7 please ?

What the heck is "hand written floating point/MMX code" ??

I thought all FPU code was hand written.

Appreciate the help.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Works fine on XP but with Win7-64 it chokes in line 354 with access violation:
    fld dword ptr[edi+ecx+4]


Magnum

Thanks, I will research what that means.

Fpu code is pretty foreign to me.

My brain can only hold so much info.

Second semester Organic Chemistry was a D for me.

The book was twice the size of a bible. :-)

Some other responses.

Quote1. There are pushes without corresponding pops or stack adjustments
2. what calling convention is used, are there registers that should be
preserved?
3. giving that code also uses threads , there are also other
possibilities for crash
4. wine is less prohibitive than Windows regarding not preserving
registers
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Looks like I have to relearn assembly.

No problem, I know I need too. :-)

Does this push have the appropriate pop ?

Quotepush eax
    fild dword ptr[esp]
    fsqrt
    fidiv lum                  ; this code is -nonlinear-
    fld1
    fsubrp st(1),st(0)
    fmul st(0),st(0)           ; curve
    fmul st(0),st(0)           ; curve more
    fimul tff
    fistp dword ptr[esp]

    pop ebx
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm


******* You don't seem to know what is the preservation rule.
Add "uses esi edi ebx"  to your proc using those register.
********use local variables instead of [esp + N] ,you can just made errors with this form of adressing.
The form [esp + n] can be use only when the prog is working and you want to win a few ยต seconds.
****** use a debugger
Fa is a musical note to play with CL

Magnum

I have not written any assembly in over a year.

I will look up uses and the preservation rule.

According to here

https://msdn.microsoft.com/en-us/library/k1a8ss06.aspx

QuoteWhen using __asm to write assembly language in C/C++ functions, you don't need to preserve the EAX, EBX, ECX, EDX, ESI, or EDI registers.

Since I do not have Win 7, I can not test if my modifications will work with Win 7.

So, did Win 7 become more strict in what works as opposed to XP ?





Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm

#6
except if have made a real mistake , the code i have downloaded is in masm language not in c.
You need to preserve the registers.
When you made an escape from c with the _asm directive,the c compiler take care of that for you.
It's not the case for a masm compiler.
Rewrite your code with the preserve rule and local variable,I will test it on Windows 10.

MonPROC PROC uses esi edi ebx MyArg:DWORD
           Local othervariable[4]:BYTE       ;or Local othervariable:DWORD       
ret
MonPROC endp
Fa is a musical note to play with CL

Magnum

Thanks.

I looked thru the code examples and could not find an example of

uses esi edi ebx

I need an example to study.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

C:\MASM32\SOURCE\fire.asm(603) : error A2137: too few arguments to INVOKE


Light_Flash3 PROC uses ebx esi edi x1:DWORD, y1:DWORD, lum:DWORD, src:DWORD, des:DWORD,
my:DWORD, x2:DWORD, y2:DWORD, tff:DWORD

LOCAL mx:DWORD
    mov eax,lum
    shr eax,1                  ; Light_Flash: dynamic 2D lighting routine
    mov lum,eax                ; does not uses any pre-computed data
    mov tff,255                ; ie. pure light frum tha melting cpu core :)
    mov eax,maxx
    mov mx,eax
    mov eax,maxy
    dec eax
    mov my,eax
    mov esi,src
    mov edi,des
    xor eax,eax
    mov y2,eax
ylp3:                          ; 2x2 instead of per pixel lighting
    xor eax,eax                ; half the quality, but higher speed
    mov x2,eax
xlp3:
    mov eax,y2
    sub eax,y1
    imul eax
    mov ebx,x2
    sub ebx,x1
    imul ebx,ebx
    add eax,ebx
    mov edx,lum
    imul edx,edx
    xor ebx,ebx
    cmp eax,edx
    ja @F                      ; jump to end causes time waves
    push eax
    fild dword ptr[esp]
    fsqrt
    fidiv lum                  ; this code is -nonlinear-
    fld1
    fsubrp st(1),st(0)
    fmul st(0),st(0)           ; curve
    fmul st(0),st(0)           ; curve more
    fimul tff
    fistp dword ptr[esp]

    pop ebx
    imul ebx,01010101h
@@:
    mov eax,y2
    imul maxx
    add eax,x2
    lea eax,[eax+eax*2]
    mov edx,maxx
    lea edx,[edx+edx*2]
    add edx,eax
   
    movd MM2,ebx               ; simply add with saturation
    movq MM0,[esi+eax]         ; gamma correction is against this code
    psllq MM2,32
    movq MM1,[esi+edx]
    movd MM3,ebx
    por MM2,MM3
    paddusb MM0,MM2
    movd [edi+eax],MM0
    paddusb MM1,MM2
    psrlq MM0,32
    movd [edi+edx],MM1
    movd ebx,MM0
    psrlq MM1,32
    mov [edi+eax+4],bx
    movd ecx,MM1
    mov [edi+edx+4],cx
    emms
@@:
    mov eax,x2
    add eax,2
    mov x2,eax
    cmp eax,mx
    jbe xlp3
    mov eax,y2
    add eax,2
    mov y2,eax
    cmp eax,my
    jbe ylp3
    ret
Light_Flash3 ENDP
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm

C:\MASM32\SOURCE\fire.asm(603) : error A2137: too few arguments to INVOKE

Flash PROTO   x:DWORD,y:DWORD,z:DWORD

invoke Flash,1,2  ;error A2137: too few arguments to INVOKE
invoke Flash,1,2,3  ;correct

There is not only Light_Flash3 who use esi edi ebx.
Use the first post,and put your new asm (the zip can be replaced)

other soluce
.code
Flash PROC x:DWORD,y:DWORD,z:DWORD
ret
Flash ENDP
start:
        invoke Flash,1,2,3  ;work without proto because the proc is placed before
end start


Fa is a musical note to play with CL

Magnum

I was told this is the problem.

Can someone help me understand and fix it ?

Quote--- snip ---
FireThread:
    [...]
    sub ebp,12                 ; as 3 local variables
--- snip ---

The register %ebp was never properly initialized, effectively corrupting the variables of the parent function.

Depending on the Windows version, the registers are initialized a bit different, effectively hiding all the trouble on Windows XP.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm

Firethread PROC uses esi edi ebx
     Local JKg:DWORD,JKL:DWORD,HJL:DWORD

invoke exitthread ;written as i can
ret
Firethread ENDP

To not close the main prog:
invoke CloseHandle,Htread
The thread is not close immediatly,need time

invoke WaitForSingleObject,Htread,INFINITE



Fa is a musical note to play with CL

Magnum

I do not understand what you want me to do.

I made some changes.

WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
Quotepush esi
    push edi
    push ebx

And I popped those register before the return.

Could you test it in Win 7 ?

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Going back to an earlier post.

Quote--- snip ---
FireThread:
    [...]
    sub ebp,12                 ; as 3 local variables
--- snip ---

The register %ebp was never properly initialized, effectively corrupting the variables of the parent function.

Was ebp not properly initialized ?

If it wasn't, how do I fix it ?

If I try enuf things, eventually something will work. :-)

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

Quote from: Magnum on February 29, 2016, 12:20:32 PM
Was ebp not properly initialized ?

If it wasn't, how do I fix it ?

we don't know - you can't show one line of code and expect us to gleen the context

but, i am guessing....

    sub     ebp,12

generally, we load EBP with the contents of ESP at some point
this creates a "stack frame"
i.e., while ESP goes up and down due to PUSHes and POPs, EBP remains stable, providing a fixed reference point

after the stack frame base pointer has been initialized, we modify ESP to create stack space for locals, not EBP

    push    ebp
    mov     ebp,esp                 ;EBP = stack frame base pointer
    sub     esp,12                  ;create stack space for 3 dword local variables

; body of routine code here

    mov     esp,ebp
    pop     ebp
    ret