Reputation: 11
I am currently trying to change the value of a string in the AVR assembly language. I am not sure if it is possible. I declare the string as:
message: .db "Frequency = 1 kHz",0x00
I am trying to alter the value stored at message later in the code to "Frequency = 2 kHz" Any idea how to do this? I want to replace the entire string, but still store it at message.
I'm using the AVR assembly language.
I tried doing:
message: .db "Frequency = 2 kHz",0x00
at a later point in my program, but I realized it would not let me re-initialize the variable.
Upvotes: 0
Views: 2291
Reputation: 8449
The label "message:" is not a variable. It acts like an address which you can reference elsewhere in your program. From the manual:
The DB directive reserves memory resources in the program memory or the EEPROM memory. In order to be able to refer to the reserved locations, the DB directive should be preceded by a label.
So it is not in SRAM, where variables reside.
You can use the LPM instruction to load values from the string after first setting Z to contain the address. [LPM : Load Program Memory : R0 ← (Z)]
It sounds like you might want to do something like having two strings and insert the number as character when you need it.
message1: .db "Frequency = ",0x00
message2: .db " kHz",0x00
You will have to do something to make sure the null byte in the first string is not transmitted.
The character for val = 1 or 2 is just 0x30 + val
Upvotes: 1