News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Actual assembly question

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

Previous topic - Next topic

Magnum

Attached is source code.

It works in XP, but not in Win 7.

I need it to work in Win 7 and then it should work under Wine.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Dave,

You get 100 gold stars.

;sub ebp,12                 ; as 3 local variables
     sub esp,12

I learned that the original code did create the stack space for 3 dword local variables correctly.

This correction should allow it to work in Win 7.
Would appreciate someone testing this on Win 7.


Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm

it work in win10
can you post your final source code ?
Fa is a musical note to play with CL

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm


There is a problem with allocated memory,you add Something to the original pointer and it is this one
who must be used for free

FireThread:
       
    invoke SetThreadPriority,idThread1,THREAD_PRIORITY_NORMAL;HIGHEST
    invoke GetDC,hwnd
    mov wnddc,eax
    invoke GetProcessHeap
    mov hHeap,eax
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,4194304
    mov Heapbitmap1,eax       ;<<<<<<<<<<<<<<<<<< keep this one for free
    add eax,4096               ; blur: -1'th line problem
    mov bitmap1,eax
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,4194304
    mov Heapbitmap2,eax      ;<<<<<<<<<<<<<<<<<< keep this one for free
    add eax,4096               ; blur: -1'th line problem
    mov bitmap2,eax
    mov eax,nd
    shl eax,4
    add eax,SPARC
    mov sb,eax                 ; size of FShell = nd*16+8
    imul nb                    ; array size   = nb*sb
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,eax
    mov hFShells,eax

    finit                      ; initialise floating point unit
    mov ax,07fh                ; low precision floats
    mov word ptr[esp-4],ax     ; fireworks... not space rockets
    fldcw word ptr[esp-4]

    ; PROBLEM HERE ?? ebp was never properly initialized
    ;sub ebp,12                 ; as 3 local variables
     sub esp,12 ; CORRECT statment

    mov eax,nb
    mov [ebp],eax
    mov eax,hFShells
    mov [ebp+4],eax
initshells:
   
lp1:
    mov eax,motionQ
    mov dword ptr[ebp+8],eax
lp2:
    mov eax,nb
    mov [ebp],eax
    mov eax,hFShells
    mov [ebp+4],eax
lp3:
    invoke FShell_render,[ebp+4],[ebp]
    mov eax,GMode
    mov ecx,offset FShell_explodeAG
    mov ebx,offset FShell_explodeOS
    test eax,eax
    cmovz ecx,ebx
    push [ebp+4] ;
    call ecx
    test eax,eax
    jns @F
    invoke random,maxy
    push eax
    mov eax,maxx
    add eax,eax
    invoke random,eax
    mov edx,maxx
    shr edx,1
    sub eax,edx
    push eax
    push [ebp+4]
    call FShell_recycle
@@:
    mov eax,sb
    add [ebp+4],eax
    dec dword ptr[ebp]
    jnz lp3
    dec dword ptr[ebp+8]
    jnz lp2
    mov eax,EMode
    test eax,eax
    jz r1
    mov eax,CMode              ; switch pre/post blur according to -
    test eax,eax               ; current chemical in fire
    jz @F
    invoke Blur_MMX2
@@:
    invoke Light_Flash3,lightx,lighty,flash,bitmap1,bitmap2
    invoke SetDIBitsToDevice,wnddc,0,0,maxx,maxy,\
           0,0,0,maxy,bitmap2,ADDR bminf,DIB_RGB_COLORS
    mov eax,CMode
    test eax,eax
    jnz r2
    invoke Blur_MMX2
    jmp r2
r1:
    invoke SetDIBitsToDevice,wnddc,0,0,maxx,maxy,\
           0,0,0,maxy,bitmap1,ADDR bminf,DIB_RGB_COLORS
    mov eax,maxx
    imul maxy
    lea eax,[eax+eax*2]
    invoke RtlZeroMemory,bitmap1,eax
r2:
    inc fcount                 ; count the frames
    fild flash
    fmul flfactor
    fistp flash
    invoke Sleep,5             ; control, if frames rate goes too high
    mov eax,stop
    test eax,eax
    jz lp1
    invoke ReleaseDC,hwnd,wnddc
    invoke HeapFree,hHeap,0,Heapbitmap1; <<<<<<<<<< free the good one
    mov eax,Heapbitmap1
    .if eax != Heapbitmap2
    invoke HeapFree,hHeap,0,Heapbitmap2 ; <<<<<<<<<< free the good one
    .endif
    invoke HeapFree,hHeap,0,hFShells
    mov idThread1,-1
    invoke ExitThread,2003
    hlt                        ; ...! i8085 memories

There is also problems with preservation

windbg see Nothing in the corrected source (Windows 10)

Fa is a musical note to play with CL

Magnum

Quote from: ToutEnMasm on March 01, 2016, 05:27:19 AM

There is a problem with allocated memory,you add Something to the original pointer and it is this one
who must be used for free

