Long int

This question is half basic, half ASM, but I think the problem may be with the BASIC half of it.

I wrote an ASM routine that I've used for a while which loads/displays sprites. (it's compiled through an assembler and made into a lib, by the way - not called through ABSOLUTE). When loading from a file, I pass the filesize through an int%. However, this only allows for files up to 32767 bytes long. So, I changed it to a Long it& for a range of up to ~2billion.
When I used only an int, I used indirect addressing - [] - to get it from the stack. I didn't change much for the long int, which takes up 4 bytes instead of 2, except that I adjusted all my other indirect addressing MOVs as well.
Also, I tried to mov the long int into ECX, where it was CX before. I figure the upper 16 bits should be empty, and that the lower 16 (btw, i only want a filesize of up to 65535...) should contain the number I passed.

So, my question is: Do long ints working differently than I anticipate - do they pass from QB to ASM differently than an int. Or, am I just getting the value from the stack incorrectly. That could be the case as well, as I know little about 32bit registers.

Comments

  • 1. First of all I'm not sure real mode allows 32 bits registers

    2. QBasic by default pass the address of the variable not its value, to pass a value use Declare MyASMRoutine (byval AValue%).

    3. You must know that all values (larger than 1 bytes, in this case integer & long) are placed from left to right so:
    [code]
    a% = &hAABB
    ' in the memory it is stored as BB AA
    b& = &hAABBCCDDEE&
    ' in the memory is stored as EE DD CC BB AA
    [/code]
  • I forgot to mention that I [italic]was[/italic] using BYVAL, which could have made a significant difference..
    Anyhow, it turns out the problem was completely different, although even though the problem is fixed, it doesn't clarify a whole lot.
    I looked at some file loading code from "dash", and noticed it uses ECX and other such registers, however, the code gives no indication that it's not in real mode. It just has ".386" at the beginning, but I code did too...

    Actually, the problem was this: I was trying to load from file to EMS. For whatever reason, it throws some funky effects when I load directly to EMS... I didn't want to bother with figuring out why or a workaround when I first wrote the routine, so I just loaded into a variable in conventional memory first, then copied into EMS; this made the code longer, but hey, it worked!
    However, this was also the problem as well as a fix. I forgot to make the "buffer" so to speak, bigger. It was only 16KB, and I was loading an approx. 64KB file... needless to say, that didn't work, so I had to complicate the code even more, by loading the file in 16KB chunks, but hey, it works!



    : 1. First of all I'm not sure real mode allows 32 bits registers
    :
    : 2. QBasic by default pass the address of the variable not its value, to pass a value use Declare MyASMRoutine (byval AValue%).
    :
    : 3. You must know that all values (larger than 1 bytes, in this case integer & long) are placed from left to right so:
    : [code]
    : a% = &hAABB
    : ' in the memory it is stored as BB AA
    : b& = &hAABBCCDDEE&
    : ' in the memory is stored as EE DD CC BB AA
    : [/code]
    :

  • Just to let you know, it probably isn't a very good idea to mix 32bit ASM with 16bit QB.

    --------------------------------------------
    I will bend your mind with my spoon...

  • why not?

    : Just to let you know, it probably isn't a very good idea to mix 32bit ASM with 16bit QB.
    :
    : --------------------------------------------
    : I will bend your mind with my spoon...
    :
    :

  • Well you can, but I don't recommend it because it can make things very confusing and hard to read. Oh and by mixing 16-bit and 32-bit, I mean you shouldn't just pop a 32-bit subroutine into an entirely 16-bit program. I mix the two al the time but I don't put one 32-bit routine in the middle of a program coded for 16-bit DOS.

    --------------------------------------------
    I will bend your mind with my spoon...

  • When you jump to 32bit pmode, you have to setup a LOT of things

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories