Compiling a simple program using ca65

1.5k Views Asked by At

I am beginning to learn 6502 assembly using Rodney Zaks' book Programming the 6502. In it there is example code, I would like to be able to run it on my macbook. I am hoping that the code will be able to run in the form it is presented in the book, but I am unsure.

I have downloaded the ca65 assembler, but I am running into some trouble. The command ca65 3_1.as works, but following that up with ld65 -o example 3_1.o (which I believed to be correct) resulted in the error: ld65: Error: Memory configuration missing

The code from the file 3_1.as is below.

Can anyone advise on how to solve my problem?

(As a small side question, at the moment I guess the $100 and $200 don't actually contain any values, so no actual addition would be done even if the program could run, is this correct?)

CLC      ; CLEAR CARRY BIT
CLD      ; CLEAR DECIMAL BIT

ADR1 = $100 ; WHERE IN MEMORY ARE THESE THINGS
ADR2 = $200
ADR3 = $300 

LDA ADR1 ; LOAD CONTENTS OF ADR1 INTO ACCUMULATOR
ADC ADR2 ; ADD CONTENTS OF ADR2 INTO ACCUMULATOR 
STA ADR3 ; TRANSFER CONTENT OF ACC TO ADR3
2

There are 2 best solutions below

6
On BEST ANSWER

To fix the linker error you need to provide a target system which will provide the memory configuration.

For example, it's a bit silly that this isn't the default:

ld65 -t none -o example 3_1.o

Note that you can also assemble and link with one command. See my answer here.

0
On

Here is a more complete program to add to the already good answers. I noticed the author didn't put in a place to start the program either. Different types of assemblers have minor ticks about how they handle syntax like the ORG statement. Some are ".Org" which means start the program here and assemble up the way in memory. "*=" can also signify the same thing (sometimes both work). This program should work on a commodore 64. With a few tweaks it can work on an Apple ][ as well(change charout to ffda and the start location). I would definitely recommend the C64 for coding growth though since it has so many more interesting hardware capabilities. It also has a massive global coding scene. Here is a link for a large volume of disk mags and ML tutorials that go beyond the basics. No books seem to do that and tend to stick to syntactical approaches only. Which is far from useful if you want to do anything big with this stuff like control houses and run aircraft components.

https://csdb.dk/release/?id=8717

.ORG = 080D ; 
CLC      ; CLEAR CARRY BIT
CLD      ; CLEAR DECIMAL BIT
LDA #$94 ; load accumulator with 94
STA ADR1 ; move 94 into adr1 (both combined is adr1 = 94)
LDA #$32 ; load accumulator with 32
STA ADR2 ; move 32(in Acc.) into adr1 (both lines is adr2 = Acc, or adr2 = 32)

LDA ADR1 ; LOAD CONTENTS OF ADR1 INTO ACCUMULATOR
ADC ADR2 ; ADD CONTENTS OF ADR2 INTO ACCUMULATOR 
STA ADR3 ; TRANSFER CONTENT OF ACC TO ADR3
JSR CHAROUT; print the result

RTS ; return from the program

; declarations can be in confusing places and still work.
; I just saw a program where the declarations were after the code
; and before the subroutines.
;-------------------------------------------
ADR1 = $100 ; WHERE IN MEMORY ARE THESE THINGS
ADR2 = $200
ADR3 = $300 
CHAROUT = $ffd2 ; character out routine commodore 64. (prints a byte to screen)