Mike Kohn's naken_asm

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Brad R
Posts: 93
Joined: 07 Jan 2014
Contact:

Mike Kohn's naken_asm

Post by Brad R »

Does anyone here have any experience with Mike Kohn's naken_asm cross-assembler? http://www.mikekohn.net/micro/naken_asm.php

I ask here because he indicates that support for the 65xx is "stable." I'm interested in some of the other processors as well. I like that it's available for Windows, Mac, and Linux.
Because there are never enough Forth implementations: http://www.camelforth.com
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Mike Kohn's naken_asm

Post by BigEd »

I just gave it a spin: it has a simulator as part of the package, which will of course help with debugging.

The 6502 test code supplied is actually rejected (It uses $ for hex, but must use 0x) and yet as the code is evidently actively being developed, and the source is available, I feel quite positive.

Perhaps I'll try to run Klaus' testsuite on it...

On windows in a cygwin terminal it looks like this:

Code: Select all

Simulation Register Dump                               Stack
------------------------------------------------------------
        7 6 5 4 3 2 1 0                          0x141: 0x00
Status: N V - B D I Z C                          0x140: 0x00
        0 0 0 0 0 0 1 0                          0x13f: 0x08
                                                 0x13e: 0x3a
  A=0x01   X=0x00   Y=0x00                       0x13d: 0x08
 SR=0x02  SP=0x41  PC=0x0001                     0x13c: 0x9c


6435 clock cycles have passed since last reset.

 ! 0x083b: rts                                      6-6
   0x083c: lda #0x20                                2-2
   0x083e: 0x00a2
   0x083f: brk                                      7-7
   0x0840: sta 0x0400,x                             5-5
   0x0843: 0x009d
   0x0845: 0x0005
Stopped.  PC=0x0001.
6442 clock cycles have passed since last reset.
stopped> run
Running... Press Ctl-C to break.
Stopped.  PC=0x0001.
6449 clock cycles have passed since last reset.
Cheers
Ed
Tor
Posts: 597
Joined: 10 Apr 2011
Location: Norway/Japan

Re: Mike Kohn's naken_asm

Post by Tor »

I also tested it yesterday - had to change that $ as well. It looks interesting. The 'speed' setting doesn't seem to change anything, but the 6502 simulator is marked beta. Had a quick look at the source to see how the setup for adding multiple architectures was done. It's encouraging that the 6502 part was implemented by someone who is not the original author (the only part so far, but still.)
So yes, interesting. Will dive deeper later, definitely. I tested with Debian Linux, 32-bit (my very old pentium-M laptop which I bring on travels).

-Tor
P.S. Brad, thanks for the link. I was not aware of the existence of this assembler.
mikeakohn
Posts: 3
Joined: 23 Feb 2014

Re: Mike Kohn's naken_asm

Post by mikeakohn »

Just out of curiosity, what's wrong with the original author here?
mikeakohn
Posts: 3
Joined: 23 Feb 2014

Re: Mike Kohn's naken_asm

Post by mikeakohn »

The $ was working at one point, but I ended up breaking it recently. I fixed the issue and just posted a 2014-02-22 version. If you guys find any more bugs or have any requests let me (or Joe) know.
joe7
Posts: 78
Joined: 23 Feb 2014

Re: Mike Kohn's naken_asm

Post by joe7 »

Thought I would take a minute to explain the assembler a bit. It does use a more modern syntax:

- low high bytes are accessed C-style, using "& 0xff" and ">> 8" (not the old > < way)
- there are no local +, ++, +++ or -, --, --- labels
- data is done like "db 0, 1, 2" or "dw 0xc000, 0xc001, 0xc002" etc. (data-byte and data-word)
- generally, data is decimal (0), hex (0x00), binary (00000000b)
- text can be done with db "Hello World"
- there is a limitation where accessing Zero Page at location 0 is always done in absolute mode

The code on this page may clear some things up, uses macros, expressions, and some tables:
http://joe.csoft.net/c64demo.html
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Mike Kohn's naken_asm

Post by BigEd »

