Hand Assembling to Machine Code on the Commodore VIC-20

  /     /   Assembly     Commodore     Programming     Retro     VIC-20    

I quite enjoy designing machine language routines on paper and then hand assembling them. For many people this would have been their only option until they got a more advanced machine language monitor or assembler. I want to show how to approach this and how to enter these programs on the Vic.

An Example Program

As an example I'm going to show how to create a routine that cycles through the various screen border and background colour combinations by changing the value of $900F.

It is easier to create the routine if we use a coding sheet like the one below to record the mnemonics, operands, labels and comments. In many respects this is similar to how we would create the routine using source code on a computer which is going to be run through an assembler, but on paper.

Address Code Label Mnemonic Operand Comment
LDA$900FRecord initial screen border/background combo
LDX#$FFFirst combo is $FF
SETCOMBOSTX$900FSet screen border/background combo
LDY#$FFTime delay
DELAYDEY
BNEDELAY
DEXNext combo
BNESETCOMBO
STA$900FRestore initial screen border/background combo
RTS

Once the routine is created we can enter the addresses and enter the machine code using lookup tables for opcodes and two's complement. This routine doesn't jump to any absolute addresses and therefore can be located wherever we find suitable. Where I have filled in the addresses I have started at location $02A1 as there is free space here between $02A1 and $02FF which is reserved for user program indirects.

Address Code Label Mnemonic Operand Comment
02A1AD 0F 90LDA$900FRecord initial screen border/background combo
02A4A2 FFLDX#$FFFirst combo is $FF
02A68E 0F 90SETCOMBOSTX$900FSet screen border/background combo
02A9A0 FFLDY#$FFTime delay
02AB88DELAYDEY
02ACD0 FDBNEDELAY
02AECADEXNext combo
02AFD0 F5BNESETCOMBO
02B18D 0F 90STA$900FRestore initial screen border/background combo
02B460RTS

This leaves us with the following machine code:

AD 0F 90 A2 FF
8E 0F 90 A0 FF
88 D0 FD CA D0
F5 8D 0F 90 60

BASIC Data Statements

One of the easiest ways to enter a routine into memory is to to convert the machine code to decimal and poke it. This works well for short machine code routines, but the data statements take up quite a lot of memory and sometimes it is better to put the routine directly into memory and load it separately.

10 for a=673 to 692
20 read b
30 poke a,b
40 next a
50 data 173,15,144,162,255,142,15,144,160,255
60 data 136,208,253,202,208,245,141,15,144,96

A Simple Hex Loader

This is almost a machine language monitor and is one of the quickest and easiest ways to enter machine language directly onto a Vic. This could be used when we have created our program by hand and just want to enter the hex codes into the computer to test it. It is also useful to load the machine code for a proper monitor. The address is in decimal but each byte is entered in hex.

The program is based on one in Vic-20 Machine Code by Bruce Smith.

10 print chr$(147)
20 input "start address:";a
30 print a;":$";
40 gosub 100:h=n:print z$;
50 gosub 100:l=n:print z$
60 b=h*16+l:poke a,b
70 a=a+1:goto 30

100 get z$
110 if z$="s" then end
120 if z$>"f" then 100
130 if z$ >="a" and z$ <= "f" then n=asc(z$)-55:return
140 if z$ = "" then 100
150 n=val(z$):return

Video Demonstrating Hand Assembling to Machine Code

You can see the machine code being hand assembled, entered and run in the following video:

Creative Commons License
Hand Assembling to Machine Code on the Commodore VIC-20 by Lawrence Woodman is licensed under a Creative Commons Attribution 4.0 International License.

Related Articles

Adding Basic Stubs to Assembly Language on the Commodore VIC-20

To make machine language programs more friendly it's nice to add a Basic stub which contains a line with a SYS statement to start the code. This is easy to do on the VIC-20 and the process gives you a...   Read More

Creating a TTY Simulator in Assembly Language on the VIC-20

The Vicmon machine language cartridge is an excellent tool for exploring the Vic-20. This article and its associated video will show you how to use it to create a simple program that will change the n...   Read More

Beginning Assembly Programming on the Commodore VIC-20

The Commodore Vic-20 is a great machine to learn an assembly language on. It was released in 1981 and was the first computer to sell one million units, which contributes to its popularity today. The ...   Read More

Changing Screen Dimensions on the Commodore VIC-20

To make the most of the limited amount of memory on the VIC-20, we can increase and decrease the screen size depending on our program's priorities and what we want to achieve. If we increase the size ...   Read More

Moving the Picture Origin on the Commodore VIC-20

The VIC-20's VIC chip provides a simple yet flexible video display and one of the features that can be quite useful is the ability to alter the picture origin on the screen. This feature allows us to ...   Read More

Sign up to get new articles straight to your inbox.

Delivered by FeedBurner

Comments

blog comments powered by Disqus