Page 1 of 1

Inline Assembly Code Question

Posted: Thu Aug 06, 2009 3:44 pm
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

Posted: Thu Aug 06, 2009 4:25 pm
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 

RE: Inline Assembly Question

Posted: Thu Aug 06, 2009 5:36 pm
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

Posted: Sat Aug 08, 2009 10:12 am
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.

Posted: Sat Aug 08, 2009 10:48 am
by blueznl

Posted: Sun Aug 09, 2009 11:16 am
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.

RE: Inline Assembly Question

Posted: Tue Aug 11, 2009 6:53 pm
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