这是一个替代A1
循环。我认为您的设置说明没问题。我假设 Intel 语法对指令的操作数排序。
A1:
MOV AL,[SI] ; get the next byte from LIST1
ADD AH,[BX] ; get the next byte from LIST2
CMP AL,AH ; compare bytes from 1 & 2
JGT BIGGER2 ; jump if LIST1 byte > LIST2 byte
MOV [DI],AL ; move LIST1 byte to LIST2
JMP NEXT
BIGGER2:
MOV [DI],AH ; move LIST2 byte to LIST3
NEXT:
INC SI ; point to next LIST1 byte
INC BX ; point to next LIST2 byte
INC DI ; point to next LIST3 byte
LOOP A1 ; go to the top for the next byte
在解决这样的问题时,您实际上可以从写出评论开始。如果你自己接受上面的评论,它们就构成了你想做的事情的低级步骤。然后您可以将这些步骤翻译成所需的汇编语言。然后,您还可以根据需要进行优化。
[编辑]
另请注意,正如@Powerslave 在他的回答中显示的那样,您可以使用内置的 x86“字符串”指令将其缩短一点,cmpsb
. 假设源和目标列表由si
和指向di
。
此外,以下将 和 的LIST1
SUMLIST2
放入LIST3
。请注意,您为字节分配了字节,LIST3
但是当您对元素求和时LIST1
,LIST2
如果将它们保留为字节,则会出现溢出。所以我会用词来表示总和:
LIST3 DW 6 DUP (?)
...
CLR AH
A1:
MOV AL,[SI] ; get the next byte from LIST1
MOV [DI],AX ; move the value (byte) to LIST3
MOV AL,[BX] ; get the value (byte) from LIST2
ADD [DI],AX ; add the LIST2 value to LIST3 (word)
INC SI ; point to next LIST1 byte
INC BX ; point to next LIST2 byte
ADD DI,2 ; point to next LIST3 word
LOOP A1 ; go to the top for the next byte