flat assembler
Message board for the users of flat assembler.

Index > Windows > ret causing an access violation

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
The access violation errors are getting old, but this one is interesting so i thought i'd post it.

Code:
format PE CONSOLE 4.0
include 'K:\asm\INCLUDE\win32ax.inc'
entry main2

drawbarstring db '*', 0
newline db 10, 0

proc drawbar
drawbarloop:
push ecx
invoke prints, drawbarstring
pop ecx
loop drawbarloop
invoke prints, newline
ret ;EAX should stay the same...
endp

proc drawbox, num, num2
pusha
mov ecx, ebx
drawboxloop:
push ecx
mov ecx, eax
invoke printint, ecx
stdcall drawbar, ecx   ;stdcall for locals, invoke for DLLs
pop ecx
loop drawboxloop
popa
ret ;EAX should stay the same...
endp

section '.code' code readable executable writeable
pausestring db "pause", 0
main2:
mov eax, 1
mov ebx, 1
main:
inc eax
inc ebx
pusha
stdcall drawbox ;Make sure values are always above 0
;invoke cmd, "CLS"
popa

cmp eax, 24
je eaxcheck
retaftereaxinc:

cmp ebx, 24
je ebxcheck
retafterebxinc:

jmp main

eaxcheck:
mov eax, 1
jmp retaftereaxinc

ebxcheck:
mov ebx, 1
jmp retafterebxinc

invoke return,0   ;Never called, but used to keep it working with windows

section '.reqdata' import readable writeable

library kernel, 'kernel32.dll',\
        commoncode, 'printstuff.dll'

import kernel,\
       return, 'ExitProcess'

import commoncode,\
       prints, 'printstring',\
       printint, 'printint',\
       cmd, 'cmd'           


I kept alot of debugging things in there and it's not really cpu efficient, but i thought i'd get the basic skeleton of it down before worrying much about efficiency... Well, if you comment out the ret in drawbar, it'll only print out 1 * perline wiht it's 1, and it won't crash. I'm gonna keep messing with it, but i saw the fact that my code (since i'm new to this still) is so horrible that it made a ret go malicious.
Post 12 Dec 2006, 22:46
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
You should forget about your code being 'cpu efficient' and move onto basics of asm/win32-coding, and hopefully you eventually come up with code formatting/style that is easier to read.

anyway, your definition of drawbar takes no params...
Post 12 Dec 2006, 23:43
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
i'm still trying to learn all the functions, and only experience can make me find a way to make it easier to read. lol

As for forgetting CPU efficiency, that's why i am learning this, so i can try to be at least half efficient, because my code in C++ is always slow and laggy, even with speed tactics like inline and macros. Well, actually that's half the reson, the other half is so that i can eventually get away from the OS.
Post 12 Dec 2006, 23:46
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
so, did my tip help you fix the bug or not?
Post 12 Dec 2006, 23:58
View user's profile Send private message MSN Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Actually yes. lol

I did some other things in attempt to fix it that damaged my draw box code so now it's not drawing boxes, but cones instead, but when i finish i'll post the code. lol I actually ment to speed write this project so i could compare the speed of this code with the same code, only in C++ to make a point to my programming teacher that Visual Studio is not a very good thing to rely on and maybe learning assembly isn't such a bad idea.
Post 13 Dec 2006, 00:02
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger 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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.