flat assembler
Message board for the users of flat assembler.

Index > Windows > Translation of MASM32 routine causing crash in FASM

Author
Thread Post new topic Reply to topic
StakFallT



Joined: 19 Jan 2006
Posts: 50
StakFallT 07 Feb 2006, 05:55
Basically as the subject implies, I've been working on an assembly demo.. Long story short, one of the routines in the project was a routine written in MASM32. I converted it with hardly any modifications to the routine; I mean their were modifications but next to none.. Anyhow I narrowed this crash in my project to this routine

Code:
proc CreateLCDColors
           push ebx
           ; This function simply copies the darker version of the colors 0-6 in
           ; the palette to colors 7-13. SHADOWDARKNESS determines the darkness
           ; of the shadow.

           xor                         ecx,            ecx
           mov                         edx,            LCDBaseColors
           ;push                        LCDBaseColors
           ;pop                         edx
           mov                         ebx,            edx                                ;ebx points to first background color
           add                         edx,            [COLORBASE_SHADOW*4]               ;edx points to first shadow color
           jmp                         Create_LCD_Colors_Check_ecx

           ; loop for every color index
           Create_LCD_Colors_Check_ecx:
                                       cmp             ecx,       [BASECOLORCOUNT*4]
                                       jl              Create_LCD_Colors_Loop
                                       jge             EndCreateLCDColorsProc

           Create_LCD_Colors_Loop:
                                       ; read color:
                                       mov             al,        [ebx+ecx]

                                       ; darken color:
                                       cmp             al,        [SHADOWDARKNESS]
                                       jl              Create_LCD_xor_al
                                       jge             Create_LCD_sub_al

           Create_LCD_xor_al:
                                       xor             al,        al
                                       jmp             ContinueCreateLCDColors
           Create_LCD_sub_al:
                                       sub             al,        [SHADOWDARKNESS]
                                       jmp             ContinueCreateLCDColors

           ContinueCreateLCDColors:
                                       ; put darkened color:
                                       mov             [edx+ecx], al
                                       inc             ecx
                                       jmp             Create_LCD_Colors_Check_ecx
           EndCreateLCDColorsProc:
                                       ret
endp
    


The really tricky thing about debugging this is it does loop through it ok at least once.. Here's how I determined this routine to be the culprit.. Issued MessageBox call as the previous instruction before calling the routine, and one right after it.. Only 1 mb shown. ok so somewhere inside the routine.. remmed out the first mb (just before calling the routine, since now at this point I know it's in the routine somewhere).. Isued a MB as the first instructions in the Xor/Sub label blocks.. 1 mb shown.. Remmed them (the MBs) out.. Issued one just before the ret call, 1 shown mb shown.. So It's really whacky.. It seems to loop through but get hung up on the ret instruction.. Thinking about it I thought it might have been because I'm pushing ebx onto the stack at the begining and for some reason the ret isn't popping the items off the stack (I read an article somewhere that you can avoid using ret if you pop the proper amount of registers or bytes or something back off at the end).. But anyhow, that didn't fix it either.. so I'm kinda not sure how to debug this further.. Any help would really be greatly appreciated! Smile

-- StakFallT

Oh I also am putting the zip file with the code attached to this thread so that if you guys (or girls Razz ) need some of the surrounding code, you won't get hung up trying to figure out where the real culprit is.. Again, thanks MUCH Smile


Description:
Download
Filename: Demo1.zip
Filesize: 201.07 KB
Downloaded: 250 Time(s)

Post 07 Feb 2006, 05:55
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 07 Feb 2006, 10:33
Code:
proc CreateLCDColors 
           push ebx
    

you pushed the ebx, but didn't pop it out.
try pop it out first then only do ret.
Post 07 Feb 2006, 10:33
View user's profile Send private message Visit poster's website Reply with quote
StakFallT



Joined: 19 Jan 2006
Posts: 50
StakFallT 07 Feb 2006, 13:00
I acctually tried that already on the outside chance that ret wasn't preserving the stack and it didn't work Sad
Post 07 Feb 2006, 13:00
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 07 Feb 2006, 13:22
i just downloaded your code and ...
wow...

there are quite a lot "mistake".
i try check the source and do some conversion for u.
Post 07 Feb 2006, 13:22
View user's profile Send private message Visit poster's website Reply with quote
StakFallT



Joined: 19 Jan 2006
Posts: 50
StakFallT 07 Feb 2006, 13:37
nm I found it... I went bracket crazy as usual... Don't thikn I'll ever understand why they shouldn't be used when I think they should but, but it's at least running now so not gonna look a gift-horse in the mouth lol

-- StakFallT
Post 07 Feb 2006, 13:37
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 07 Feb 2006, 13:46
i think my tutorial could help you...
(you switch chapters at top of the page)
Post 07 Feb 2006, 13:46
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.