• Please review our updated Terms and Rules here

"CALL ABSOLUTE" in QBASIC

Since CALL ABSOLUTE takes a variable-length argument list, the last argument in the list is the offset of the code to be executed (the segment is given by a DEF SEG statement).

So a CALL ABSOLUTE with no arguments simply takes whatever is on the stack (the offset of the returns address) and the default segment value, uses it as an argument pointer and jumps to it. Havoc ensues. QBASIC should perhaps have included a check for at least one argument, but I suspect that CALL ABSOLUTE was tossed into the language as an afterthought.

To the ignorant, it's just like being given a gift of gasoline and matches.
 
That is a bug in QBasic; it shouldn't do the jump without a value setup to jump to. The code jumps to some random* location and does whatever will happen there. That could result in crashes, your prettier lockup, on up to very bad actions like knocking out the MBR on the hard disk. Don't do it. The library that handles this in QuickBasic does check to make sure there is some value, though jumping to the wrong place can still happen.

* Not really random but the value can vary between systems, OS setup, code layout.
 
No, issuing a CALL ABSOLUTE without knowing what it does is just plain stupidity both on the part of the user and of Microsoft for allowing a loose cannon like that into the language.

There are safe(r) ways to do this, such as insisting that the code being invoked obey a rigid set of rules on format (i.e. use checksummed headers with a sanity check).

But then, QBASIC was a pet of BillG, so we shouldn't have expected too much.

Forgive the rant, but some things really rankle me.
 
No, issuing a CALL ABSOLUTE without knowing what it does is just plain stupidity both on the part of the user and of Microsoft for allowing a loose cannon like that into the language.

There are safe(r) ways to do this, such as insisting that the code being invoked obey a rigid set of rules on format (i.e. use checksummed headers with a sanity check).

But then, QBASIC was a pet of BillG, so we shouldn't have expected too much.

Forgive the rant, but some things really rankle me.

not really, CALL ABSOLUTE can be very nice. however, it is stupid to use if you don't know what it's going to do. it can be used as a sort of ghetto "inline asm" in a way if you create a string with some valid x86 machine code. of course, if you're smart enough to do it properly - you probably could just use a language superior to QBASIC to begin with.
 
That is a bug in QBasic; it shouldn't do the jump without a value setup to jump to. The code jumps to some random* location and does whatever will happen there. That could result in crashes, your prettier lockup, on up to very bad actions like knocking out the MBR on the hard disk. Don't do it. The library that handles this in QuickBasic does check to make sure there is some value, though jumping to the wrong place can still happen.

* Not really random but the value can vary between systems, OS setup, code layout.

it's not some unknown random number, but if it's not specified it will go to address 0 in the currently defined segment (from a DEF SEG =), and it's not a bug either. that's where it should go if you don't tell it. it assumes you know what you're doing and have DEF SEG'd to the segment you want it to begin execution at. basically, if somebody doesn't understand CALL ABSOLUTE, they shouldn't use it.
 
Since CALL ABSOLUTE takes a variable-length argument list, the last argument in the list is the offset of the code to be executed (the segment is given by a DEF SEG statement).

So a CALL ABSOLUTE with no arguments simply takes whatever is on the stack (the offset of the returns address) and the default segment value, uses it as an argument pointer and jumps to it. Havoc ensues. QBASIC should perhaps have included a check for at least one argument, but I suspect that CALL ABSOLUTE was tossed into the language as an afterthought.

To the ignorant, it's just like being given a gift of gasoline and matches.

ah, so i was wrong when i said it just goes to address 0 in the currently defined segment if not given an argument?
 
you're probably right about it. CALL ABSOLUTE can be extremely useful if you feel like defining some string constant with valid x86 binary code that you can call, or even do some dynamic "compilation" in x86 binary if you know what you're doing. of course, if you know what you're doing that well you're probably not going to use QB in the first place.
 
Back
Top