Jump to content
IGNORED

Check/test an assembler


pfeuh

Recommended Posts

Hello,

 

Is there a kind of test bench for a 6502 assembler? Like an asm source file, with all the instructions and a list of the resulting bytes. Perhaps I am not clear, I mean two files like these:

    ; test.opcodes.asm

    org = $1234
start
    BRK          ; opcode 000 $00
    ORA ($a5,X)  ; opcode 001 $01
                 ; opcode 002 $02 illegal
...
...
...
    SBC $4400,X  ; opcode 253 $fd
    INC $4321,X  ; opcode 254 $FE
                 ; opcode 255 $ff illegal
; results.txt

$00
$01 $05
...
...
...
$fd $00 $44
$fe $21 $43

 

Edited by pfeuh
Link to comment
Share on other sites

Not that I know of.

 

Issues with both native and cross-platform assemblers can include stuff like:

- Zero page values represented as absolute instead of zp in generated instructions.

- Forward reference to labels not working properly.

 

Then there's other things like whether it supports just base 6502 or variants like 6502C and 65816.

 

I guess a validator program might be good, it could verify itself by checksum of the generated test instructions.

Link to comment
Share on other sites

Thank you for this answer. I'm not so far at the moment, but it could be my cup of tea. Today, I just want to be sure of my validation code input & output. As I supposed that this doesn't exist, I wrote something to validate an assembler and a disassembler. Here it is. It could be a begin of a validation  program, if somebody can test it. I'm absolutely not sure at the moment, I may have missed some instruction or bugged some other. Here are input and output files. in TSTOPCO. bin (which is a binary file for Atari assembled by cc65's assembler)n the validation code begin at $206f. the input file is generated from the table I would like to validate, test_opcodes.dump is generated by my 6502 emulator under construction.

 

TSTOPCO.BINtest_opcodes.dumptest_opcodes.asm

Link to comment
Share on other sites

Hi there,

 

I didn't see your post in time sadly. FWIW here's what we use to test the 6502 part of rmac. Perhaps you could use it to cross reference stuff?

6502.zip

 

The idea is that running the source file past the assembler should produce an identical listing to the .ref file.

Edited by ggn
Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

I've just sent 2 bugs to the Atasm page on sourceforge https://sourceforge.net/p/atasm/bugs/

There are tickets from 11 years ago, is anybody aware of?

 

I've used Atasm as a reference assembler to make some unitary tests on my tiny one. Unfortunately, I spend more time on Atasm than I should do. I think I'm going to switch on cc65 assembler. It's less user friendly, because you can't set the start address where you want, each time, a little retro-engineering is mandatory. Any advice?

 

 

 

Link to comment
Share on other sites

On 8/31/2020 at 4:44 PM, pfeuh said:

I think I'm going to switch on cc65 assembler. It's less user friendly, because you can't set the start address where you want,

I have used Atasm and ca65 for a while, and eventually switched to mads. ca65 is not too bad. Working with the linker might be intimidating at first. But you can set your start address everywhere you want with .ORG

 

https://www.cc65.org/doc/ca65-11.html#ss11.72

 

Quote

each time, a little retro-engineering is mandatory. Any advice?

 

Atasm hasn't been updated for at least six years. You could try sending a message to schmelze directly.

 

Edited by ivop
add missing word
Link to comment
Share on other sites

Thank you for the links. It's done, I've sent a messsage to Schmelze. Concerning .ORG, i've tried to begin some code starting with it, but it relocate to $2000 and something, after a start code I presume.

 

cl65 -O -t atari test_opcodes_cc65.asm -o TEST_OPCODES_CC65.BIN

    .ORG 1536
    .export _main
_main:
LABEL_01: BRK
    ORA ($A7,X)
    ORA $6C
    ASL $C1
    PHP
    ORA #$F5
pfeuh@pfeuhsLaptop:/media/pfeuh/70b90f4a-e5a6-4a83-bf19-1feffc44cab0/Documents/sources/C_language/linux/vosc6502$ ./vosc6502.exe -bat g.bat
VOSC6502 (Virtual Old School Computer with a 6502 processor)
version 0.99 -------------------------- MMXX - Pierre Faller

ataload /media/pfeuh/70b90f4a-e5a6-4a83-bf19-1feffc44cab0/Documents/sources/python/atasmPrecompiler/utest/TEST_OPCODES_CC65.BIN
838 bytes loaded
PC:FFFF SP:FD A:00 X:00 Y:00 S:..U..... _ ff -- -- ???
>f 0 1 a7
Searching for 00 01 A7
206F - 0001 occurences found
>u 206f
206f 00           brk
2070 01 a7        ora ($a7,x)
2072 05 6c        ora $6c
2074 06 c1        asl $c1
2076 08           php
2077 09 f5        ora #$f5
2079 0a           asl a
207a 0d a6 87     ora $87a6
207d 0e 7e 46     asl $467e
2080 10 fe        bpl $2080
>

 

Link to comment
Share on other sites

Yes, of course, here it is.

 

gcc -Wall 6502.c dsp56k_amode.c eagen.c listing.c op.c symbol.c 68kgen.c dsp56k.c error.c mach.c procln.c token.c amode.c dsp56kgen.c expr.c macro.c riscasm.c debug.c dsp56k_mach.c fltpoint.c mark.c rmac.c direct.c eagen0.c kwgen.c object.c sect.c -o rmac

 

 

rmac.log

Edited by pfeuh
log not complete
Link to comment
Share on other sites

 

2 minutes ago, pfeuh said:

I was editing the log which was not complete.

I assume you're trying to compile it by hand instead of using the supplied makefile? That won't work as some tools need to be built and produce some header files before the main code can be compiled.

 

In other words, did you try typing "make"? 

Link to comment
Share on other sites

On 8/31/2020 at 5:36 PM, ivop said:

ca65 is not too bad. Working with the linker might be intimidating at first. But you can set your start address everywhere you want with .ORG

 

With ca65/cc65 ".org" is the wrong thing. Use "-S <address>" when linking to specify where you want your program to be located.

  • Like 1
Link to comment
Share on other sites

Thank you.

 

I've tried with this, got an error:

 

cl65 -O -t atari test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN -S 1536

cl65: Don't know what to do with `1536'

 

Then I tried with these 2 lines, no error but no file generated:

 

cl65 -O -t atari test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN -S1536

cl65 -O -t atari -S1536 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN

 

 

 

Link to comment
Share on other sites

10 hours ago, sanny said:

Use "--start-addr" with cl65, like

Yeah, thanks, this parameter is great!

 

cl65 -O -t atari --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN

 

Got 4 blocks,

 

<2E00-2ef4> cc65 bootstrap
<02E2-02e3> init address
<0600-0838> my code under test
<02E0-02e1> run address

 

EDIT

 

After a few more analysis it's not great, because my code under test which should be at 1536 ($600) is at $661, there is some cc65 code in $600-$660... :(

 

 

 

TEST_OPCODES_CC65_1536.BIN test_opcodes.asm

Edited by pfeuh
Link to comment
Share on other sites

your posted program does not compile for me:


 

$ cl65 -O -t atari --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN
Unresolved external '_main' referenced in:
  runtime/callmain.s(27)
ld65: Error: 1 unresolved external(s) found - cannot create output file
$

 

You need to define an entry point into your program in order that the linker does not complain, e.g.

 

--- test_opcodes_cc65.org       2020-09-03 18:21:57.676657529 +0200
+++ test_opcodes_cc65.asm       2020-09-03 18:21:39.652362817 +0200
@@ -1,3 +1,6 @@
+.export start
+start:
+
 LABEL_01: BRK
     ORA ($A7,X) 
     ORA $6C

 

Then you can compile it:

 

$ cl65 -O -t atari --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN
ld65: Warning: /data/home/chris/classic/atari800/cc65-git/cc65/cfg/atari.cfg(62): Segment 'STARTUP' does not exist
$ ataricom TEST_OPCODES_CC65_1536.BIN 
ataricom 0.30-150320
(c) 2008-2014 Matthias Reichl <hias@horus.com>
block    1: 2e00-2ef5 (bytes:   246, offset:      6)
block    2: 02e2-02e3 (bytes:     2, offset:    256)
      INIT: 2e47