FireThread:
       
    invoke SetThreadPriority,idThread1,THREAD_PRIORITY_NORMAL;HIGHEST
    invoke GetDC,hwnd
    mov wnddc,eax
    invoke GetProcessHeap
    mov hHeap,eax
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,4194304
    mov Heapbitmap1,eax       ;<<<<<<<<<<<<<<<<<< keep this one for free
    add eax,4096               ; blur: -1'th line problem
    mov bitmap1,eax
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,4194304
    mov Heapbitmap2,eax      ;<<<<<<<<<<<<<<<<<< keep this one for free
    add eax,4096               ; blur: -1'th line problem
    mov bitmap2,eax
    mov eax,nd
    shl eax,4
    add eax,SPARC
    mov sb,eax                 ; size of FShell = nd*16+8
    imul nb                    ; array size   = nb*sb
    invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,eax
    mov hFShells,eax

    finit                      ; initialise floating point unit
    mov ax,07fh                ; low precision floats
    mov word ptr[esp-4],ax     ; fireworks... not space rockets
    fldcw word ptr[esp-4]

    ; PROBLEM HERE ?? ebp was never properly initialized
    ;sub ebp,12                 ; as 3 local variables
     sub esp,12 ; CORRECT statment

    mov eax,nb
    mov [ebp],eax
    mov eax,hFShells
    mov [ebp+4],eax
initshells:
   
lp1:
    mov eax,motionQ
    mov dword ptr[ebp+8],eax
lp2:
    mov eax,nb
    mov [ebp],eax
    mov eax,hFShells
    mov [ebp+4],eax
lp3:
    invoke FShell_render,[ebp+4],[ebp]
    mov eax,GMode
    mov ecx,offset FShell_explodeAG
    mov ebx,offset FShell_explodeOS
    test eax,eax
    cmovz ecx,ebx
    push [ebp+4] ;
    call ecx
    test eax,eax
    jns @F
    invoke random,maxy
    push eax
    mov eax,maxx
    add eax,eax
    invoke random,eax
    mov edx,maxx
    shr edx,1
    sub eax,edx
    push eax
    push [ebp+4]
    call FShell_recycle
@@:
    mov eax,sb
    add [ebp+4],eax
    dec dword ptr[ebp]
    jnz lp3
    dec dword ptr[ebp+8]
    jnz lp2
    mov eax,EMode
    test eax,eax
    jz r1
    mov eax,CMode              ; switch pre/post blur according to -
    test eax,eax               ; current chemical in fire
    jz @F
    invoke Blur_MMX2
@@:
    invoke Light_Flash3,lightx,lighty,flash,bitmap1,bitmap2
    invoke SetDIBitsToDevice,wnddc,0,0,maxx,maxy,\
           0,0,0,maxy,bitmap2,ADDR bminf,DIB_RGB_COLORS
    mov eax,CMode
    test eax,eax
    jnz r2
    invoke Blur_MMX2
    jmp r2
r1:
    invoke SetDIBitsToDevice,wnddc,0,0,maxx,maxy,\
           0,0,0,maxy,bitmap1,ADDR bminf,DIB_RGB_COLORS
    mov eax,maxx
    imul maxy
    lea eax,[eax+eax*2]
    invoke RtlZeroMemory,bitmap1,eax
r2:
    inc fcount                 ; count the frames
    fild flash
    fmul flfactor
    fistp flash
    invoke Sleep,5             ; control, if frames rate goes too high
    mov eax,stop
    test eax,eax
    jz lp1
    invoke ReleaseDC,hwnd,wnddc
    invoke HeapFree,hHeap,0,Heapbitmap1; <<<<<<<<<< free the good one
    mov eax,Heapbitmap1
    .if eax != Heapbitmap2
    invoke HeapFree,hHeap,0,Heapbitmap2 ; <<<<<<<<<< free the good one
    .endif
    invoke HeapFree,hHeap,0,hFShells
    mov idThread1,-1
    invoke ExitThread,2003
    hlt                        ; ...! i8085 memories

There is also problems with preservation

windbg see Nothing in the corrected source (Windows 10)

Look at 1st line of code to see the change.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

TouEnMasm

?????? Look at 1st line of code to see the change ??????
don't understang

The modifies must be made to avoid a crash when closing the prog (wrong pointer)
Fa is a musical note to play with CL

Magnum

I made all your recommended changes.

New source attached.

You said it worked in Win 10.

I guess you found some more errors.



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

I lost my copy of the executable.

Would someone mind compiling it for me.

Thanks,
              Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

HSE

Equations in Assembly: SmplMath

Magnum

Thanks HSE. I am running Ubuntu-Mate from having migrated from Win XP.

When I run fire.exe, it opens in a small window and it runs ok.

When I increase the window size, it crashes.

It uses about 25% of my cpu when running.

I wonder if changing thread priority would help?

FireThread:
       
    invoke SetThreadPriority,idThread1,THREAD_PRIORITY_NORMAL;HIGHEST
    invoke GetDC,hwnd


Unhandled exception: page fault on read access to 0x00e26ef8 in 32-bit code (0x004010d2).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:006b GS:0063
EIP:004010d2 ESP:0061fea4 EBP:0061feb8 EFLAGS:00010206(  R- --  I   - -P- )
EAX:003ffc30 EBX:00000000 ECX:00000000 EDX:00400ed8
ESI:00a26020 EDI:00625020
Stack dump:
0x0061fea4:  000000ff 0000036e 00000000 00000370
0x0061feb4:  00000638 0061feec 004015d3 00000428
0x0061fec4:  0000027f 0000000a 00a26020 00625020
0x0061fed4:  00110000 00000008 0000007f 7bc7da10
0x0061fee4:  00010001 00010001 00000000 0015d570
0x0061fef4:  00000000 00000000 7bcdbcb4 7bcdbcb4
Backtrace:
=>0 0x004010d2 in fire (+0x10d2) (0x0061feb8)
  1 0x004015d3 in fire (+0x15d2) (0x0061feec)
0x004010d2: movq 0x0(%edx,%esi,1),%mm1
Modules:
Module Address Debug info Name (9 modules)
PE   400000-  404000 Export          fire
PE 7b410000-7b5b6000 Deferred        kernel32
PE 7bc10000-7bc14000 Deferred        ntdll
PE 7f460000-7f464000 Deferred        winex11
PE 7f4f0000-7f4f4000 Deferred        imm32
PE 7f8e0000-7f9a6000 Deferred        user32
PE 7fac0000-7fac4000 Deferred        advapi32
PE 7fb40000-7fb47000 Deferred        gdi32
PE 7ffd0000-7ffd4000 Deferred        version
Threads:
process  tid      prio (all id:s are in hex)
0000000e services.exe
00000030    0
0000002d    0
00000028    0
0000001f    0
00000015    0
00000010    0
0000000f    0
00000011 mscorsvw.exe
0000001a    0
00000019    0
00000018    0
00000012    0
0000001b winedevice.exe
00000024    0
00000021    0
00000020    0
0000001c    0
0000001d winedbg.exe
0000001e    0
00000025 plugplay.exe
0000002a    0
00000029    0
00000026    0
0000002b winedevice.exe
00000035    0
0000002f    0
0000002e    0
0000002c    0
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

HSE

#26
Was a console building. New build.
Equations in Assembly: SmplMath

Magnum

Unhandled exception: page fault on write access to 0x00e6538e in 32-bit code (0x00401349).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:006b GS:0063
EIP:00401349 ESP:0061feb0 EBP:0061fec4 EFLAGS:00010202(  R- --  I   - - - )
EAX:0043f36e EBX:00000592 ECX:000018f0 EDX:00aad580
ESI:00a26020 EDI:00155830
Stack dump:
0x0061feb0:  00aad580 0000077c 000003c2 00000097
0x0061fec0:  0000016e 0061feec 0040153a 00155820
0x0061fed0:  00000005 00110000 00000008 0000007f
0x0061fee0:  7bc7da10 00010001 00010001 00000005
0x0061fef0:  00155820 00000010 00000000 7bcdbcb4
0x0061ff00:  7bcdbcb4 00000000 00000000 0040146c
Backtrace:
=>0 0x00401349 in fire (+0x1349) (0x0061fec4)
  1 0x0040153a in fire (+0x1539) (0x0061feec)
0x00401349: movw %dx,0x0(%eax,%esi,1)
Modules:
Module Address Debug info Name (9 modules)
PE   400000-  404000 Export          fire
PE 7b410000-7b5b6000 Deferred        kernel32
PE 7bc10000-7bc14000 Deferred        ntdll
PE 7f460000-7f464000 Deferred        winex11
PE 7f4f0000-7f4f4000 Deferred        imm32
PE 7f8e0000-7f9a6000 Deferred        user32
PE 7fac0000-7fac4000 Deferred        advapi32
PE 7fb40000-7fb47000 Deferred        gdi32
PE 7ffd0000-7ffd4000 Deferred        version
Threads:
process  tid      prio (all id:s are in hex)
0000000e services.exe
00000030    0
0000002d    0
00000028    0
0000001f    0
00000015    0
00000010    0
0000000f    0
00000011 mscorsvw.exe
0000001a    0
00000019    0
00000018    0
00000012    0
0000001b winedevice.exe
00000024    0
00000021    0
00000020    0
0000001c    0
0000001d winedbg.exe
0000001e    0
00000025 plugplay.exe
0000002a    0
00000029    0
00000026    0
0000002b winedevice.exe
00000035    0
0000002f    0
0000002e    0
0000002c    0
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

HSE

ABI corrections  in previous post.
Equations in Assembly: SmplMath

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org