Accessing PowerBASIC variables by name

All variables in a PowerBASIC module are visible to Inline Assembler code created with the ASM statement.  You can reference LOCAL, STATIC, GLOBAL, and THREADED variables by name.  You can also reference procedure parameters by name, though you must differentiate between parameters passed by reference (BYREF) or by copy (BYCOPY), and those passed by value (BYVAL).  Any variable referenced in an assembly-language statement must be defined prior to use.

SUB DoStuff (BYVAL c&)

  LOCAL a%, b$

  a% = 7              ' Local variable a%

  ! PUSH EBX

  ! MOV  AX, a%       ; Move value to AX

  ! ADD  a%, AX       ; Add value back to a%

  b$ = "LINDA"        ' Local variable b$

  ! MOV  EBX, b$      ' Address of b$

  ! MOV  [EBX], "l"   ' Put lowercase "l" in first position

  ! MOV  EAX, c&      ' Put c& into EAX

  ! INC  EAX          ' Increment its value

  ! MOV  c&, EAX      ' Put it back

  ! POP  EBX

END SUB

 

See Also

The Inline Assembler