Silly Questions

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post by xubuntu »

Thank you XavSnap, it was the missing "then".
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post by xubuntu »

When we execute "run" in basic, where does it jump to? At which memory location the "run" command starts at? It's always the same address, isn't it?
User avatar
1024MAK
Posts: 5102
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Silly Questions

Post by 1024MAK »

RUN with no parameters always starts executing from the first line of the program. The address in memory is 16509.

In some BASICs, like the BASIC in a ZX81, a line number can be specified:

RUN 100

This starts execution of the program starting at line 100.

In ZX81 BASIC, if line 100 does not exist, it’s the next line after where execution starts.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post by xubuntu »

ok then. So...

We make a "new" program and we type in basic

10 CLS

which is in assembly
call $0a02

which is in machine language
cd 2a 0a

which is in decimal
205 42 10

So PRINT PEEK 16509 should return 205
PRINT PEEK 16510 should return 42
and PRINT PEEK 16511 should return 10.

And yet, PRINT PEEK 16509 returns 0
PRINT PEEK 16510 returns 10
and PRINT PEEK 16511 returns 2.

What am I missing here.
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Silly Questions

Post by bobs »

BASIC is interpreted on-the-fly, not compiled, so you won’t ever see the actual assembly call in the listing.

For more details look at chapter 27 in the ZX81 manual
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post by xubuntu »

Not the assembly but I will see the machine code instructions.

When you type "list" the program gets from somewhere and lists the code. Where from ?
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Silly Questions

Post by bobs »

No, you won’t. LIST will show the BASIC program as it is in memory. For example, the first two bytes you give in your example - 0, 10 - is the line number “10”. The machine code instructions are never stored anywhere, the BASIC is interpreted line by-line as the program is ran. This is completely different to a compiler.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Silly Questions

Post by XavSnap »

:shock:

Seem to be a CHAT GPT tread ! (LLM, a CrayonLike tread!)

Don't do that....Don't do that....

ZX81 BASIC is based on tokens !
And yet, PRINT PEEK 16509 returns 0
PRINT PEEK 16510 returns 10
Line 10
and PRINT PEEK 16511 returns 2.
BASIC len string...
basiccls.JPG

Zx BASIC is a "script" to the BASIC ROM MONITOR.
Don't try to read a BASIC code like an ASM compiled program.

If you had to compile it, use MCODER or MGT compiler.
Last edited by XavSnap on Fri Mar 24, 2023 12:36 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Silly Questions

Post by Moggy »

bobs wrote: Wed Mar 22, 2023 12:41 pm No, you won’t. LIST will show the BASIC program as it is in memory. For example, the first two bytes you give in your example - 0, 10 - is the line number “10”. The machine code instructions are never stored anywhere, the BASIC is interpreted line by-line as the program is ran. This is completely different to a compiler.
This is exactly the same mistake I made 40 odd years ago thinking the machine code could just be magically pointed to in some kind of location, not realising that as you say it is interpreted line at a time rather than compiled and stored.
User avatar
1024MAK
Posts: 5102
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Silly Questions

Post by 1024MAK »

The BASIC interpreter takes each command one at a time, along with it’s parameters. It then works out what class of command it is. If a numeric expression is found, BASIC’s internal calculator routine is used to evaluate the expression. The result is then passed to the part of the ROM that actually carries out the command.

In order to fit as much functionality in only 8K bytes of ROM, the ROM code is designed to be space efficient. Hence the way that the ROM code works, is rather convoluted.

At no point will you see any machine code stored in RAM during the execution of a purely BASIC program.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply