Inline Assembly Troubles (Such a Noob Problem)

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

Inline Assembly Troubles (Such a Noob Problem)

3,440 Views
mjcoury
Contributor I
I am having some trouble with my inline assmebly. to preface everthing, this is my routine to read memory out to the serial port

void ReadRamOut(word iMemory, int iByte) {
int i = 0;
char *memory_ptr;

memory_ptr = (char*)iMemory;

for( i=0; i
SCIStartTransmit(*(memory_ptr+i));
} // end for
} // end ReadRamOut


Here is the code to write to flash

DisableInterrupts
memory_ptr = (char*)iMemory;
for( i=0; i
ctemp = gu8SCIData[i];
asm{
LDA ctemp
STA memory_ptr
}
WriteFlash();
memory_ptr++;
} // end for loop

iMode = 0x00;
gu8SCIIndex = 0;
EnableInterrupts

I show the ReadRamOut routine because that method of pointing to a memory location has worked for me... so I assumed it would work again for the inline assembly....
Now assume iMemory = 0x1600. instead of writing ctemp to the memory location 0x1600 it writes over the 0x1600 with the contents of ctemp. I have tried a few different combinations of iMemory and memory_ptr to get this to work.. Any Ideas?

Message Edited by mjcoury on 2006-08-01 08:58 AM

Labels (1)
0 Kudos
Reply
3 Replies

638 Views
rhinoceroshead
Contributor I
If you just want to transfer the contents of gu8SCIData[i] into the location pointed to by memory_ptr, then you can just do this:
 
*memory_ptr = gu8SCIData[i];
 
There is really no need to fuss with the inline assembly - but the reason it might be failing could be that you are erasing the contents of the accumulator when they are needed.  Try this assembly instead:
 
PSHA
LDA ctemp
STA memory_ptr
PULA
 
What is in the WriteFlash() function?  Do you know that works?
0 Kudos
Reply

638 Views
mjcoury
Contributor I
void WriteFlash(void) {
byte temp = 0x00;

if ((FSTAT & 0x10) != 0) {
FSTAT |= 0x30;
}
asm {
//LDA #$CC
//STA $1600
LDA #$20
STA FCMD
LDA #$80
STA FSTAT
NOP
NOP
NOP
NOP
WFLOOP:
LDA FSTAT
LSLA
BPL WFLOOP
}
} // end WriteFlash


Yes, I know it works.. if i use
asm{
LCD #$CC
STA $1600
}
WriteFlash()

the value of 0xCC will be written to location 0x1600

Message Edited by mjcoury on 2006-08-01 09:58 AM

0 Kudos
Reply

638 Views
CompilerGuru
NXP Employee
NXP Employee
as rhinoceroshead already pointed out, such simple assignments can be made easely in C, no need for HLI.
The HLI assembly instruction "STA memory_ptr" clearly stores the content of A into the high byte of the local variable memory_ptr. If you want to store to the place were memory_ptr points to, you have to load it into H/X, and then do a STA 0,X. Just using C is much simpler tough:
*memory_ptr= ctemp;

Daniel
0 Kudos
Reply