News:

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

Main Menu

Need help with my first masm program

Started by coffeeprog, July 29, 2021, 01:21:16 AM

Previous topic - Next topic

coffeeprog

Hello,

   I have been trying to recode the Bounce1 program written in C to masm assembler from the Petzold book Programming Windows, chapter 14.  I have ran into a few problems and am asking for help.  The video explains more  Thanks.

Chad Botting
coffeeprog

https://youtu.be/H6QoM--RD7s
https://forums.grc.com/threads/c-and-assembly-symbols-and-debugging-question-and-a-discussion.760/

TouEnMasm

Hello,
Welcome on the forum.With source code all is possible.


Sub Eax, Ebx                                 ;
mov edx,eax                                  ;<<<<<<<<<<<<<<<<<<<<< don't use eax in a call
Invoke BitBlt, hdc, Ecx, Edx, cxTotal, cyTotal, hdcMem,0, 0, SRCCOPY

The compiler need a very number of registers to solve the call,eax is the one you coulndn't use without random problems.That is perhaps it work,perhaps not.

Fa is a musical note to play with CL

coffeeprog

Ok, thanks, that did not solve the problem, but I did not know not to use eax in a call

Greenhorn

Hi Chad Botting,

you cannot do this (actually and technically you can but then you must know what you're doing):


Mov DWord Ptr [cyClient], Ecx
Mov Eax, DWord Ptr [cyClient]


By doing Mov DWord Ptr [cyClient], Ecx you will overwrite the variable xCenter with the high word of ecx.
And with Mov Eax, DWord Ptr [cyClient] you will load cyClient into ax and xCenter into the high word of eax.

In the Petzold source the size of the static variables are int = DWORD and not WORD.

Download and read the MASM Programmer's Guide and you'll understand what's wrong with your code.
http://masm32.com/board/index.php?topic=3445.0

Kind Regards
Greenhorn
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

TouEnMasm


Here is what you can do with a c source code using option /FAs,you get an asm file who can help you.
There is errors of size using the register dword ptr [XXX] .. who must be corrected.
Fa is a musical note to play with CL

coffeeprog

Ok, good information, the link the Programmer's Guide is dead, but you can just search for the filename of the pdf.  I actually bought a copy on ebay, so I have a physical copy too.

Greenhorn

Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Greenhorn

OK, had a closer look at it ...

Attached code should work fine, but it's not tested ...
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Greenhorn

You have to complete your WM_DESTROY. At the moment there is a GDI leak if do not free allocated resources.



.ElseIf uMsg == WM_DESTROY

; Clean up
.If (hBitmap)
Invoke DeleteObject, hBitmap
.EndIf

invoke KillTimer, hWnd, ID_TIMER
Invoke PostQuitMessage, 0
Xor Eax, Eax
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Greenhorn

Sorry, forgot to adjust the protos ...


MinNum PROTO :DWord, :DWord
MaxNum PROTO :DWord, :DWord
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

coffeeprog

Thank for your help, I think I am done for today.  I am including the newest code in a zip file and another video for additional help.  Super thanks.

Chad

https://www.youtube.com/watch?v=8Q9Cl3Eq2SU

TouEnMasm


This one work exactly as the original except he is green to be original.
Fa is a musical note to play with CL

coffeeprog

I made a quick video for the sake of completion.  This is the fully working Bounce1 in masm, little messy still, but works.

https://www.youtube.com/watch?v=RYZL7te3sdM


jj2007

Quote from: Greenhorn on July 29, 2021, 05:28:14 AM
You have to complete your WM_DESTROY. At the moment there is a GDI leak if do not free allocated resources.

Raymond Chen doesn't agree with you. To test it, write a little proggie that spawns another little proggie 10,000 times. If your system crashes, you are right. If not, Chen is right.


nidud

#14
deleted