Table lookups (HC08)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Table lookups (HC08)

4,982 Views
Bloodhound
Contributor I
Hi All,
 
I am a little stuck on perhaps the correct syntax to do a simple table lookup (see code below).
Ignoring any additional instructions that would increment the Table pointer, what I have found is if I use the code below, the values from the Table are not getting stored in to T1MODH, instead the address location value of Table is being stored.
What is the correct syntax to use so I can point to a table location and get the value from the table to store in to T1MODH.
I also tried using -
ldhx  Table
Figuring that that is not an immediate load, but, the compiler complains I can't use that addressing mode for that command.
 
Thanks,
Ross
 
ldhx  #Table             
sthx  T1MODH 
 
Table:
 fdb   2000
 fdb   3000
 fdb   4000
Labels (1)
0 Kudos
Reply
12 Replies

2,527 Views
mke_et
Contributor IV
I use tables in my code for a POCSAG encoder. Here's a real short example from my code:

ldhx #instrings ; Get location of start
find_end_instr
lda 0,x ; byte of text message
beq put_eom ; If a zero, put an EOM
incx ; Point to next

and then loop around to do what needs to me done when processing a text message that was received to a buffer in RAM. I point HX to the ADDRESS of the table. Be aware that X is 256byte wraparound if you use it the way I use it!

Also, one thing I discovered... Be careful about interupts. What happens to 'H'? That caught me off-guard for a while!

Message Edited by mke_et on 2007-09-21 08:36 AM
0 Kudos
Reply

2,527 Views
Alban
Senior Contributor II
Hi Mike,

The H is indeed to be pushed/pulled manually.
This is for code to be backwards-compatible to HC05.

CodeWarrior is always adding a the PUSH and PULL when compiling. Unless told otherwise.

Cheers,
Alban.

0 Kudos
Reply

2,527 Views
mke_et
Contributor IV
I got bit on the H issue with my POCSAG code. I used HX as an index and sometimes would pull stuff out of FLASH with it and sometimes out of RAM. I got bit when I used some of my 'generic' routines from an ISR and H wasn't left pointing in foreground where I thought it was. I thought it was something stupid I did (it was) so I just 'initialed' H whenever I needed to use it. It mostly fixed things. Then I realized it was the ISR that was clobbering H. One of those things that when you find it you feel good about yourself at first, then realize how stupid you were once you think about it for a while...
0 Kudos
Reply

2,527 Views
bigmac
Specialist III
Hello Mike,
 
Prior to using any indexed addressing, I think it is a good idea to always initialize the H register, and not assume any previous value.
 
Of course there would still be problems if an ISR is corrupting the H-value, assuming the interrupt can occur immediately prior to any indexed instruction.  As you have found the hard way, this type of problem can be particularly difficult to diagnose as it may occur only infrequently.
 
BTW, I first implemented a POCSAG encoder within some HC05 devices, about 15 years ago.
 
Regards,
Mac
 
0 Kudos
Reply

2,527 Views
Bloodhound
Contributor I
Thanks for the answers.
From what I can see I don't think I am doing anything wrong yet I am getting the error.
 
As was mentioned, if I have -
   ldhx  #Table
Then hx is loaded with the address of the table, not what I want.
 
If I change this command to -
        ldhx  Table
The error I am seeing in CodeWarrior says -
 
"Error A13001: Invalid Addressing Mode. not allowed for LDHX"
 
I get the very same error if I use the line of code that 'Encoder' posted up -
 
ldhx table,x     ; table+pointer -> H:X
 
However, the other code you posted works fine with no compile error -
 
clrh            ; assures h=0
ldx #pointer    ; pointer is an 8 bit offset
lda table,x
sta T1MODH
lda table+1,x
sta T1MODH+1
 
Thanks,
Ross
 
 
 


Message Edited by Bloodhound on 2007-09-21 08:56 AM
0 Kudos
Reply

2,527 Views
bigmac
Specialist III
Hello Ross,
 
