1

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
Andrew
  • 539
  • 5
  • 20
  • That sounds like an installation issue. As to the addition, something is still in those memory locations and the cpu would add those just fine even though you don't know what the inputs and hence the output is going to be. – Jester Jul 28 '19 at 14:13
  • I have tried uninstalling, then installing again, but I've had no luck. By adding a config file with memory addresses in it I have managed to make the error go away. However, I get a new error now: "exec format error". As a work around I have slightly modified the code, and now using https://github.com/skilldrick/6502js to compile and run it – Andrew Jul 28 '19 at 15:03
  • *at the moment I guess the $100 and $200 don't actually contain any values* - memory and registers *always* contain a value. The power-on or program-startup state of registers and memory might not be guaranteed by anything, but a load from that address will get a value. (Even if your 6502 doesn't have that much RAM connected, I think it will read some value after putting the address on the address bus. A simulated 6502 might just read zeros.) – Peter Cordes Jul 28 '19 at 23:38

2 Answers2

3

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.

Nick Westgate
  • 3,088
  • 2
  • 34
  • 41
  • thank you nick, it is strange that isnt the default. I can now get it to compile but I get the error "exec format error: ./example" when i try and run it - do I need another program now to do this? – Andrew Jul 29 '19 at 12:11
  • That's right, your Mac can't run a 6502 binary. You'll need to use an emulator (e.g. Apple II or C64) and use that to run your output file. The other answer I linked to builds a C64 object. Don't forget to choose the correct target with "-t", and you might need to provide a start address in the code with ".org". – Nick Westgate Jul 29 '19 at 22:19
  • ok, I will look into that, thank you. One final thing, sorry. So my program will add the contents of ADR1 and 2, then move it to ADR3. Is there then a quick and easy way to query ADR3 to see its contents, to make sure it has given the correct answer? Or is that not really possible while keeping the programs simple? – Andrew Jul 30 '19 at 08:52
  • 1
    How to do that is platform specific. For instance on the Apple II you could add (first optionally "LDA ADR3", though that isn't needed in your case as ADR3 is already in A, then) "JSR $FDDA" at the end of your code. This calls a ROM routine which prints the contents of A as hex digits on the text screen. Or after your code is run, in BASIC you would use PRINT PEEK (768) to print ADR3 in decimal. For the C64 platform you would have to research how to do something similar. – Nick Westgate Jul 30 '19 at 23:18
  • this is very useful info, I've found that though theres lots of great resources online to explain how to write 6502 asm its sometimes not made clear how to run it and see the results if you are starting as an absolute beginner. I think I will install an Apple II emulator and try that what you have suggested out, thanks. What is the relation between ADR3 and (768)? – Andrew Jul 31 '19 at 14:35
  • Decimal 768 = $300 hex, the address of ADR3. If I've answered your question please accept it. – Nick Westgate Jul 31 '19 at 20:25
1

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)