Page 2 of 2

Re: Silly Questions

Posted: Sun Mar 19, 2023 6:49 am
by xubuntu
Thank you XavSnap, it was the missing "then".

Re: Silly Questions

Posted: Wed Mar 22, 2023 7:43 am
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?

Re: Silly Questions

Posted: Wed Mar 22, 2023 8:24 am
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

Re: Silly Questions

Posted: Wed Mar 22, 2023 9:44 am
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.

Re: Silly Questions

Posted: Wed Mar 22, 2023 12:04 pm
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

Re: Silly Questions

Posted: Wed Mar 22, 2023 12:31 pm
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 ?

Re: Silly Questions

Posted: Wed Mar 22, 2023 12:41 pm
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.

Re: Silly Questions

Posted: Wed Mar 22, 2023 1:07 pm
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.

Re: Silly Questions

Posted: Wed Mar 22, 2023 3:35 pm
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.

Re: Silly Questions

Posted: Wed Mar 22, 2023 7:31 pm
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