The 8bit coder! - #3: Assembler...what? How am I going to get started?
Marco Rey y Sander
Customer-centric | Value-oriented | Employee inspiring | Presales Solution Architect for Microsoft Dynamics 365 FinOps (Retail/Commerce), Power Platform, Copilot Studio and IOM (intelligent order management) environment
As a retro-programmer I (almost) only program on the real old machines. When I feel like it, I turn on my C64, insert a 5.25 inch floppy disk and am happy to learn the contents of the disk with a command like Load "$",8. Most of the time it's my favorite assembler that I load and run to do some programming. Just for fun and to get some different ideas. You want to try some 8-BIT development but don't know how to start? Here is a little suggestion that can help you!
First of all it is important to understand that the C64 has a lot of memory addresses available and each of them can be accessed. This means that we can enter and read data here. For this purpose MONITOR programs exist. With this you can make the contents of memory areas visible.
However, the programs themselves must first be loaded into the memory. Better is a cartridge. These plug-in modules are plugged into the expansion port and are directly available when starting the C64.
One of the most popular plug-in modules at that time was certainly the Final Cartridge III. This had, among many other functionalities, also an integrated monitor program that could be started directly with the command MON. In the picture you can see 3 different variants of the module: modern, old and very old:
When you start the MONITOR you get, at the first view, a cryptic overview of the current status of the C64. With the command M and the range of a memory area the content is displayed. If you look at the area starting at address $0400, you directly see the contents of the screen. This could now be overwritten here directly with so-called OP codes:
This is of course "hardcore coding" and discourages possible beginners to deal with it in detail.?The monitor program also allows to write assembler code. To do this, enter the command A followed by the start address where the code is to be written.
For example, if we want to start programming at address $0801, we simply write A 0801 and enter the first command (here JSR $AEFD). After pressing the return key the line is analyzed and translated into OP codes. These are displayed directly. The assembler command JSR $AEFD means in machine language 20 FD AE. These are hexadecimal values, i.e. values between 0 and 15, where the values 10 to 15 are symbolized by the letters A to F. The value 20 (the JSR command) is directly displayed. The 20 (the command JSR) is interpreted by our C64, which only knows power on or power off (i.e. 0 and 1) as follows: 00100000.?
But what does the command JSR mean? JSR branches to the specified address by setting the program counter (PC) directly to this value, where the program execution is then continued. That means we jump with this command to the address $AEFD. But why this address now? Well, the C64, has a lot of memory addresses that are "empty" and so can be used by us programmers for our programs, whether programmed in Basic or Assembler. But there are also addresses that do certain things when called. We are talking about the ROM routines that make up the operating system of the C64. The routine $AEFD checks if a comma is present.
But how can one know this? Therefore where I also got the knowledge from: Books!
Another important starting point: archive.org.
If you now look at the ROM routines, it becomes clear what I intend to do with the few lines of code? Or?:
领英推荐
Well, programming with MON is not really fun. It helps to understand, but it is not very flexible. I can't document the code, I can't create dynamic jumps based on jump labels. In short: Programming is not done with it.
Another type of assembler programs allows to capture code like in a Basic program. For this each line is started with a line number and then the assembler code is captured. Big advantage: Comments can be stored and the source code is thus still comprehensible after a long time. It is also possible to define jump marks and to realize jumps (for example in a loop or branch) dynamically. So you don't have to calculate and store the jump address in advance. Another advantage of this type of assembler is the possibility to define macros and to reuse the code contained therein several times. But the biggest advantage, at least for me, is to define variables. Thus no longer the cryptic address of the routine must be addressed, but a speaking variable. The code is thus much easier to read and understand:
With RUN the compilation run of the assembler is executed and the translation into OP codes is performed. The result is displayed and the program can be called and executed with a SYS command:
But I personally favor the king of assembler programs: Turbo Macro Pro (https://turbo.style64.org/). Without leading lines, code can be copied, deleted and pasted elsewhere at any time. Macros, variables, jump marks are possible. Comments too, of course. With the INCLUDE command it is possible to include further source files, thus to realize also really large programs:
What does our little program do now? Assembler programs can, first of all, not be started with the RUN command. To start an assembler program the address to be started is called directly with a SYS command. For example: SYS20480. With our program we extend the call of SYS and can pass 2 numeric values. We use these to set the frame and background color. Simple, isn't it?
Happy coding!
What do you think? I love feedback, suggestions, or questions! Write your comments under the article. If you like this article, then share it! If you think it is interesting for others, then share it!
#8bit #coding #retro #developer #c64 #commodore #assembler