我正在编写一个基于 LC-3 汇编语言的 .asm 程序,该程序将遍历字符串列表,反转每个字符串,并将其存储回列表中的位置。
例如:
STRINGS .STRINGZ "aabbb"
"bbcva"
"abcde"
该程序会将该列表翻转为“ bbbaa
”、“ avcbb
”和“ edcba
”——因此,颠倒字符串但保持列表顺序。
我目前正在研究一个嵌套循环的想法,其中外循环将从一个字符串转到另一个字符串,而内循环将翻转它们,它正在踢我的屁股!我用 Java 编写了代码来做同样的事情,我花了 5 分钟,但出于某种原因,汇编只是在我的脑海里大便。有关如何执行此操作的任何指示?
到目前为止,这是我所拥有的,混合了伪和汇编:
.ORIG x3000
LEA R0, STRINGS ; Load the address of the first char of the list of strings
Loop until NOP is found, signaling end of the string.
LEA R1, the address above ; stores the address of the last char
LDR R2, #0 Offset +1 ; load the first char to be flipped
LDR R3, #0 Offset +2 ; load the last char to be flipped
STR R3, #0 Offset +1 ; store the last char in the mem addr of the first
STR R2, #0 Offset +2 ; store the first char in the addr of the last
ADD R1, R1 + 1 ; increment the addr of the first char to move to the second
ADD R2, R2 - 1 ; decrement the addr of the last char the move the second-to-last
loop back to beginning somehow
而且我一点也不知道如何在字符串之间进行外循环。
TL;DR - 用于反转内存中字符串的汇编程序,请帮助。