Quick question (6809 assembly)

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Quick question (6809 assembly)

Post by Rink »

Apologies for asking this - it feels a little bit like I'm cluttering up the board - but being more of a Z80 man, I'm having a bit of a problem working out how to do this.

On the 6809, what's the easiest way to compare the low 8 bits of the x register (i.e. the address itself, not the contents of memory that it points to)? Basically, if the address in x ends in 0xF then I want to add on a value before my loop continues. Can't see a suitable instruction (but have probably missed it) and the only other thing I can think of is pushing x to the stack and then accessing the memory using the SP, but this seems incredibly wasteful.

Cheers.

R
sixxie
Posts: 1346
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Quick question (6809 assembly)

Post by sixxie »

As an index register, X lacks the bitwise and arithmetic operations of A and B, so you need to transfer the value into one of those. The legal way to do that is TFR X,D - A will contain the top 8 bits, B the bottom 8 bits (as D is the combination of the two).

An illegal way to do it without invalidating A is TFR X,B. 16 bit into 8 bit is technically illegal, but this will work on 6809s and 6309s (maybe not some emulations/reimplementations). Assemblers might chuck that out, so you can just embed the code directly: FCB $1F,$19

The other option - TFR X,A - will work on a 6809, but not a 6309 (you'd end up with the upper 8 bits of X that way).

Obviously you burn at least one register either way - but you'd do that anyway even storing to memory, as you'd still have to pull it into an accumulator afterwards to do the masking and testing...
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Re: Quick question (6809 assembly)

Post by Rink »

Brilliant, thanks Sixxie.

That's what I was looking for - I didn't realise D was a register pair so didn't think to check whether TFR X,D was a valid instruction. I can live with trashing A, that's not a problem.

R
Post Reply