机器只有直接寻址模式,意思是:
load R1, address --> fill R1 with value of Memory[address]
store R1, address --> fill Memory[address] with value of R1其他一些指示:
add R1, #immediate --> R1 = immediate + R1
add R1, address --> R1 = M[address] + R1
Loop R1, L --> if != 0 goto L 发布于 2014-02-22 13:54:07
如果没有寄存器间接寻址模式,除了自修改代码之外,没有其他方法,正如rcgldr已经指出的那样。
start: load R1, #arrayAddr ; address of first array element
load R2, #arrayLength ; loop counter
load R3, #0 ; sum
arrayLoop: store R1, modifyAddr ; modify operand of the instruction below
opcodeAddr: add R3, dummyAddress ; get array element, add to sum
add R1, #2 ; next address (assuming 16-bit integers, i.e. 2 bytes per element)
add R2, #-1 ; decrement counter
loop R2, arrayLoop将modifyAddr定义为标签opcodeAddr处的指令地址
modifyAddr = opcodeAddr + 1 ; (assuming instructions have a 1-byte opcode)我用了3个寄存器。如果指令集包含一个“比较”指令,那么2个寄存器就足够了。
https://stackoverflow.com/questions/21939793
复制相似问题