I created a table, where I have various data. I need to take out data from this table, alter it, then write it back to the same position, however, for some reason, data is not written to the position
Here is my code
CSEG AT 3h
precos: DB 100, 200, 150, 170
Lookup:
MOV DPTR, #precos ; DPTR points to the start of the lookup table
MOV A, #0 ; A is the offset from the start of the lookup table
MOVC A, @A + DPTR ; Moves the (A+1)th item into the Accumulator
ADD A, #20
MOV R1, #precos
MOV @R1, A
JMP Lookup
When I loop through the code, A goes from 0 to 100 to 120, then it's supposed to write it at address 3 (position 0 from the table), get it back again, add 20 more, etc... Works like this:
A = 0 - first iteration
A = 100
A = 120
A = 0 - second iteration
A = 100
A = 120
etc
What I actually need, is a way to access a memory position, alter it, then update it. This:
A = 0 - first iteration
A = 100
A = 120
A = 0 - second iteration
A = 120
A = 140
etc
I have been reading through various stuff, but couldn't find an answer that works. Here, for example, it shows the instructions, but doesn't give output examples: http://www.keil.com/support/man/docs/is51/is51_mov.htm
Edit: I don't necessarily need to use exactly this way. I just need a way to have a variable, like in C, and do something like this:
int var = 100;
for(;;) var += 20;
In general, 8x51 microcontrollers do not allow code to write to the address space from which a MOVC instruction reads data. Some 8x51-based controllers or systems allow that space to be accessed via MOVX instruction, but may require that certain registers be set a certain way to enable that.