我创建了一个表,其中包含各种数据。我需要从该表中取出数据,对其进行更改,然后将其写回相同的位置,但是,由于某些原因,数据不会写入该位置
以下是我的代码
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当我遍历代码时,A从0到100再到120,然后它应该把它写到地址3(表中的位置0),再次取回它,再加20,等等。其工作原理如下:
A = 0 - first iteration
A = 100
A = 120
A = 0 - second iteration
A = 100
A = 120
etc我真正需要的是一种访问内存位置,更改它,然后更新它的方法。这一点:
A = 0 - first iteration
A = 100
A = 120
A = 0 - second iteration
A = 120
A = 140
etc我一直在阅读各种资料,但找不到一个有效的答案。例如,在这里,它显示了指令,但没有给出输出示例:http://www.keil.com/support/man/docs/is51/is51_mov.htm
编辑:我不一定要这样使用。我只需要一种方法来拥有一个变量,就像在C中一样,然后做一些像这样的事情:
int var = 100;
对于(;;) var += 20;
发布于 2015-06-02 08:13:36
通常,8x51微控制器不允许代码写入MOVC指令从中读取数据的地址空间。一些基于8x51的控制器或系统允许通过MOVX指令访问该空间,但可能需要将某些寄存器设置为某种方式才能实现。
https://stackoverflow.com/questions/30585356
复制相似问题