It has been pointed out that the following has a bad exit, and eats up the cpu for someone. It seems to exit and work fine for me. The resource is loaded with the following:
.code
start:
invoke GetModuleHandle, eax
mov hInstance,eax
push esi
INVOKE FindResource, hInstance, 200, RT_RCDATA
push eax
INVOKE SizeofResource, hInstance, eax
mov nMusicSize, eax
pop eax
INVOKE LoadResource, hInstance, eax
INVOKE LockResource, eax
mov esi, eax
mov eax, nMusicSize
add eax, SIZEOF nMusicSize
INVOKE GlobalAlloc, GPTR, eax
mov pMusic, eax
mov ecx, nMusicSize
mov dword ptr [eax], ecx
add eax, SIZEOF nMusicSize
mov edi, eax
rep movsb
pop esi
invoke DialogBoxParam, hInstance, 100, 0, ADDR DlgProc, eax
invoke GlobalFree, pMusic
invoke ExitProcess, eax
Anyone see a problem?
code tags added
- sluggy
Could you include the entire project? Then others can try it and give more accurate results.
Someone may have been pulling your leg, ExitProcess() is system specification to exit a prgram.
TRY invoke ExitProicess,0
or erase " Push esi" and "POP esi" ::)
Here is the source. Please give it the once over and give me some pointers. I just relearned asm, and Im sure there are lots of mistakes and places that could use improvement.
https://www.sharemation.com/upucker/source.zip
The problem that was pointed out to me was.......
"CPU goes to 99%~ after smacking the X. There are no error messages (I know that it was kind of implied, but I simply meant it does not close properly). Taskmanager is showing the massive CPU, and my computer not responding well is showing the massive CPU."
It runs fine for me in winXP. So I was thinking that it may be an os issue or something, but since I just learned asm, Im not sure. I was hoping someone might have run into something like this, and point me in the right direction. I made a few changes, but Im not sure if they worked.
I added MOVEABLE PURE LOADONCALL DISCARDABLE to a couple of the resources in the rsrc.rc file.
I added DISCARDABLE to the dialog in the rsrc.rc file.
Someone pointed out that the 2 settimer calls might be the problem, but Im not sure if I need to kill them or restart them etc.
Okay Upucker. Couple issues here. First, did you get permission to use that musical score? Because if not, the creator, "Quazar of Sanxion", can rightfully sue for copyright infringement (and win.) If in doubt, it's always best to "roll your own." See this site for a good Win32 tracking program: http://www.madtracker.org/
Second, I'm not a fan of trainers. Yeah, okay, that's personal preference, but the site rules may not allow posting about them. Read the fine print.
Third, when I exit your app in XP SP2, I get "picture.exe - Application Error. The instruction at "0x7c910f29" referenced memory at "0x00000000". The memory could not be "read". This is better known as a page fault. So I ran picture.exe through memproof and got this:
(http://heliosstudios.net/temp/picture_err.png)
Thanks for the reply. I dont use radasm, so while I can look through your post, can you spell out what it says.
UPucker, I could not reproduce the problem here, but two things met the eye:
1) Your code does "invoke GlobalFree, pMusic" twice (source lines 167, and 361). Freeing the memory once is enough.
2) The DlgProc's WM_TIMER handler uses EDI without saving/restoring the register's original content.
Changing these should render the program more stable.
OK fixed the multiple exits, but the wm_timer using edi escapes me. Please could you explain.
Thanks for the tips. Its nice to be able to come here to get help from such an experienced group.
Quote from: UPucker on August 20, 2005, 04:36:29 AM
OK fixed the multiple exits, but the wm_timer using edi escapes me. Please could you explain.
You can freely use registers eax, ecx and edx in your program, but any other must preserved, which means you must restore it's original value:
push edi ; save edi to stack
... ; do whatever you want with edi
pop edi ; restore edi from stack
(ret)
Check MASM32\HELP\ASMINTRO.HLP chapter 'Register Preservation' for additional information.
that part I understand, but where am i abusing it? where would I need to save and restore it?
Quote from: UPucker on August 20, 2005, 05:54:40 AM
that part I understand, but where am i abusing it?
"Abusing" is such a harsh word ... you are using it here:
Wm_2:
cmp [uMsg],WM_TIMER
jnz Wm_3
mov eax, wParam
.if eax==1
;All our drawing is done here. ************************************
;| This small peice of
mov edi, [canvas_buffer] ;| code wipes away the
mov ecx,ScreenWidth * ScreenHeight ;| previous frame we
mov eax, 000000ffh ;| drew to the screen
rep stosd ;| without it we get a mess.
;|
;--- drawing functions... ;|
;|
mov edi, [canvas_buffer] ;| IMPORTANT!
Quote from: UPucker on August 20, 2005, 05:54:40 AM
where would I need to save and restore it?
There are several possibilities. In my view, the best one is:
Do a "PUSH EDI" at the start of the DlgProc (before any other instruction).
Do a "POP EDI" at the DlgProc's end (right before XOR EAX, EAX / RET).
In other words, what I propose to do is this:
DlgProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
push edi
Wm_1:
; your code goes here
Wm_6:
pop edi
xor eax, eax
ret
DlgProc endp
Okay I updated some resources, and made a couple of changes. I also commented the source.
If someone would please take a look, and let me know if anything is lacking or needs improvement, I would be grateful.
Please remember that I am just learning asm. This is my second project.
Source Code:
https://www.sharemation.com/upucker/source.zip
Mark Jones : Thanks for pointing me to memproof. After fixing a couple of the problems people have pointed out, I ran it through memproof, and it looks ok to me. I was wondering if you would check the new version, and explain what memproof is pointing out? Pretty please with sugar on top!
Would someone please look through the code and give me some pointers? I am a noob at asm, and would love a little mentoring.