Announcement

Collapse
No announcement yet.

Labels and LineNumbers

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

  • Lance Edmonds
    replied
    To be clear:
    In PB/DLL 5.0 (and earlier) and PB/CC 1.0 labels were "global".

    In PB/DLL 6.0 and PB/CC 2.0, the rules on label scope changed so that they became "local" within subs/functions (referenced by BASIC code), however, the behavior of inline assembler was not changed.

    BUT...

    This behavior is *definately* going to change so that inline assembly code can not reference labels that are outside of it's "local" scope - if you rely or utilize the current compiler behavior in your existing code, then you code will *not* work with future versions of the compiler.

    Unless you really understand what the compiler is doing in the generated machine code, DO NOT try jumping out of scope! I'll say that again: DO NOT try jumping out of scope. Doing so it to almost guarantee one GPF point for trying because doing so will cause code (whose stack frame has not been set up) to execute - potentially very dangerous stuff for non-assembly-guru's.

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

    Leave a comment:


  • Semen Matusovski
    replied
    ASM works incorrect in PB/CC and PB/DLL (takes first address).
    But CodePtr and all Basic's statements works fine.

    Code:
       #Compile Exe
       #Dim All
       #Register None
     
       Function PbMain
          Local l1 As Long
     Start:
          ! LEA EAX, DWORD PTR Start
          ! MOV L1, EAX
          MsgBox "PbMain: ASM " + Str$(l1) + " BAS " + Str$(CodePtr(Start))
          Call TestSub
       End Function
       
       Sub TestSub
          Local l2 As Long
       Start1:
       Start:
          ! LEA EAX, DWORD PTR Start
          ! MOV L2, EAX
          MsgBox "Test0: ASM " + Str$(l2) + " BAS " + Str$(CodePtr(Start))
          ! LEA EAX, DWORD PTR Start1
          ! MOV L2, EAX
          MsgBox "Test1: ASM " + Str$(l2) + " BAS " + Str$(CodePtr(Start1))
       End Sub
    Like Fred, I also don't understand, why it's not possible to use the same labelName and Variable-name in different functions/Subs (VB allows it, PB - if to see manual - doesn't refuse)

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

    Leave a comment:


  • Steve Hutchesson
    replied
    Ron,

    Thanks for running this test, it confirms what I had found before
    that using a duplicate label in another SUB/FUNCTION produces is
    unreliable. I have been able to routinely reproduce the problem
    so I have stayed with unique labels.

    What I have not done is test the distinction between purely basic
    code and mixed inline/basic code so whan I get a chance, I will have
    to do a test piece to see if it is consistent when no ASM instructions
    are used.

    Regards,

    [email protected]

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

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Steve, when you get the GPFs with labels does it involve inline asm?
    I recalled some strange things happening when I had the same label defined in more than one sub/function.
    This snippet will go bonkers if the inline asm is used but works ok if only the basic code is used.
    If you change the name of one of the labels and the jump referencing it, the code works fine also.

    This has probably been brought up before. It appears best to ensure you use globally unique labels with PB's inline assembler.

    Ron
    Code:
    #Dim All
    #Register None
    #Option Version4
     
    Function PBMain() Export
      Local l as long
    Start:
      !inc l
      !mov eax, l
      !cmp eax, 2
      !jle Start
        'Incr l
        'if l <= 2 then
        '  Goto Start
        'end if
      stdout "Before Call - L:" & Str$(l)
      Call TestSub
      stdout "After Call - L:" & Str$(l)
    End Function
     
    Sub TestSub Export
       'Exit Sub
      Local l as Long
    Start:
      !inc l
      !cmp l, 2
      !jle Start
        'Incr l
        'if l <= 2 then
        '  Goto Start
        'end if
    End Sub
     
    Here's the disassembled code which shows the same label address being used by both functions.
     
    =========
    PBMAIN
    =========
    :0040108C 55                      push ebp
    :0040108D 8BEC                    mov ebp, esp
    :0040108F 53                      push ebx
    :00401090 56                      push esi
    :00401091 57                      push edi
    :00401092 83EC5C                  sub esp, 0000005C
    :00401095 31F6                    xor esi, esi
    :00401097 56                      push esi
    :00401098 56                      push esi
    :00401099 56                      push esi
    :0040109A 56                      push esi
    :0040109B 56                      push esi
    ---------
    :0040109C FF4584                  inc dword[ebp-7C] 
    :0040109F 8B4584                  mov eax, dword[ebp-7C]
    :004010A2 3D02000000              cmp eax, 00000002
    :004010A7 0F8EEFFFFFFF            jle 0040109C 
    :004010AD BAB0334000              mov edx, 004033B0
    :004010B2 E83A0B0000              call 00401BF1
    :004010B7 DB4584                  fild dword[ebp-7C]
    :004010BA E8570A0000              call 00401B16
    :004010BF E8BC0A0000              call 00401B80
    :004010C4 E8E5060000              call 004017AE
    :004010C9 E808070000              call 004017D6
    :004010CE E832000000              call 00401105
                                ;;TESTSUB
    :004010D3 BAC2334000              mov edx, 004033C2
    :004010D8 E8140B0000              call 00401BF1
    :004010DD DB4584                  fild dword[ebp-7C]
    :004010E0 E8310A0000              call 00401B16
    :004010E5 E8960A0000              call 00401B80
    :004010EA E8BF060000              call 004017AE
    :004010EF E8E2060000              call 004017D6
    :004010F4 8B4588                  mov eax, dword[ebp-78]
    :004010F7 8D65F4                  lea esp, dword[ebp-0C]
    :004010FA 5F                      pop edi
    :004010FB 5E                      pop esi
    :004010FC 5B                      pop ebx
    :004010FD 5D                      pop ebp
    :004010FE C3                      ret
     
    :004010FF 00 00 00 00 70 62                                 ....pb
     
    =========
    TESTSUB
    =========
    :00401105 55                      push ebp
    :00401106 8BEC                    mov ebp, esp
    :00401108 53                      push ebx
    :00401109 56                      push esi
    :0040110A 57                      push edi
    :0040110B 83EC5C                  sub esp, 0000005C
    :0040110E 31F6                    xor esi, esi
    :00401110 56                      push esi
    :00401111 56                      push esi
    :00401112 56                      push esi
    :00401113 56                      push esi
    :00401114 FF4588                  inc dword[ebp-78]
    :00401117 837D8802                cmp dword[ebp-78], 00000002
    :0040111B 0F8E7BFFFFFF            jle 0040109C 
    :00401121 8D65F4                  lea esp, dword[ebp-0C]
    :00401124 5F                      pop edi
    :00401125 5E                      pop esi
    :00401126 5B                      pop ebx
    :00401127 5D                      pop ebp
    :00401128 C3                      ret
    [This message has been edited by Ron Pierce (edited April 09, 2000).]

    Leave a comment:


  • Steve Hutchesson
    replied
    Fred,

    If I remember rightly, it was one of the conditions of the change
    from global labels in PB5 to local labels in PB6. I have never
    been able to get local labels to work at runtime, they build ok
    but i get unexplained GP faults from running them so I always use
    labels of unique names and rely on memory and a naming convention
    I use to ensure they are unique.

    I would prefer the GLOBAL labels personally as it allows you to do
    some interesting and useful things and it had duplicate label
    checking. The concept of LOCAL labels is a useful one but I would
    prefer to have both.

    Regards,

    [email protected]bq.com.au


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

    Leave a comment:


  • Fred Oxenby
    started a topic Labels and LineNumbers

    Labels and LineNumbers

    Labels and LineNumbers ar private to the Sub/Function where they occure.

    Why do you get Error 466 Duplicate Name definition if you
    use a labelName as a variable-name.
    Of course labelName and Variable-name is in different functions/Subs


    -------------
    Fred
    mailto:[email protected][email protected]</A>
    http://www.oxenby.se

Working...
X