6809 assembly language - LEA instruction.

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

6809 assembly language - LEA instruction.

Post by cobaka »

Morning all!

Not sure whether I should post this here (Programming) or on the "completely off-topic" board.

Here goes: Anyone here familiar with MC6809 assembly language - specifically the LEA ('load effective') address instruction?
I'm uncertain about the nature of the calculation invoked by this instruction.

собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: 6809 assembly language - LEA instruction.

Post by williams2 »

Anyone here familiar with MC6809 assembly language

Maybe. What do you want, in particular?

LEA (Leave Effective Address) allows you to do 16 bit add/subtract despite the fact that the 6809 is basically an 8 bit cpu.

You can get a small book here that seems to have most of the information needed to write code for the 6809.
https://archive.org/download/bitsavers_ ... da_3224333

If I find something I like at archive.org, I bookmark the web page of the uploader (usually near the bottom of the previous page, near the showe all link. If you click on the uploader's archive.org page, you can see what else the uploader uploaded. And if they include their favorites, the other uploaders in the favorites list often have similar items listed that they uploaded.

It's better to use the x address register than the Y register. Instructions that use the Y register are 1 byte longer than the X register instructions, and slower too.

Tjis will load the accumulator with the value in the ram location pointed to by the number in the X register:

LDA (X)

This will load A with the contents of the byte at the address of ram that is the number in PCR plus 500. If PCR is 1000 then this instruction loads (copies) the number in the byte at ram address 1500. The number in PCR is unchanged (Well. the PCR Program Counter Register is incrementing constantly, that is, the cpu chip is running, executing the instructions 1 by 1.) The beauty of this, is you can write position independent code, move it anywhere and it will still work. You can't do that with a Z80 or an 8080 or a 6502, not easily)

LDA (500,PCR)

This does the same thing, but puts the value of 500 plus what ever is in X in Y. The number in X is not changed.

LEAY 500,X

Do you have a specific question? Are you programming a 6809 microprocessor circuit board? Or maybe you have a very old Radio Shack computer? or you have a 6809 emulator?

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: 6809 assembly language - LEA instruction.

Post by cobaka »

Hello @williams2
You asked:

Do you have a specific question? Are you programming a 6809 microprocessor circuit board? Or maybe you have a very old Radio Shack computer? or you have a 6809 emulator?

Yes, I have an assembler and working emulator for the 6809 - from L. Benschop/GitHub.
I'm a beginner there. These two run on my Linux box under the Puppy OS. I also have the parts for a SBC. More about that below.

To date I haven't used the assembler/simulator extensively; you can understand that from my ignorance of the LEAX instruction. That was the specific instruction that I didn't understand. I spent about 4 hours reading various explanations (and code) about LEAX etc; I got an satisfying answer an hour or so after I posted here. This is what I found:

6809_LEAx_instruction.jpg
6809_LEAx_instruction.jpg (57.61 KiB) Viewed 1300 times

My interest in the small 8-bit processors came (in part) from trying to understand the path from the early 'monsters' like ENIAC/ILLIAC (etc) to the early uPs of the 70s. ENIAC (or maybe ILLIAC) had about 18,000 'tubes'. The 6502/6800 has about 4000 transistors. The 8080: 6500. 6809 about 9000. The fellows who designed the early machines were clever beyond imagination, but I dare to think the architecture of even the simple 8080 processor can solve the same class of problem that the 100kW early monsters could solve. Why did it take 25 years for a whole industry to arrive at the simpler architecture seen in the 8-bit uP?

I think, in part, the answer is found in memory and IO. Those two items are as significant as the CPU, it seems. A mercury delay line is a cumbersome form of memory. Paper tapes running at 30mph are difficult to manage. It's an interesting topic. I have a single-board (as-yet unbuilt) 6809uP. 32k RAM, 16k ROM. This elegant 8-bit CPU fascinates me. Simple serial IO. An ancient, but very interesting toy from times past. I want to see what this little bit of silicon can do. How will I adjust to text only I-O? How much will I miss a GUI?

My specific question was about the LEAX/LEAY instruction. Mostly, I have an answer. I learned most of my programming reading 8080 code written by Philip Levy and Stepen Dompier. If I can find comparable code for the 6809 I'll study that with great interest. If I can write code that has few errors (these two wrote remarkably bug-free programs) I'll be pleased.

I'm interested in the language created by this fellow Charles Moore. Forth. People who program in C (etc) laugh at Forth but Moore controlled serious hardware using this simple language. On You-Tube I saw a demonstration of Forth used for string manipulation.
https://www.youtube.com/watch?v=mvrE2ZGe-rs
String handling is quite different from controlling a 100-ton telescope. I think writing a program to emulate grep or sed, in Forth, would be an interesting exercise. I suspect the finished code might be only 5 or 10k-bytes. I think it can be done. I'm curious.

Again, tnx for your reply.

Собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 288 times

Re: 6809 assembly language - LEA instruction.

Post by williams2 »

The 6809 is an 8 bit microprocessor,

LEA lets you do 16 bit add/subtract arithmetic using the 6809 Effective Address instructions.

LDA #$5F puts the hex number 5F in the accumulator, A

LDA $5F copies the number that is in the 16 bit ram address $005F, to A.

LDA ($5F) copies to A the number in ram at the address that is in the address $005F

LDA (7,$5F) same as above, but adds 7 to the address. But which address is the 7 added to? You need to read the manual. But the manual is sometimes wrong.

LEA allows you to get at the effective addresses that the 6809 calculates, for your own purposes, and allows the 6809 to do some 16 bit arithmetic.

LEAX 1,X this just increments the number in the X register, and I think sets the flags. I don't remember if there is an INCX instruction. The again, INCX might not affect the flags.

In the Z80 chip, you can decrement the BC 16 bit register, but it doesn't set the flags, so you end up doing something like this:

Code: Select all

PUSH A
LD B
XOR C  ; it's either AND or OR or XOR
POP A

If you don't care about A you do not need the PUSH POP.

The 6809 is much nicer to program than the Z80, 8080, 6800, 6502

LEA allows you to get at the 16 bit effective addresses that the 6809 calculates

You might be interested in FreeForth http://christophe.lavarenne.free.fr/ff/
Very small and a bit different.

gforth is a mainstream Linux forth.

Levanthal wrote books for learning the 6809 and the Z80.
The 6809 Cookbook is not a bad book.

There are books to learn 6809 programming on the Radio Shack computers, for example, the CoCo Color Computers.

even the simple 8080 processor can solve the same class of problem that the 100kW early monsters could solve

I remember writing a program in Basic b20 on a Dec PDP 10 to print pythagorean integer triplets.I left it running all night, detached from a terminal. It took about 3 or 4 hours.

I wrote the same program in FreeForth, the program takes a fraction of a second to run,

Code: Select all

\ Pythagorean Triplets (FreeForth)

."^JPythagorean_Triplets_a\^2_+_b\^2_=_c\^2_;_a,b,c_<_256^J^J"

variable a
variable a2
variable b
variable b2
variable ab2
+longconds

: tab 9 emit ;

: pythag
  256 TIMES 255 r - dup a ! dup * a2 !
    r TIMES 255 r - dup b ! dup * b2 ! a2 @ b2 @ + ab2 !
      r TIMES ab2 @ 255 r - dup * =
        drop drop
        IF a @ . tab b @ . tab 255 r - . cr BREAK
      REPEAT
    REPEAT
  REPEAT ;

pythag bye ;

I wrote 4 or 5 programs, this is the slowest, but the code is clearer.

I assume you know about http://rosettacode.org/wiki/Rosetta_Code

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: 6809 assembly language - LEA instruction.

Post by cobaka »

@williams2 I started a new topic: Free Forth & Reverse Polish Languages: https://www.forum.puppylinux.com/search ... =egosearch

You:

But the manual is sometimes wrong.

Oh yes! Especially if the uP is a PIC chip dealing with arithmetic instructionс.

The CP/M assembler had a nasty problem too.
In assembly source code, if you declared a label with the same name as an opcode it would assign the opcode value to the label. Took me about a day to understand that the problem lay in the assembler, not my source.
Interestingly the assembler did not give an expected 'duplicate label' warning. The moral: When using CP/M's ASM, do not use "PUSH" or "POP" as a function label. (Lots & lots of people out there still using CP/M, I'm sure!!)

ASM was 'slowwwww'. I used an operating system/assembler from Processor Technology, PTDOS.
It would assemble 160k of source in 20 seconds. ASM would do the same job in 4 1/2 minutes.

And (if I can say this) I never found an error in PTDOS code or documentation.
Amazing!

собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

Post Reply

Return to “Programming”