The reason for the assembly error is that Table would be located at an extended address (within flash).  For the HC08, the LDHX instruction does not have an extended addressing mode.  In contrast, the LDHX Table instruction would work for a HCS08 device since this has additional addressing modes.
 
A further approach using zero offset indexing, which I think is what you were originally aiming for.  This would work for either type of device -
 
  ldhx #Table
  lda  ,x
  sta  T1MODH
  aix  #1      ; Increment H:X
  lda  ,x
  sta  T1MODL
 
For the HCS08 only, the following should also work -
 
  ldhx  #Table
  ldhx  ,x
  sthx  T1MOD
 
Regards,
Mac
 


Message Edited by bigmac on 2007-09-21 11:40 AM
0 Kudos
Reply

2,527 Views
Bloodhound
Contributor I
Thanks Mac, that certainly makes sense.
Thanks to everyone who responded, very helpful board this one (and kind to HC08 newbies!)
I remember looking at the HCS devices but there was none with a CAN controller :smileysad:
 
Cheers,
Ross
 


Message Edited by Bloodhound on 2007-09-21 11:50 AM

Message Edited by Bloodhound on 2007-09-21 11:53 AM
0 Kudos
Reply

2,527 Views
bigmac
Specialist III
Hello Ross,
 
Both the 9S08DVxx series and the 9S08DZxx series include a CAN module.  These are relatively new devices, so I am not sure whether currently available.
 
Regards,
Mac
 
0 Kudos
Reply

2,527 Views
PeterHouse
Contributor I
Just to clarify a litte:

The # prefix indicates an immediate load and will result in the address of Table into the a or hx registers.


    ; Load Address of Table
    lda    #Table
    ldhx   #Table

    ; Load contents of memory location(s) pointed to by Table
    lda    Table
    ldhx   Table

    ; Immediate Hex value into a or hx
    lda    #$0F
    ldhx   #$7FEC


Peter House
0 Kudos
Reply

2,527 Views
Encoder
Contributor I
Hallo.
That's right: your code dumps the double byte address of "Table" to T1MODH/T1MODL, which isn't surely what you want.
Assumed that you want to dump a double byte, there are many ways to do that. A possible code may be:
 
; limited to 8 bit offset but very powerful because the
; offset pointer may be a constant (#pointer) or a variable
; (pointer) and is not lost in the x register after load
; i.e. it may be further incremented or processed here
clrh            ; assures h=0
ldx #pointer    ; pointer is an 8 bit offset
lda table,x
sta T1MODH
lda table+1,x
sta T1MODH+1
 
or
 
; with 16 bit offset.
; apparently smaller code, but #pointer is mainly
; a constant and is not easy to process in the program.
; If you want to use a 16bit variable you must process it
; elsewhere in ram and load it from there.
; The pointer is lost in H:X register and replaced by the
; table value
ldhx #pointer    ; pointer is a 16 bit offset
ldhx table,x     ; table+pointer -> H:X
sthx T1MODH      ; H:X -> T1MODH:T1MODL
 
I hope it is what you want.
Encoder
 
P.s.: Take care that default numeric declaration in CodeWarrior is decimal, so
 
fdb 2000    ; decimal
 
is not exactly
 
fdb $2000   ; hex
 


Message Edited by Encoder on 2007-09-20 07:45 PM
0 Kudos
Reply

2,527 Views
Navidad
Contributor III
Can you give the exact error message ? ldhx Table is the correct version but there is no reason why you should get an error. If you are usign an HC08 (not an HCS08) you might get a warning if Table is not located in the direct page.
0 Kudos
Reply

2,527 Views
sekhar
Contributor I
Hello,

Sorry for coming in the middle. I am having a problem regarding Flash in case of MC68HC908EY16. After some sucessful Erase & Program conditions, at one state the flash getting completely corrupted. No operation is been able to perform. can u tell me reasons for this type of problems.

Thanks & Regarding
Sekhar
0 Kudos
Reply