GPFs again: I'm stumped!

DOS specific questions.
jamjamason
Posts: 20
Joined: Jul 17, 2012 18:51

GPFs again: I'm stumped!

Postby jamjamason » Sep 27, 2012 18:13

Can any kind soul enlighten me as to why the following do-nothing code causes a GPF? Thanks in advance.

Code: Select all

#LANG "fblite"
DIM SHARED DMADescriptor AS USHORT
DIM SHARED DMALinearAddress AS UINTEGER
DIM SHARED ErrorCode AS USHORT

PRINT "Starting..."

ASM
    PUSHAD

    MOV EBX, DWord Ptr [ErrorCode]
    MOV Word Ptr [EBX], AX  'this line causes a GPF

    POPAD

END ASM

PRINT "Error Code:" + STR$(ErrorCode) + ", DMALinearAddress=" + HEX$(DMALinearAddress)

END
dkl
Site Admin
Posts: 3200
Joined: Jul 28, 2005 14:45
Location: Germany

Re: GPFs again: I'm stumped!

Postby dkl » Sep 27, 2012 19:27

The first MOV loads the value of ErrorCode into EBX, the second MOV tries to dereference that value as if it was an address, which doesn't work since ErrorCode is zero (and not a pointer to something).

I assume you wanted to store a value into ErrorCode, so then you probably need to load the address of ErrorCode into EBX (instead of its value):

Code: Select all

   LEA EBX, DWord Ptr [ErrorCode]


Also, ErrorCode is a short (2 bytes), but you're using Dword Ptr (4 bytes), so consider making ErrorCode a Uinteger/Ulong, or using something like:

Code: Select all

   LEA BX, Word Ptr [ErrorCode]
frisian
Posts: 236
Joined: Oct 08, 2009 17:25

Re: GPFs again: I'm stumped!

Postby frisian » Sep 27, 2012 20:07

dkl wrote:Also, ErrorCode is a short (2 bytes), but you're using Dword Ptr (4 bytes), so consider making ErrorCode a Uinteger/Ulong, or using something like:

Code: Select all

     LEA BX, Word Ptr [ErrorCode]


That does not work, address is 32 bit, BX is 16 bit.

simple fast and easy solution.
replace
MOV EBX, DWord Ptr [ErrorCode]
MOV Word Ptr [EBX], AX 'this line causes a GPF

with
MOV Word Ptr [ErrorCode], AX
dkl
Site Admin
Posts: 3200
Joined: Jul 28, 2005 14:45
Location: Germany

Re: GPFs again: I'm stumped!

Postby dkl » Sep 27, 2012 20:19

oh yes, I think I meant:

Code: Select all

LEA EBX, Word Ptr [ErrorCode]
jamjamason
Posts: 20
Joined: Jul 17, 2012 18:51

Re: GPFs again: I'm stumped!

Postby jamjamason » Oct 02, 2012 17:12

Thanks to dkl and frisian for those insights. That's very helpful!
jamjamason
Posts: 20
Joined: Jul 17, 2012 18:51

Re: GPFs again: I'm stumped!

Postby jamjamason » Oct 03, 2012 16:02

I think it's worth noting here that the methods given by dkl and frisian work in the MAIN section of code, but when referencing variables that were passed on the stack inside a subroutine, the correct form to use is:

MOV EBX, DWord Ptr [ErrorCode]
MOV Word Ptr [EBX], AX
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: GPFs again: I'm stumped!

Postby MichaelW » Oct 03, 2012 17:53

jamjamason wrote:I think it's worth noting here that the methods given by dkl and frisian work in the MAIN section of code, but when referencing variables that were passed on the stack inside a subroutine, the correct form to use is:

MOV EBX, DWord Ptr [ErrorCode]
MOV Word Ptr [EBX], AX

That would be the correct form only if the variables were passed by reference (IOW by address), the default for the qb and fblite dialects. If the variable were passed by value, then you would again be trying to use a variable value as an address.

Return to “DOS”

Who is online

Users browsing this forum: No registered users and 1 guest