我正在編寫一個基於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 - 裝配程序在內存中反轉字符串,請大家幫忙。