Announcement

Collapse
No announcement yet.

CPU Register EBX

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

  • CPU Register EBX

    The PB DLL Manual states that the value in the EBX register must be preserved, however the example code in the manual shows it being loaded with a value and not preserved as in:

    SUB KerPlunk
    ASM mov EAX, 5
    ! mov EBX, &HFF
    ! add EAX, EBX
    END SUB

    My questions are:

    Why is EBX special, while EAX is not? They are both general purpose registers. . .

    Is PB doing something special with EBX?

    When the above sub is exited is EBX restored to the value it had before the sub was called?

    A side note, default compiler setting of:
    #REGISTER DEFAULT
    can lead to some very interesting results when inline assembly code is used, but anyone sharp enough to do inline assembly would already know that. It might be a good idea to place a warning in the help file and/or manual.

    Tim

    [This message has been edited by Tim Wisseman (edited June 21, 2000).]

  • #2
    Tim,

    Its Windows convention to preserve EBX, ESI & EDI but you can freely use
    EAX ECX & EDX without needing to preserve them.

    From what I can tell coding inline asm in PB, it still handles the stack
    preservation automatically where u must do the preservations manually in
    MASM for example.

    You normally leave the base pointer (EBP) and the stack pointer (ESP)
    alone unless you are performing manual stack manipulation. FS & GS are
    not normally used in win32 but apparently the OS uses them from time to
    time.

    Regards,

    [email protected]

    ------------------
    hutch at movsd dot com
    The MASM Forum - SLL Modules and PB Libraries

    http://www.masm32.com/board/index.php?board=69.0

    Comment


    • #3
      The PB DLL Manual states that the value in the EBX register must be preserved, however the example code in the manual shows it being loaded with a value and not preserved as in: <snip>
      The example code is designed to show the general format of inline assembly code, rather than a specific task - the sub neither accepts or returns any values so it is of no "real" use. However, I'll ask for this to be improved so there is absolutely no confusion.
      A side note, default compiler setting of:
      #REGISTER DEFAULT
      can lead to some very interesting results when inline assembly code is used, but anyone sharp enough to do inline assembly would already know that. It might be a good idea to place a warning in the help file and/or manual.
      The help file does describe a number of "warnings", but the most pertinent to your note is already in the help file under the REGISTER statement:
      "Further, float register variables may never be referenced by name from inline assembler code, as the compiler can not always track the register locations with absolute certainty."
      And in more detail in the REGISTER VARIABLE section of Appendix C:
      "You must use care with inline assembler floating point opcodes in functions that enable register variables. Float register variables may occupy up to four of the coprocessor registers, so you must limit your use of the x87 registers to the remaining four. Further, float register variables may never be referenced by name from inline assembler code, as the compiler can not always track the register locations with absolute certainty."


      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Actually, the register preservation requirements for EBX/ESI/EDI only apply to assembler code which precedes BASIC statements within a sub/function. PowerBASIC assumes that it can use these 3 registers to store data from one statement to the next. If there are no more statements, it's of no consequence. PowerBASIC must preserve registers between sub/function calls, and does so automatically. Of course, ESP and EBP must always be preserved.

        One note... never change a segment register. Win32 in unforgiving.

        Bob Zale
        PowerBASIC Inc.


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

        Comment


        • #5
          I do not want to use ESI or EDI, just EAX EBX ECX and EDX.

          So when I have basic statements in the same sub as asm statements I will push and pop EBX, just to be safe.

          Very interesting. Thanks guys!

          Tim


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

          Comment


          • #6
            > Why is EBX special, while EAX is not? They are both general purpose registers. . .

            Tim,

            Back in the stone age of 16 bits, AX, BX, CX and DX were general purpose.
            But BX could be used as an index register as well, like SI and DI. In 32 bit EAX, EBX, ECX and EDX are functionally the same, so this convention of preserving EBX is more or less out of habit.

            Peter.


            ------------------
            [email protected]

            Comment

            Working...
            X