H
H
Hogs_Of_War2015-08-03 19:42:15
Microcontrollers
Hogs_Of_War, 2015-08-03 19:42:15

How to work with strings in AVR Assembler?

Help me choose an instruction for reading from a flash using a pointer
Here is a piece of code that defines a string and its length

Message:	.db  	"Hello World!"            ;String which need to write
ldi len,12						   ;String length

And here is a piece of code for displaying a string on the LCD
loop:

ld byte, ;HELP

ldi temp,0x01		;RS-bit (0 - sending command, 1 - send data)
rcall send_byte		;Call procedure for send a symbol as 4-bit mode
delayClocks 100,1,1     ;some delay
dec len	                ;len is length of string
brne loop

What instruction can be used to read data from a flash? Are designs
mov bx,byte[i+1]
or similar possible but only for AVR microcontroller?
Z.Y. code for ATmega8A
UPD: Solved, thanks to comrade jcmvbkbc
By the way, I found an interesting moment when declaring a string with the .db directive, the real address of the string is 2 times greater than the address of the label
For example:
Here is a string defined before the procedure code. Label address - 0x0030 but in memory this line starts with 0x0060
Message: .db "Hello World!"
Tried to determine after the program code in the end the same thing. The label address was 0x0098 and the text itself started at 0x130. If anyone knows what is the reason for such an incomprehensible behavior for me, then please explain, and in general the problem is solved, thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2015-08-03
@Hogs_Of_War

What instruction can be used to read data from a flash?

lpm
Are the constructions
mov bx,byte[i+1] possible?

For program memory, no.
ldi r30, lo8(Message)
ldi r31, hi8(Message)

loop:

lpm
adiw r30, 1
mov byte, r0
ldi temp,0x01		;RS-bit (0 - sending command, 1 - send data)
rcall send_byte		;Call procedure for send a symbol as 4-bit mode
delayClocks 100,1,1     ;some delay
dec len	                ;len is length of string
brne loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question