Jump to content
  • 0

Where is a good location to put assembly programs?


dmc6502
 Share

Question

4 answers to this question

Recommended Posts

  • 0

If you don't enter any BASIC lines (with a line number) or any immediate statements that use any kind of variables, you technically can use anywhere from $0400 to $9eff. Of course be sure to save your ML program first, if you're ever in doubt.

But, if you do want to create an ML program that can be loaded and run as if it were a BASIC program, below are the bytes you need.  Saving is a different matter, you'll need to save from $0801 to wherever your ML ends. If you use BASIC's SAVE command, it would just save the stub and leave your ML code behind.

Here are those bytes:

0801: 0b 08 01 00 9e 32 30 36 31 00 00 00
080d: (where your program starts)

What are these bytes doing?  They're "grouped" like this:  (0b 08)  (01 00)  (9e)  (32 30 36 31)  (00)  (00 00)

0b 08 is the link to the next BASIC line at $080b.  This actually points to the 2nd set of 00's at the end of the line above, they are the link to the *next* BASIC line, and since they are 0, BASIC knows this is the end of the program (end of the stub).
01 00 is the line number, you can change these to whatever you like.  ff 00 would be line 255.  00 01 would be line 256 etc. (little-endian)
9e is the BASIC token for SYS
32 30 36 31 are the hex ASCII codes for 2061 which is decimal for $080d (the rightmost digits happen to be the decimal digits)
00 is the BASIC end of line marker
00 00 as already mentioned is the null link marking the end of the BASIC program

Thus the BASIC stub will SYS2061 your program that begins immediately following the three 00's, at $080d

  • Like 3
Link to comment
Share on other sites

  • 0

Hi.

0400-07FF "golden RAM" is OK to use.

I think it will not play nicely with BASIC if your program is larger than that, and passes the 0800 boundary.

I would say most programs are made with a small BASIC stub so you can start it with RUN. If you do it like this, the assembly code is stored in RAM right after the end of the BASIC stub, normally at 080D.

How you build an assembly program with a BASIC stub depends on your assembly environment.

If using the CC65 tool chain it is done automatically by the linker if you compile with a command like this:

cl65 -o MYPROGRAM.PRG -u __EXEHDR__ -t cx16 -C cx16-asm.cfg MYSOURCE.S

If you haven't used CC65, there's a bit of a learning curve. But it is worth it in the long run.

Edited by Stefan
  • Like 1
Link to comment
Share on other sites

  • 0
2 hours ago, Stefan said:

Hi.

0400-07FF "golden RAM" is OK to use.

I think it will not play nicely with BASIC if your program is larger than that, and passes the 0800 boundary.

I would say most programs are made with a small BASIC stub so you can start it with RUN. If you do it like this, the assembly code is stored in RAM right after the end of the BASIC stub, normally at 080D.

How you build an assembly program with a BASIC stub depends on your assembly environment.

If using the CC65 tool chain it is done automatically by the linker if you compile with a command like this:

cl65 -o MYPROGRAM.PRG -u __EXEHDR__ -t cx16 -C cx16-asm.cfg MYSOURCE.S

If you haven't used CC65, there's a bit of a learning curve. But it is worth it in the long run.

Thanks for the advice. About 90% of anything I will write will easily fit within 1k. I used to use the C64 Machine Language Monitor cartridge, so I'm right at home with the X16 monitor. I'll probably use that exclusively.

Link to comment
Share on other sites

  • 0

$080D is the easiest if you just was to do LOAD "MYAPP.PRG" and just RUN it. You can always programmatically use "golden RAM", you just won't be able to load to it directly out of your built image. You can have a separate file to load from the main one if you need the extra RAM, too.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use