0

我正在尝试调整一个程序来计算文件中字符的出现次数,以存储匹配发生在遥远内存位置的十六进制地址列表。代码:

011 0000 0000 0000 ;Codes x3000 as Load-address of program
0101 010 010 1 00000 ;R2 <- 0
0010 011 000010000 ;R3 <- M[x3012]
1111 0000 0010 0011 ;TRAP x23 (Loads INPUT into R0)
0110 001 011 000000 ;R1 <- M[R3]
;LOOP BEGINS HERE
0001 100 001 1 11100 ;R4 <- R1 - EOT
0000 010 000001000 ;If above = 0, exit loop
1001 001 001 111111 ;R1 <- NOT R1
0001 001 001 1 00001 ;R1 <- R1 + 1
0001 001 001 0 00 000 ;R1 <- R1 + R0
0000 101 000000001 ;If above != 0, do NOT increment counter
0001 010 010 1 00001 ;R2 <- R2 + 1 (increment counter)
0001 011 011 1 00001 ;R3 <- R3 + 1 (increments pointer to next char in file)
0110 001 011 000000 ;R1 <- M[R3] (loads next char into R1)
0000 111 111110110 ;BRnzp x3004 (unconditionally RETURN to loop start)
;LOOP ENDS HERE
0010 000 000000100 ;R0 <- M[x3013]
0001 000 000 0 00 010 ;R0 <- R0 + R2
1111 0000 0010 0001 ;TRAP x21 (OUTPUT)
1111 0000 0010 0101 ;TRAP x25 (HALT)
0011 0001 0000 0000 ;Codes x3100 for the starting address of the file
0000 000 000110000 ;ASCII template

所以我的程序从内存地址 x3000 开始。我想开始在 x300B 处处理列表的指令集(在“增量 R2”指令下方)。麻烦的是,我想从 x3500 开始列表,但我不知道有一种“有效”的方法可以到达那里。

我最初的计划是使用加载间接 (LDI) 指令,但由于符号扩展,9 位偏移量最多只能允许 x00FF = 0000 0000 1111 1111 的偏移量,这只能让我从 x300C(x300B 与程序计数器递增)到 x310B。

我想出的唯一真正的“解决方法”是使用加载有效地址 (LEA) 指令将地址 x310B 存储在寄存器中(比如 R5),然后将值 x00FF 存储在 R6 中,并重复将 R6 添加到 R5直到我到达 x3408(这需要 3 个 ADD 指令),此时我将值 x0092 存储在 R6 中,将其添加到 R5,我最终在 R5 中有 x3500。

到那时,剩下的就很简单了(将 R3 存储在(R5 + 计数器)中,这会将当前匹配的地址放入列表中的适当“位置”)

我实际上还没有这样做,因为我上面描述的获取 x3500 的整个方法看起来真的很麻烦和笨拙。我无法摆脱这样一种感觉,即必须有一种更好、更快的方法来同时移动这么多内存地址。

Is it possible to move from x300C to x3500 in a single instruction? Even two would be better than what I've currently got.

4

1 回答 1

1

You wouldn't want to do that, it is possible but a simpler method would be to use LD (opcode 0010) and LDR (opcode 0110) to do this. No need to have the PC jump to x3500 (which would start executing the data in your array which is bad)

Have an address contain the bits 0011 0101 0000 0000 Opcode 0010 will allow you to pull the x3500 into a register. Opcode 0110 will then allow you to load values from your array.

于 2017-11-19T17:16:29.720 回答