C64 Bedtime Coding (Eng) – Machine Language (#02)

Basics

This is a series of articles related to the 6502 Assembly language programming on the Commodore C64. The intention is to learn this while having fun. We will achieve this objective by writing simple games.

Machine Language

So, what is machine code and how it is written?

Here is a simple 6502 program

A2 01
8E 84 03
A9 02
6D 84 03
8D 85 03
60

As you can see it has no meaning to the human being. Well let me rephrase that. It has no meaning to most human beings, but I am sure that there are some 6502 Gurus out there that will be able to translate that. [@Bill I’m looking at you :wink: ]

The above is the extreme and we will never write such a program thankfully.

It is what the computer understands. Of course, they will be translated into binary (Not Hex) or better +5V and 0 but that is to deep down the line.

The 6510 CPU Registers

In the previous article it was shown that the CPU is using its own Registers which are just memory locations within the CPU, and these permit the CPU to perform its functions.

The 6510 processor has 3 Registers. These are called the A register which is short for the Accumulator, the X register and the Y register. There is also the Status Register (SR) and the Program Counter (PC) plus the Stack Pointer (SP).

(Article by Phaze101)

The code in the graphic is for the SWTPC 6800, not 6502…

3 Likes

What is wrong with this picture?

from the second article,

LDX   #$1        ;Load the X Register with the value of 1
STX $C000      ;Store the value of X in memory location $C000
LDA #$2        ;Load the A Register with the value of 2
ADC $C000      ;Add the value of X store at $C000 to the A register
STA $C001      ;Store the result in memory location $C001
RTS
Answer
LDX   #$1        ;Load the X Register with the value of 1
STX $C000      ;Store the value of X in memory location $C000
LDA #$2        ;Load the A Register with the value of 2
**CLC            ;Clear carry**
ADC $C000      ;Add the value of X store at $C000 to the A register
STA $C001      ;Store the result in memory location $C001
RTS
1 Like

Hmmm…straight up machine code versus assembler.
SWTPC = South West Technical Products Corp.
6800 - Motorola / Freescale 8 bit microprocessor
Fond memories of some of the things that laid the ground for the toys we have today.
OK… time to step out of the WayBack Machine

1 Like

Right on! I remember using one of these during school …

http://www.vintage-computer.com/heathkit3400.shtml

blimmy… I vaguely remember that. It was a lot for my three year old mind to take in and mostly sat in storage while I played more with the trs-80 and apple.

ok ok, my turn to step out of the wayback machine.

I am building a retro Pi so that I can write basic and assembly code in the C64 emulator. Not sure if it can be done. According to the 8 bit guy it can be done. I hope I can also save those programs I write. If all else fails there is always Zork1 to play

1 Like

There are books on 6052 machine language in the VCC area. I would prefer to write in assembly language rather than machine language, but you will have to get an assembler from somewhere. There are free ones you can download.

Yes it can be done and we’ll be doing the same in an upcoming class series.

As Bill pointed out we have all the books one would need to get into programming for the commodore including original hardware. To get started I’d also suggest to look into c64-devkit and /r/c64 getting started guide.

As for book material outside of the original manuals at the space, I can suggest getting a copy of Retro Game Dev by Derek Morris which we’ll be using as a text book for our classes.