Announcement

Collapse
No announcement yet.

ASM questions for PB/DOS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASM questions for PB/DOS

    1) How do you access a static variable inside a module with ASM
    code?
    2) How to reference a code address inside the module? For
    instance, I need to get the code segment ffset into DS X.

    I need to write a hook for Interrupt 15h, function 4Fh. I
    already have the code working fine using Debug, so the machine
    language part is not a problem. I just need to learn how to
    incorporate my machine language into ASM statements in
    PowerBASIC.

    Question #1 is the most urgent. I see plenty of examples for
    accessing parameters which are passed, but I don't see how to
    access a static variable declared in the module.

    Here is the approach I was planning for #2, it seems simple
    enough, but please let me know if I'm going astray:

    ! push cs ; Paranoid transfer to make sure ds points to code
    ! pop ds
    ! lea dx,[code_addr]

    .... more code in the middle

    ! code_addr:
    ! ; routine goes here

    I've looked in the first few screens of this board and haven't
    seen topics like this discussed, and I also have not seen any
    documentation on the ASM statement beyond what is in the manual
    (which I did read, I promise!)

    Thanks for any help!
    Allan


    ------------------

  • #2
    I should have disabled smilies, I see. The line with the
    smilies should read:

    "I need to get the code segmentffset into DSX."


    ------------------

    Comment


    • #3
      Allan,
      I think the code below demonstrates what you want, except it gets the code address into the CSX pair and not the DSX pair.

      Since you're accessing code, the CS register is already pointing at the code segment. DS is pointing at the data segment, where your variables are. If you start mixing them you'll probably get confused. It CAN be done, but it's just as easy not to mix the use of DS and CS.

      If you change DS then all references you make to any variables in the PB code will be wrong as they are all referenced by DS.

      Paul.

      Code:
      REM point 1
      REM access a variable
       
      a%=&H1234
       
      !mov ax,a%   ;get the variable contents into AX
       
       
       
      REM point 2
      REM get a label (code address)
       
      REM first in BASIC
      print hex$(codeseg(label))
      print hex$(codeptr(label))
       
      REM now in ASM
      !lea dx,label      ;get address into CS:DX
       
      end
       
       
      label:

      Comment


      • #4
        Thanks, Paul. So you're saying that a static variable in a
        module is directly addressable using the current DS. That makes
        sense.

        Unfortunately, I have no choice but to use DSX to address the
        location in my code, because that's what DOS function 25h insists
        on. So I'll have to save the original DS and restore it as soon
        as I get control back from DOS.

        Thanks for your reply!

        Allan

        Allan,
        I think the code below demonstrates what you want, except it gets the code address into the CSX pair and not the DSX pair.
        Since you're accessing code, the CS register is already pointing at the code segment. DS is pointing at the data segment, where your variables are. If you start mixing them you'll probably get confused. It CAN be done, but it's just as easy not to mix the use of DS and CS.

        If you change DS then all references you make to any variables in the PB code will be wrong as they are all referenced by DS.

        Paul.



        ------------------

        Comment

        Working...
        X