Hi Mike, good to see you here... also Joe!
Thanks for fixing the $.
(I suspect Tor's point was that it's encouraging to see software with more than one contributor - it's a measure of health of a project.)
Tor
Posts: 597
Joined: 10 Apr 2011
Location: Norway/Japan

Post by Tor »

mikeakohn wrote:
Just out of curiosity, what's wrong with the original author here?
Nothing wrong at all - quite the opposite! What I meant was that the fact that somebody else was able to extend and add a new architecture to the assembler indicates that your software is actually understandable by others - and that's definitely not always the case for a lot of software out there. I've seen tons of code (including assemblers) where in practice only the original author is able to do substantial work on the code because nobody else can understand it without investing a lot of effort, or sometimes it's understandable but not easy to expand on.

In short, even though I only looked briefly at parts of the code, the fact that somebody else (the 6502 author) could contribute tells me, as a programmer, that your code is the type of code I like to see.

-Tor
mikeakohn
Posts: 3
Joined: 23 Feb 2014

Re: Mike Kohn's naken_asm

Post by mikeakohn »

Ah, I wasn't sure if that was supposed to be positive or negative so I just thought I'd ask. Thanks for the compliment then :).

As far as the health of this project, along with a naken_asm side project called Java Grinder (which Joe is doing the 65xx work on also), naken_asm is my highest priority. As I said before, if you guys find any issues or have any useful suggestions just let me know.

Btw, glad to see interest in the assembler. Thanks!
Brad R
Posts: 93
Joined: 07 Jan 2014
Contact:

Re: Mike Kohn's naken_asm

Post by Brad R »

Good to see Mike and Joe here. I've had a very productive email exchange with Mike as I've been trying out the MSP430 assembler, to see if it will assemble my MSP430 Forth. naken_asm seems to have just about the right feature set for that job, and supports most of the MCUs I'm interested in.

I've had a couple of glances at the source code, and it looks fairly straightforward to extend.
Because there are never enough Forth implementations: http://www.camelforth.com
joe7
Posts: 78
Joined: 23 Feb 2014

Re: Mike Kohn's naken_asm

Post by joe7 »

Just changed the assembler a bit to always use absolute mode in regular indexed modes:
https://github.com/mikeakohn/naken_asm

Did this after finding out that indexing in zp wraps around, breaking something I was trying to do. I knew the indirect ones wrapped.
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: Mike Kohn's naken_asm

Post by barrym95838 »

Am I the only one thinking that removing zp,x and zp,y from a 6502 assembler is rather harsh? We're talking about bread with no butter here ...

How hard would it be to add an assembler directive or operand pre-fix override?

I'm asking the second question because I genuinely don't know the answer, but I think that I already have a guess for the answer to my first question.

Mike
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Mike Kohn's naken_asm

Post by BigDumbDinosaur »

barrym95838 wrote:
Am I the only one thinking that removing zp,x and zp,y from a 6502 assembler is rather harsh? We're talking about bread with no butter here ...
I'd have to agree with you on that one. I can think of a whole lot of code that would be busted if those addressing modes were eliminated. I would not use any assembler that can't properly support the full instruction set of the target processor and/or uses kinky non-standard syntax. What's wrong with sticking with standards that have existed for decades? <Rhetorical question>
x86?  We ain't got no x86.  We don't NEED no stinking x86!
clockpulse
Posts: 87
Joined: 20 Oct 2012
Location: San Diego

Re: Mike Kohn's naken_asm

Post by clockpulse »

I agree also. Zero page is a very special place.
User avatar
BitWise
In Memoriam
Posts: 996
Joined: 02 Mar 2004
Location: Berkshire, UK
Contact:

Re: Mike Kohn's naken_asm

Post by BitWise »

The WDC assembler (and mine) uses an address prefix character to force a particular mode. So |addr or !addr forces an absolute mode, <addr is always zero page and >addr is the 65816 long absolute. You can add the index suffixes after the address as usual (e.g |addr,X).

Very useful when you want to force a particular mode or if the assember can't work out the mode because the value is imported from a different relocatable module.
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs
Post Reply