机器只有直接寻址模式,意思是:
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
答案 0 :(得分:1)
没有寄存器间接寻址模式,除了自修改代码之外别无其他方法,正如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个寄存器。如果指令集包含'compare'指令,那么2个寄存器就足够了。