block    3: 0600-0740 (bytes:   321, offset:    262)
block    4: 02e0-02e1 (bytes:     2, offset:    587)
       RUN: 0600
$ 

 

Or use the atari-asm.cfg linker config file:

 

$ cl65 -O -t atari -C atari-asm.cfg --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.BIN
$ ataricom TEST_OPCODES_CC65_1536.BIN 
ataricom 0.30-150320
(c) 2008-2014 Matthias Reichl <hias@horus.com>
block    1: 0600-0740 (bytes:   321, offset:      6)
block    2: 02e0-02e1 (bytes:     2, offset:    331)
       RUN: 0600
$ 

 

Link to comment
Share on other sites

Yes, it's a COM file but with a (bad) BIN extension. Now it's called a XEX. Thanks, I'm going to correct that.

 

@sanny, first of all, I've done a mistake with the source file... :(   I put now in attachment the right one. Really sorry for that. It compiles with the following line but as I said, There is cc65 stuff at $600. Version is cl65 V2.16 - Ubuntu 2.16-2. By the way, the XEX file is created, but no comment or information is ouputed on the console.

 

cl65 -O -t atari --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.XEX

 

Even with the line you suggested, the result is the same, cc65 stuff at $600 and code under test at the back.

 

cl65 -O -t atari -C atari-asm.cfg --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.XEX

Unresolved external `__CONSTRUCTOR_COUNT__' referenced in:
  runtime/condes.s(30)
Unresolved external `__CONSTRUCTOR_TABLE__' referenced in:
  runtime/condes.s(32)
  runtime/condes.s(33)
Unresolved external `__DESTRUCTOR_COUNT__' referenced in:
  runtime/condes.s(47)
Unresolved external `__DESTRUCTOR_TABLE__' referenced in:
  runtime/condes.s(49)
  runtime/condes.s(50)
