ML code memory area

Basic and Machine Language

Moderator: Moderators

Post Reply
traymond20
Vic 20 Newbie
Posts: 15
Joined: Sun May 29, 2016 3:18 pm
Location: U.S.A. WYOMING

ML code memory area

Post by traymond20 »

I have a beginners book on ML from Compute (I forget the title) its very basic but does have handy
number tables that are handy and I think for Opp codes.

This book mentions the areas of memory for the starting address, is this an actual memory address?
Is this starting address you usually SYS to start the ML code?

This book also mentions combining ML with basic I think using decimal numbers in Data statements.

I forget the programmers name he was Canadian very popular in the 80's but did a number of videos and books, but a very good
ML programmer. Anyway he wrote a very basic book on ML for compute books, I have this book and learned simple things about ML as far
as the difference with HEX or assembly.

I just want to try and learn the basics and start simple and try to make sense of ML but it always seems to eat my lunch and intimidate me. :)

Any suggestions on ML books for either the Vic or other CBM computers?

Thanks,

traymond
User avatar
darkatx
Vic 20 Afficionado
Posts: 471
Joined: Wed Feb 04, 2009 2:17 pm
Location: Canada

Re: ML code memory area

Post by darkatx »

You just described the late great Jim Butterfield.

http://www.bombjack.org/commodore/books.htm

Go down to Machine Language and Assembly Language sub heading and get Machine Language on the Commodore 64, 128 and other Commodore Computers Revised and Expanded Edition Its the binary digits on the beach under a parasol :)
Learning all the time... :)
User avatar
Mike
Herr VC
Posts: 4830
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: ML code memory area

Post by Mike »

traymond20 wrote:This book mentions the areas of memory for the starting address, is this an actual memory address? Is this starting address you usually SYS to start the ML code?
There are several candidates of memory areas where to put small chunks of machine code, so it doesn't collide with a BASIC program that uses the code. It is also possible to block parts of the BASIC memory, thus allocate it for a bigger machine code part or for other uses - like a re-defined character set, or data tables.

SYS does not necessarily point to the start of that allocated memory range, it is also possible to have it start the machine code somewhere in the middle, when other parts of the machine code are located before the entry point. Those other parts could quite possibly be subroutines called from within the machine code main part, with JSR.

You'll quite often see programs with a BASIC stub that just contains a SYS statement. When RUN, it executes machine code, that is (most often directly) located behind that BASIC stub. It is quite instructive to use a monitor like VICMON (or the one built-in to VICE) to take a peek at that stub, to get an idea how it is constructed.

What you shouldn't do is, assemble a piece of machine code directly at the start of BASIC (i.e. to $1001 on unexpanded VIC-20, for example). If that code is loaded, the BASIC interpreter assumes, that it is a BASIC program and will invoke the line relinker, which will inevitably change your code quite unexpectedly or even will crash: see here.
Last edited by Mike on Sat Oct 22, 2016 11:05 am, edited 1 time in total.
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Re: ML code memory area

Post by GreyGhost »

This is the BASIC stub I use at the beginning of my programs. Make this the first part of your program and start your code after start_ml = *.

Code: Select all

* = $0801                       ; Start of Basic for C64($0801)
                                ; Start of Basic for unexpanded vic($1001)
                                ; Start of Basic for 3k vic($0401)
                                ; Start of Basic for 8k+ vic($1201)
        word eop                ; Pointer to next BASIC line
        word 10                 ; Line number
        byte $9e                ; SYS token
        text start_ml           ; ML start address
        byte 0                  ; End of Line
eop
        word 0                  ; End of Program

start_ml = *                    ; ML code goes after this line
Rob
traymond20
Vic 20 Newbie
Posts: 15
Joined: Sun May 29, 2016 3:18 pm
Location: U.S.A. WYOMING

Re: ML code memory area

Post by traymond20 »

I see I saved that for my programming notes maybe tinker with my
Hesmon cartridge.

Thanks,

traymond
Post Reply