Author Topic: Need help with my first masm program  (Read 1486 times)

coffeeprog

  • Guest
Need help with my first masm program
« on: July 29, 2021, 01:21:16 AM »
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

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Need help with my first masm program
« Reply #1 on: July 29, 2021, 02:10:44 AM »
Hello,
Welcome on the forum.With source code all is possible.

Code: [Select]
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

  • Guest
Re: Need help with my first masm program
« Reply #2 on: July 29, 2021, 02:39:31 AM »
Ok, thanks, that did not solve the problem, but I did not know not to use eax in a call

Greenhorn

  • Member
  • **
  • Posts: 175
Re: Need help with my first masm program
« Reply #3 on: July 29, 2021, 02:40:14 AM »
Hi Chad Botting,

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

Code: [Select]
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

TouEnMasm

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Need help with my first masm program
« Reply #4 on: July 29, 2021, 02:51:07 AM »

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

  • Guest
Re: Need help with my first masm program
« Reply #5 on: July 29, 2021, 02:56:12 AM »
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

  • Member
  • **
  • Posts: 175
Re: Need help with my first masm program
« Reply #6 on: July 29, 2021, 03:12:04 AM »
Attached your code but it is not testet !

Try this link https://idoc.pub/download/masm-611-programmers-guide-5143gd0jejnj

Greenhorn

  • Member
  • **
  • Posts: 175
Re: Need help with my first masm program
« Reply #7 on: July 29, 2021, 04:20:25 AM »
OK, had a closer look at it ...

Attached code should work fine, but it's not tested ...

Greenhorn

  • Member
  • **
  • Posts: 175
Re: Need help with my first masm program
« Reply #8 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.

Code: [Select]

.ElseIf uMsg == WM_DESTROY

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

invoke KillTimer, hWnd, ID_TIMER
Invoke PostQuitMessage, 0
Xor Eax, Eax

Greenhorn

  • Member
  • **
  • Posts: 175
Re: Need help with my first masm program
« Reply #9 on: July 29, 2021, 05:59:37 AM »
Sorry, forgot to adjust the protos ...

Code: [Select]
MinNum PROTO :DWord, :DWord
MaxNum PROTO :DWord, :DWord

coffeeprog

  • Guest
Re: Need help with my first masm program
« Reply #10 on: July 29, 2021, 09:45:03 AM »
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

  • Member
  • *****
  • Posts: 1805
    • EditMasm
Re: Need help with my first masm program
« Reply #11 on: July 30, 2021, 01:21:24 AM »

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

coffeeprog

  • Guest
Re: Need help with my first masm program
« Reply #12 on: August 04, 2021, 04:50:49 AM »
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

  • Member
  • *****
  • Posts: 11551
  • Assembler is fun ;-)
    • MasmBasic
Re: Need help with my first masm program
« Reply #13 on: August 04, 2021, 08:20:46 PM »
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

  • Member
  • *****
  • Posts: 2213
    • https://github.com/nidud/asmc
Re: Need help with my first masm program
« Reply #14 on: August 05, 2021, 12:46:12 AM »
Radical views from The Old New Thing - Raymond Chen - MSFT January 5, 2012:

Quote
Don't worry about freeing memory; it will all go away when the process address space is destroyed. Don't worry about closing handles; handles are closed automatically when the process handle table is destroyed.
...
The building is being demolished. Don't bother sweeping the floor and emptying the trash cans
...

Rather "selective" editing there.

Quote
When the Dll­Main function receives a reason code of DLL_PROCESS_DETACH, the increasingly-inaccurately-named lpReserved parameter to is used to indicate whether the process is exiting. And if the process is exiting, then you should just return without doing anything. No, really. Don’t worry about freeing memory; it will all go away when the process address space is destroyed. Don’t worry about closing handles; handles are closed automatically when the process handle table is destroyed. Don’t try to call into other DLLs, because those other DLLs may already have received their DLL_PROCESS_DETACH notifications, in which case they may behave erratically in the same way that a Delphi object behaves erratically if you try to use it after its destructor has run. The building is being demolished. Don’t bother sweeping the floor...