我正在编写一个基于LC-3汇编语言的.asm程序,它将遍历字符串列表,将每个字符串反转并将其存储回列表中的位置。字符串反转LC3汇编语言
例如:
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 - 装配程序在内存中反转字符串,请大家帮忙。