[Coco] Errors in Leventhal's 6809 Subroutines book?

Joel Rees joel.rees at gmail.com
Sat Jan 29 13:24:19 EST 2022


On Sat, Jan 29, 2022 at 12:49 PM Robert Gault <robert.gault at att.net> wrote:
>
> The instruction mentioned was leax -1,s
> that should give an error although I have not yet tried it.

Not sure why you're thinking it should give an error, but I can guess
that you have only had LEA explained as how the 6809 does increments
and decrements. LEA does far more than that.

Study the index mode post-byte for the variety of address math the
6809 can do in a single instruction. Then consider that you have LEAX,
LEAY, LEAS, and LEAU, and all four simply take the index post-byte as
their operand. Thus, if you have a calculated offset in D, to an
element in, say, an array passed on the parameter stack pointed to by
U, and you want the address of that element in Y:

  LEAY D,U ; (How we got the offset in D is a good question, but ...)

Or if you have a table of constants in the object code and want to get
a pointer to the table, you can use even use LEA with PC relative
indexing:

MONTHDAYS FCB 31,28,31,30,31,30,31,31,30,31,30,31
* get number of days up to month
GDAYSTOMO
  LDD ,U++ ; get month number from parameter stack
  BEQ GD2MERR
  CMPD #12
  BHI GD2MERR
  LEAX MONTHDAYS,PCR ; *** point to table ***
  CLR A ; A is actually already known zero, but don't surprise the reader.
* don't want to add the final month, decrement first
GD2MLOOP
  DEC B
  BEQ GD2MFIN
  ADDA ,X+
  BRA GD2MLOOP
GD2MFIN
  TFR A,B
  CLR A
  BRA GD2MEXIT
GD2MERR
  LDD #0
GD2MEXIT
  PSHU D
  RET


> Sent from AT&T Yahoo Mail on Android
>
>   On Fri, Jan 28, 2022 at 10:34 PM, Joel Rees<joel.rees at gmail.com> wrote:   2022年1月29日(土) 11:23 Robert Gault <robert.gault at att.net> said:
>
> > A Google search did not find corrections for the book. However, the second
> > error would have been quickly found if EDTASM had been used to compile the
> > code. It would have been reported as an error.
> >
>
> Are you sure?
>
>   LEAX -1,X
>
> is valid syntax for a valid op-code.
>
> Sent from AT&T Yahoo Mail on Android
> >
> >  On Fri, Jan 28, 2022 at 8:50 PM, Don Barber<don at dgb3.net> wrote:  Hi
> > folks, I've been teaching myself 6809 assembly, and quickly ran
> > across Leventhal's books which have been invaluable. I have the
> > programming book, but have also been referencing the subroutine book
> > from online copies available at:
> >
> >
> > https://colorcomputerarchive.com/repo/Documents/Books/6809%20Assembly%20Language%20Subroutines%20(Lance%20Leventhal).pdf
> >
> > and
> >
> >
> > https://archive.org/details/assembly-language-subroutines-for-the-6809_Leventhal
> >
> > Both appear identical.
> >
> > However, I've already run across two bugs:
> >
> > One is on page 72, in MPBMUL, where a BNE is executed right after a
> > "LEAU -1,U". However, the LEAU does NOT set the Z flag, so the BNE is
> > actually working off either the preceding INCA or the STA instructions
> > (depending upon the STA's Carry result). One can test this does not work
> > by trying to multiply 0x0001 times 0x08a6; the result will be an
> > incorrect 0x00a6. One has to add a 'CMPU #0' after the LEAU statement to
> > get the correct behavior.
> >
> > The other is on page 78 in MPBDIV, where one will find a "LEAX -1,S"
> > that should instead be "LEAX -1,X" as the X register is being used as a
> > decrement counter. The original text will result in an infinite loop as
> > the S register is not modified in this loop.
> >
> > So my question is: is there an errata somewhere where known bugs are
> > listed? I imagine people ran across these back in the day too. Both of
> > these got me stuck for an hour or three each, though in hindsight they
> > should have been obvious.
> >
> >
> > Thanks,
> >
> > Don
> >
> >
> >
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > https://pairlist5.pair.net/mailman/listinfo/coco
> >
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > https://pairlist5.pair.net/mailman/listinfo/coco
> >
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco



-- 
Joel Rees

http://reiisi.blogspot.jp/p/novels-i-am-writing.html


More information about the Coco mailing list