In start08.c from my MC9S08SH8 Startup_Code folder, I found this code snippet (I've removed irrelevant comments and follow-on code):
static void Init(void) {
int i;
asm {
ZeroOut:
LDA _startupData.nofZeroOuts:1 ; /* nofZeroOuts */
INCA
STA i:1 ; /* i is counter for number of zero outs */
LDA _startupData.nofZeroOuts:0 ; /* nofZeroOuts */
INCA
STA i:0
LDHX _startupData.pZeroOut ; /* *pZeroOut */
BRA Zero_5
Zero_3:
.
.
}
What are the "i:0" and "i:1" references? From the definition of "i" as an int, (a 16-bit, 2-byte value), they APPEAR to be low-byte and high-byte references, especially since the "STA" opcode is dealing with the 8-bit accumulator. I can't see that there is any reference to a structure or bitfield since "i" is defined locally.
It appears that
"STA i:1"
means
"store the entire 8-bit accumulator in the high byte of variable 'i' ".
It doesn't make any sense if I try to look at it from the individual bits. Am I correct?
Bob
Hi,
regarding to "STA i:1"
here, "i" is a variable name. "1" is offset address of "i".
let's take example "i" is at address 0x100. thus "STA i:1" means stores the contents of A in memory address 0x101(0x100+1)
other examples:
"STA i:2" : stores the contents of A in memory address 0x102
"STA i:0" : stores the contents of A in memory address 0x100
"STA i:5" : stores the contents of A in memory address 0x105
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Jennie:
Thank you for clarifying that.
I am curious, though... using your example where "i" is at location 0x100, wouldn't
"STA i+5"
also store the accumulator at address 0x105, which is the way I have always known how to store the Accumulator at a fixed offset from a given address location?
Is this "offset syntax" standard usage industry-wide, or only available on NXP/Freescale processors (used with CodeWarrior)? I could not find any reference to this type of offset usage on the internet.
Bob
Hi,
instruction STA doesn't support syntax "STA i+5".
I think the offset syntax is widely used in many MCU assembly code.
for more information about STA usage, see below. I extracted it from instruction set. see attached document.
Have a great day,
Jennie Zhang
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------