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
    57
    Posts
    8,779
    Rep Power
    10

    Re: Line numbers and GOTO

    Danger, danger !





    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

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

    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
    Rep Power
    159

    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
    Rep Power
    159

    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

    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

  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

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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