Inline Assembly Code Question

Windows specific forum
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

Inline Assembly Code Question

Post by Logman »

I have successfully run Direct to Compiler code using the "!" symbol, but am having trouble converting it to Inline ASM code.

Here's some sample code; I've stripped out everything to make it simple. Specifically, I'm having trouble with the LABEL l_L1: and with the LOOP statement that loops back to the LABEL l_L1. Everything else works, it just seems that I'm not implementing the LABEL and LOOP to the LABEL correctly in my procedure below--I keep getting a compiler error stating that l_L1 is not defined or is unrecognized:

Code: Select all

EnableASM

OpenConsole()

Global a.l = 0
Global c.l = 100

; Example inline ASM code

Procedure myInlineProc()
  MOV Eax, [v_a]  ; put contents of memory location [v_a] into eax register
  MOV Ecx, [v_c]  ; put contents of memory location [v_c] into ecx register
l_L1:
  INC Eax            ; add 1 to global variable eax register
  LOOP l_L1
  ProcedureReturn
EndProcedure

; Use myInlineProc

variable1.l = myInlineProc()
PrintN("Contents of EAX register = " + Str(variable1))

; Exit program

Print("Press [ENTER] to exit... ")
Input()
CloseConsole()

End
Can someone familiar with Inline ASM code help me with the LABEL error? Although ! l_L1: and ! LOOP l_L1 work when coding directly to the FASM compiler, LABELS and LOOPS may not work for Inline ASM. I'm not sure.

Thanks in advanced.

Logman
User avatar
mk-soft
Always Here
Always Here
Posts: 6338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Is a bug with EnableASM and labels

Code: Select all



EnableASM

OpenConsole()

Global a.l = 0
Global c.l = 100

; Example inline ASM code

Procedure myInlineProc()
  MOV Eax, [v_a]  ; put contents of memory location [v_a] into eax register
  MOV Ecx, [v_c]  ; put contents of memory location [v_c] into ecx register
  !l_L1:                ; Explizit ASM "!"
  INC Eax            ; add 1 to global variable eax register
  LOOP l_L1
  ProcedureReturn
EndProcedure

; Use myInlineProc

variable1.l = myInlineProc()
PrintN("Contents of EAX register = " + Str(variable1))

; Exit program

Print("Press [ENTER] to exit... ")
Input()
CloseConsole()

End 
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

RE: Inline Assembly Question

Post by Logman »

Thanks mk-soft.

I didn't think to mix direct instructions with inline instructions. That opens all new possibilities too because it works.

Logman
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Code: Select all

Procedure myInlineProc() 
  MOV Eax, [v_a]  ; put contents of memory location [v_a] into eax register 
  MOV Ecx, [v_c]  ; put contents of memory location [v_c] into ecx register 
  L1: ; THIS LINE IS NOT INLINE ASM, IT IS NORMAL PB CODE
  INC Eax            ; add 1 to global variable eax register 
  LOOP l_L1 
  ProcedureReturn 
EndProcedure
Don't add l_ to label definitions, the compiler adds it for you. You only add l_ when use the label from asm.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Fzarada
New User
New User
Posts: 5
Joined: Mon Aug 03, 2009 11:46 pm

Post by Fzarada »

Quote from PB reference manual:
When you reference a label, you must put the prefix 'l_' before the name. This is because PureBasic add a 'l_' before a BASIC label to avoid conflit with internal labels. The label need to be referenced in lowercase when using the inlined ASM.
Logman
User
User
Posts: 33
Joined: Sun Oct 12, 2008 5:42 pm
Location: Virginia, USA

RE: Inline Assembly Question

Post by Logman »

Thanks Trond:

I didn't catch the part about "When you REFERENCE a label, you must put the prefix..." in the manual. Didn't realize I was referencing a PB label.

I changed the LOOP statement in the code below. The manual states that you have to prefix labels using l_ when referencing them and you must reference labels using lowercase when using inline ASM.

Code: Select all

Procedure myInlineProc()
  MOV Eax, [v_a]  ; put contents of memory location [v_a] into eax register
  MOV Ecx, [v_c]  ; put contents of memory location [v_c] into ecx register
L1: ; THIS LINE IS NOT INLINE ASM, IT IS NORMAL PB CODE
  INC Eax            ; add 1 to global variable eax register
  LOOP l_l1          ; label needs to be referenced in lowercase using inline
  ProcedureReturn
EndProcedure

Don't add l_ to label definitions, the compiler adds it for you. You only add l_ when use the label from asm.
Logman :D
Post Reply