Unresolved external `__RESERVED_MEMORY__' referenced in:
  atari/crt0.s(74)
  atari/crt0.s(78)
ld65: Error: 5 unresolved external(s) found - cannot create output file

 

I'm sure I missed something huge...

 

 

 

 

 

 

 

test_opcodes_cc65.asm TEST_OPCODES_CC65_1536.XEX

Link to comment
Share on other sites

  • cc65 version 2.16 is quite old. I suggest that you download and compile the latest version from git (https://github.com/cc65/cc65 )
    Just check the source code out and type "make"
  • With the errors you posted, no binary would be created. At which bin file did you look at?
  • Don't export a "_main" label in your code, but a "start" label. "_main" would draw in C startup code.

 

regards,
chris

Link to comment
Share on other sites

At which bin file did you look at?

I was looking at TEST_OPCODES_CC65_1536.XEX with the command

cl65 -O -t atari --start-addr 0x600 test_opcodes_cc65.asm -o TEST_OPCODES_CC65_1536.XEX

 

version 2.18: from github done.

export "start" instead of "_main" done.

 

And it works as expected, code under test is at $600 ($00 $01 $A7...), Thank you Sanny! There is still something unusual for an asm file, it is the bloc located at $2e00, but I can live with.

<2E00:2EF5>
2E00 60 50 72 6F 67 72 61 6D 20 77 6F 75 6C 64 20 6C `Program would l
2E10 6F 61 64 20 62 65 6C 6F 77 20 4D 45 4D 4C 4F 2E oad below MEMLO.
2E20 9B 43 6F 6E 73 69 64 65 72 20 75 73 69 6E 67 20 .Consider using
2E30 61 20 68 69 67 68 65 72 20 6C 6F 61 64 20 61 64 a higher load ad
2E40 64 72 65 73 73 2E 9B 38 AD E5 02 E9 00 8D F6 2E dress..8........
2E50 AD E6 02 E9 00 8D F7 2E AD F6 2E 38 E9 00 8D F6 ...........8....
2E60 2E AD F7 2E E9 08 8D F7 2E AD F6 2E C9 41 AD F7 .............A..
2E70 2E E9 07 90 31 AD E7 02 C9 00 AD E8 02 E9 06 90 ....1...........
2E80 24 A2 00 A9 01 9D 44 03 A9 2E 9D 45 03 A9 46 9D $.....D....E..F.
2E90 48 03 A9 00 9D 49 03 A9 0B 9D 42 03 20 56 E4 20 H....I....B. V.
2EA0 E0 2E 4C DA 2E 60 4C BC 2E 4E 6F 74 20 65 6E 6F ..L..`L..Not eno
2EB0 75 67 68 20 6D 65 6D 6F 72 79 2E 9B A2 00 A9 A9 ugh memory......
2EC0 9D 44 03 A9 2E 9D 45 03 A9 13 9D 48 03 A9 00 9D .D....E....H....
2ED0 49 03 A9 0B 9D 42 03 20 56 E4 20 E0 2E 6C 0A 00 I....B. V. ..l..
2EE0 A9 0A 20 EB 2E 18 E9 00 D0 F8 60 A2 00 A0 00 88 .. .......`.....
2EF0 D0 FD CA D0 FA 60                               .....`
<02E2:02E3>
02E2 47 2E                                           G.
<0600:0740>
0600 00 01 A7 05 6C 06 C1 08 09 F5 0A 0D A6 87 0E 7E ....l..........~
0610 46 10 FE 11 52 15 07 16 4D 18 19 7E E9 1D F5 50 F...R...M..~...P
0620 1E 1E 24 20 DA B1 21 96 24 D0 25 D1 26 D8 28 29 ..$ ..!.$.%.&.()
0630 79 2A 2C 10 BC 2D CD 97 2E 78 16 30 FE 31 66 35 y*,..-...x.0.1f5
0640 72 36 FB 38 39 BA 9F 1D AB 64 1E 20 5D 40 41 28 r6.89....d. ]@A(
0650 45 D7 46 15 48 49 A5 4A 4C FE F3 4D 71 65 4E 6C E.F.HI.JL..MqeNl
0660 28 50 FE 51 B2 55 0C 56 A4 58 59 B7 2B 5D 9D CD (P.Q.U.V.XY.+]..
0670 5E B3 40 60 61 5E 65 59 66 A2 68 69 48 6A 6C 20 ^.@`a^eYf.hiHjl
0680 E1 6D 34 53 6E 76 3D B0 FE 71 DD 75 73 76 A3 78 .m4Snv=..q.usv.x
0690 79 01 40 7D 68 61 7E E3 50 81 07 84 C1 85 3C 86 y.@}ha~.P.....<.
06A0 82 88 8A 8C A1 D1 8D D2 7D 8E E3 51 90 FE 91 3B ........}..Q...;
06B0 94 03 95 21 96 0E 98 99 FF A2 9A 9D FB 0A A0 06 ...!............
06C0 A1 0A A2 C6 A4 C8 A5 90 A6 CE A8 A9 33 AA AC 3D ............3..=
06D0 DD AD 98 CD AE 1D E5 B0 FE B1 F3 B4 E0 B5 F7 B6 ................
06E0 F1 B8 B9 AA CE BA BC E1 6E BD 5C 09 BE EB 98 C0 ........n.\.....
06F0 DE C1 45 C4 71 C5 E3 C6 B5 C8 C9 74 CA CC 77 0E ..E.q......t..w.
0700 CD FF C1 CE DD 12 D0 FE D1 CA D5 41 D6 81 D8 D9 ...........A....
0710 63 70 DD 9A 99 DE D2 55 E0 E5 E1 FD E4 C9 E5 70 cp.....U.......p
0720 E6 83 E8 E9 C8 EA EC F5 2E ED CE 56 EE 16 CF F0 ...........V....
0730 FE F1 6E F5 DD F6 B7 F8 F9 29 84 FD E1 2B FE 23 ..n......)...+.#
0740 B0                                              .
<02E0:02E1>
02E0 00 06

                                           ..

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...