Getting access to a string in asm

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

Getting access to a string in asm

Jump to solution
1,588 Views
mnemonic
Contributor III

Hello experts!

 

I want learn something about accessing a string. I found the application note AN1752. But I does not understand this exactly.

 

I done some coding on a LCD and displaysome chars by this way:

 

lcd_val:  DS.B 1 

 

write:

        lda #'H'

        sta lcd_val

        jsr write_char

        lda #'E'

        sta lcd_val

        jsr write_char

        lda #'L'

        sta ..........

        ...............

 

Now I want learn how to get access to 'HELLO' Array and store it to lcd_val:

 

MSG: DC.B 'HELLO'

 

 

Can anyone tell me how to do this?

 

best regards,

 

norticum

Labels (1)
0 Kudos
Reply
1 Solution
788 Views
bigmac
Specialist III

Hello norticum,

 

A couple of comments about Eckhard's sub-routine -

  1. The sub-routine assumes that the string data is terminated with a zero byte value.
  2. The sub-routine will work only if the value H:X remains unaltered by the write_char sub-routine. Perhaps check that this is so. If not, you might consider modifying write_char by saving the H:X entry value(s) to the stack, and restoring them on exit.
  3. The H-register must have a value of zero for the sub-routine to operate correctly. This might be explicitly initialised with ldhx #0 as the first instruction (in lieu of clrx).

For a more general sub-routine that is capable of sending many different strings to the LCD, consider entering the sub-routine with the H:X value already set to the start address of a particular string.

 

MSG1:

   dc.b  "Hello",0 

 

... 

 

   ldhx  #MSG1

   jsr   send_string

 

...

 

send_string:

   lda   ,x

   beq   end_str     ; Exit if end of string

   jsr   write_char

   aix   #1          ; Next string character

   bra   send_string ; Loop always

end_str:

   rts


Again, the write_char sub-routine must not alter the H:X value.

 

Regards,

Mac

 

Message Edited by bigmac on 2009-11-28 03:36 AM

View solution in original post

0 Kudos
Reply
4 Replies
788 Views
eckhard
Contributor V

Hello,

 

ist is done in a loop, using the X Register

 

 

 

                clrx
L1             lda       MSG,X          ;load AccA w/char from msg
                beq      OUTMSG       ;end of msg?
                jsr       write_char     ;write data to LCD
                incx
                bra     L1                  ;loop to finish msg
OUTMSG     rts

Eckhard

0 Kudos
Reply
789 Views
bigmac
Specialist III

Hello norticum,

 

A couple of comments about Eckhard's sub-routine -

  1. The sub-routine assumes that the string data is terminated with a zero byte value.
  2. The sub-routine will work only if the value H:X remains unaltered by the write_char sub-routine. Perhaps check that this is so. If not, you might consider modifying write_char by saving the H:X entry value(s) to the stack, and restoring them on exit.
  3. The H-register must have a value of zero for the sub-routine to operate correctly. This might be explicitly initialised with ldhx #0 as the first instruction (in lieu of clrx).

For a more general sub-routine that is capable of sending many different strings to the LCD, consider entering the sub-routine with the H:X value already set to the start address of a particular string.

 

MSG1:

   dc.b  "Hello",0 

 

... 

 

   ldhx  #MSG1

   jsr   send_string

 

...

 

send_string:

   lda   ,x

   beq   end_str     ; Exit if end of string

   jsr   write_char

   aix   #1          ; Next string character

   bra   send_string ; Loop always

end_str:

   rts


Again, the write_char sub-routine must not alter the H:X value.

 

Regards,

Mac

 

Message Edited by bigmac on 2009-11-28 03:36 AM
0 Kudos
Reply
788 Views
mnemonic
Contributor III

Hello Mac Hello Ego!

 

Thanks a lot! Both Listings are very interesting. I tried the code from Mac, it works fine!  

 

Can you please explain me "lda ,x" ?  I do not understand this line.

 

Regards,

 

norticum

 

0 Kudos
Reply
788 Views
bigmac
Specialist III

Hello norticum,


mnemonic wrote:

Can you please explain me "lda ,x" ?  I do not understand this line.



 

This instruction uses indexed addressing mode with no offset.  That is the accumulator is loaded with a byte value fetched from an address that is specified by the 16-bit value contained within the H:X register.  Another way of writing the instruction is lda 0,x.

 

Regards,

Mac

0 Kudos
Reply