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
Solved! Go to Solution.
Hello norticum,
A couple of comments about Eckhard's sub-routine -
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
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
Hello norticum,
A couple of comments about Eckhard's sub-routine -
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
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
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