我一直在制作这个程序,它接受一个列表并在其中查找唯一元素并将其存储在另一个列表或寄存器中
下面的代码将主列表放入 SI 寄存器中,然后 BX 充当指针,遍历整个数组以查找相似之处...如果没有找到相似之处,则 SI 中的元素(存储在 AL 中)将存储在 DI 中。 .为了避免当 BX 到达其值的完全相同位置时可能出现的第一个相似性,我为此设置了一个标志。
uniqueElement macro list1 list2
local loop1,comparasionLabel,checkFlag,trigger,nextElement,addElement,endAddition
lea si,list1
lea di,list2
loop1:
mov ah,00H
mov cx,00H ;this is an intial flag gets triggered when an initial similarity is spotted
lea bx,list1 ; this will be the search loop which will compare each of it's elements to SI
mov al,BYTE PTR[SI]
cmp al,'$' ; since I'm using a '$' terminated string
je endAddition
comparasionLabel:
mov dl,BYTE PTR[BX]
cmp dl,'$'
je addElement
cmp al,dl
je checkFlag
inc bx
jmp comparasionLabel
checkFlag:
cmp cx,00H ; this is when a first similarity is spotted, the flag gets triggered here
je trigger
cmp cx,01H ; or if it was already triggered and another similarity spotted, SI moves to next element
je nextElement
trigger:
mov cx,01H
inc bx
jmp comparasionLabel
nextElement:
inc si
jmp loop1
addElement:
mov ah,00h
mov BYTE PTR [di],al
inc di
inc si
jmp loop1
endAddition:
inc di
mov ah,00H
mov al,'$'
mov BYTE PTR[di],al
endm
这只是执行宏的代码
.model small
.data
list1 db 'H3llo$'
list2 db 50 DUP [?]
.code
mov ax,@data
mov ds,ax
uniqueElement list1 list2
mov ah,09H
mov dx,offset di
int 21h
.exit
我不知道为什么它不断打印相同的列表而不删除唯一的项目