asm crashes

New to FreeBASIC? Post your questions here.
dafhi
Posts: 1357
Joined: Jun 04, 2005 9:51

asm crashes

Postby dafhi » Jun 04, 2005 10:26

Code: Select all

FUNCTION AddFive(num AS INTEGER) AS INTEGER
ASM
    mov eax, [num]
    add eax, 5
    mov [AddFive], eax
END ASM
END FUNCTION

DIM i AS INTEGER = 4

PRINT "4 + 5 = "; AddFive(i)

sleep
I3I2UI/I0
Posts: 90
Joined: Jun 03, 2005 10:39
Location: Germany

Postby I3I2UI/I0 » Jun 04, 2005 10:33

sorry, (only freeBASIC 0.14b)

Code: Select all

FUNCTION AddFive(ByVal num AS INTEGER) AS INTEGER
ASM
    mov eax, [num]
    add eax, 5
    mov [FUNCTION], eax
END ASM
End FUNCTION

DIM i AS INTEGER = 4

PRINT "4 + 5 = "; AddFive(i)

Sleep
Last edited by I3I2UI/I0 on Jun 04, 2005 10:49, edited 2 times in total.
dafhi
Posts: 1357
Joined: Jun 04, 2005 9:51

Postby dafhi » Jun 04, 2005 10:37

ah ... okay, i think. i'm a vb-er and saw this example but [Function] instead of [AddFive] was used. Took me at least 15 minutes to figure that one out. Anyway, I'll have a look. Thanks.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jun 04, 2005 10:40

those both crash on my comp.

Code: Select all

FUNCTION AddFive(byval num AS INTEGER) AS Integer
Dim a As Integer
ASM
    mov eax, [num]
    add eax, 5
    mov [a], eax
END ASM
Function = a
END FUNCTION

DIM i AS INTEGER = 4

PRINT "4 + 5 = "; AddFive(i)

sleep


this works on mine, i dont know why this works and the others dont on my comp, (i dont know asm)
v1ctor
Site Admin
Posts: 3801
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Postby v1ctor » Jun 04, 2005 16:45

Yeah, if you use the function's name instead of FUNCTION (present in 0.14), then it will try to write to the address of the AddFive function, causing an exception in Windows or Linux, because the pages reserved for code sections are marked as read-only.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest