Accessing PowerBASIC variables by name

Most variables in a PowerBASIC module are visible to Inline Assembler code created with the ASM statement.  You can reference LOCAL, STATIC, and GLOBAL variables by name by simply using the name as an operand of the assembler opcode. That isn't possible with INSTANCE, THREADED, array, and pointer variables, as their access requires multiple operations best handled by higher level PowerBASIC code.  You can also reference procedure parameters by name, though you must differentiate between parameters passed by reference ( BYREF ), 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