PDA

View Full Version : "CALL ABSOLUTE" in QBASIC



linuxlove
May 31st, 2010, 08:25 AM
http://www.youtube.com/watch?v=H3sl50-H6tI

The only line in the entire program is "CALL absolute". It's also done in QBASIC, not QuickBASIC.
I'm wondering what causes this to happen.
According to someone else, doing this in QEMU causes it to lock up.

Chuck(G)
May 31st, 2010, 08:40 AM
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.

krebizfan
May 31st, 2010, 09:03 AM
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.

Chuck(G)
May 31st, 2010, 09:20 AM
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.

Mike Chambers
July 2nd, 2010, 10:20 PM
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.

Mike Chambers
July 2nd, 2010, 10:30 PM
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.

Mike Chambers
July 2nd, 2010, 11:12 PM
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?

Chuck(G)
July 3rd, 2010, 07:51 AM
ah, so i was wrong when i said it just goes to address 0 in the currently defined segment if not given an argument?

That's the way I understand it, from looking at code. Maybe I'm missing something.

Mike Chambers
July 31st, 2010, 09:24 AM
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.

Chuck(G)
July 31st, 2010, 09:44 AM
Another approach was to load some code in with a TSR or other mechanism and call it once the QBASIC program was loaded.