Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Line numbers and GOTO

  1. #1

    Line numbers and GOTO

    Eros may wish to avert his gaze.

    http://community.thinbasic.com/index.php?topic=2517

    LineNumbers1.tbasic
    [code=thinbasic]

    'LINE NUMBERS
    '

    uses "oxygen","file"
    dim src as string

    src = "
    10 rem legacy
    20 dim a,b,c,i
    30 a=1 : b=1
    40 c=a+b
    60: i=i+1
    70: if i<20 then a=b : b=c : goto 40 '
    80:
    80: print `FIBONACCI NUMBER: `+str$(c/b)
    "




    o2_basic src

    'msgbox 0, o2_view "o2h "+src

    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if

    o2_exec

    'msgbox 0,o2_error

    [/code]

  2. #2

    Re: Line numbers and GOTO


    This is a more palatable use of line numbers:

    [code=thinbasic]
    '
    'LINE NUMBERS: CONTEMPORARY STYLE
    '

    uses "oxygen","file"
    dim src as string

    src = "

    10:

    dim a=1, b=1, c=0, i=0

    20:

    c=a+b
    inc i
    if i<20 then a=b : b=c : goto 20

    30:

    print `FIBONACCI NUMBER: ` str c/b

    40:

    "

    o2_basic src
    [/code]

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,313
    Blog Entries
    2
    Rep Power
    10

    Re: Line numbers and GOTO

    Danger, danger !





    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    62
    Posts
    3,869
    Rep Power
    398

    Re: Line numbers and GOTO

    The first version looked fine to me and the code is tighter. Never saw a version like the second... it might grow on me so I won't be quick to judge.

    Well the jmp command was just like a goto but with a label involved instead of line number in terms of a feature. I assume jmp is more efficient and is
    not hated as much as goto?

    I like line numbers as you know exactly where you are in the code. It is a feature I requested for thinAir and I know it will come in the future some time.
    Without line numbers you have to always sort of analyze the code and it takes a few milliseconds to a couple of seconds depending on the code to know where you are when you scroll.

    So thanks for adding them to the module!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5

    Re: Line numbers and GOTO


    GOTO translates to Assembly code jmp long in this instance. But Line numbers have to be turned into non-numbers internally. so all line numbers are prefixed with underscores _

    To use JMP with line numbers it would be: jmp long _100 etc


    When oxygegen reports an error it does not give the physical line number - instead it gives the last label encountered. Line numbers can be used as trace markers for this purpose - then removed in the final code.

  6. #6
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Blog Entries
    1
    Rep Power
    154

    Re: Line numbers and GOTO

    on the amiga I used to push my return address on the stack and do a JMP to a subroutine because it was quicker than a jsr would this still apply with 8086+ cpus?
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  7. #7

    Re: Line numbers and GOTO


    Push return address and Jump is the operational equivalent of call - The slow parts are storing the return address to stack memory then refilling the instruction pipeline with code from a new memory location.

    On today's 8086's Memory access time is the limiting factor.

    What processor did your Amiga have? And was it doing any housekeeping prior to the call, which you might have been able to bypass?

  8. #8
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Blog Entries
    1
    Rep Power
    154

    Re: Line numbers and GOTO

    The Amiga used the 68000 range of CPUs and I cant remember what the code looked like its been about 10 years at least

    [code=asm]
    LEA returnaddress, (sp)+
    JMP mysub[/code]

    Timings

    http://linas.org/mirrors/www.nvg.ntn...000timing.HTML
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  9. #9
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    52
    Posts
    3,283
    Blog Entries
    2
    Rep Power
    340

    Re: Line numbers and GOTO

    Quote Originally Posted by Michael Clease
    The Amiga used the 68000 range of CPUs and I cant remember what the code looked like its been about 10 years at least

    [code=asm]
    LEA returnaddress, (sp)+
    JMP mysub[/code]

    Timings

    http://linas.org/mirrors/www.nvg.ntn...000timing.HTML
    Yes, that were the days. :P
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  10. #10

    Re: Line numbers and GOTO

    The first version looked fine to me and the code is tighter. Never saw a version like the second... it might grow on me so I won't be quick to judge.
    In ScriptBasic, line numbers are labels and optional for compatibility. The numbering doesn't have to be in any order or used on every line.

    100 FOR x = 1 TO 10
      PRINT x 
      GOSUB 50
    NEXT x
    
    END
    
    50 PRINTNL
     RETURN
    
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •