Accumulator Addressing

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Accumulator Addressing

Post by chysn »

Back when I was a kid, using available assemblers like HESMon, I learned that the accumulator addressing syntax was implied. So

Code: Select all

LDA #$80
LSR
Nowadays, when I look at the Commodore VIC-20 Programmer's Reference Guide, Lance Leventhal's books, and VIC Revealed, all these resources specify the Accumulator addressing mode explicitly, like this

Code: Select all

LDA #$80
LSR A
Okay, two ways to do the same thing. But I'm finding that some modern assemblers like xa and Acme complain when the Accumulator is explicit (the second syntax), while mass:werk's online assembler complains about the implicit syntax. Personally, I prefer the implicit syntax because that's what I used when I was a kid. But shouldn't assemblers treat both the same?

This is an issue for me now because I'm starting to put my 6502 code on Github, and I'd like to find some degree of portability.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Accumulator Addressing

Post by Mike »

Both syntaxes are found in the wild in sources.

The MOS documents specify explicit accumulator addressing. A lot of monitors of that time instead used implicit accumulator addressing as that can be implemented with less code. Today's tools either (again) leave out explicit accumulator addressing, or enable/disable this as command-line switch. The rationale being, that explicit accumulator addressing is essentially redundant, or are least a possible source of confusion: is "A" maybe a symbol, or even the address $0A in implicit hex notation? You cannot have both types in one source as that would introduce said ambiguity.

In practice, you will always have to infer from another persons source whether the used assembler wants implicit or explicit accumulator addressing. For own source, just choose the tool which suits you best.

My toolchain contains a monitor which outputs implicit accumulator addressing, and an assembler, which wants explicit accumulator addressing; so I am very much aware of that issue and still can live with it. :)
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: Accumulator Addressing

Post by funkheld »

Hi good afternoon.

The assembler instruction LSR shifts the eight bits of the accumulator one place to the right and not 2...3...4..

ok is :
LDA #$10
LSR



or 3 Bits:
LDA #$10
LSR
LDA #$10
LSR
LDA #$10
LSR

greeting
groepaz
Vic 20 Scientist
Posts: 1188
Joined: Wed Aug 25, 2010 5:30 pm

Re: Accumulator Addressing

Post by groepaz »

think again
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Accumulator Addressing

Post by chysn »

Mike wrote: Sun Jan 19, 2020 3:00 am My toolchain contains a monitor which outputs implicit accumulator addressing, and an assembler, which wants explicit accumulator addressing;
I'm sure your monitor is your own Minimon :) May I ask what your assembler is?
so I am very much aware of that issue and still can life with it. :)
Sure, in the human panoply of minor grievances and annoyances, this is hardly worth mentioning. In fact, the diversity of assemblers for the 6502 in the year 2020 is nice to see.
funkheld wrote: Mon Jan 20, 2020 9:15 am or 3 Bits:
LDA #$10
LSR
LDA #$10
LSR
LDA #$10
LSR
Be careful here. You're resetting your accumulator each time, so this won't do what you seem to expect.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4842
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Accumulator Addressing

Post by Mike »

chysn wrote:I'm sure your monitor is your own Minimon :)
Yes, this is MINIMON but I also still use TEDMON (the 264 variant, mainly when a program occupies address ranges overlaid by ROM or I/O on the VIC-20 and I want to relocate it).
May I ask what your assembler is?
I use the inline assembler of BBC BASIC. To be more specific, it's the one of HI BASIC which runs on the 2nd processor Tube.

One of the nicer things is, you have the full expression parser available to calculate addresses. :)

With the program MG BROWSE, I included source for the machine code part. There, you might take a look how 'typical' source for that assembler looks like (and you find prominent examples of explicit accumulator addressing with quite some 'ROL A' instructions in the TDraw routine).

Greetings,

Michael
Post Reply