我正在尝试逐位减去 2 个整数,并得到了这个算法
b = 0
difference = 0
for i = 0 to (n-1)
x = bit i of X
y = bit i of Y
bit i of difference = x xor y xor b
b = ((not x) and y) or ((not x) and b) or (y and b)
end for loop
我已经实现了这一行b = ((not x) and y) or ((not x) and b) or (y and b)
。我应该如何在我的代码中实现算法的最后一行
这是我到目前为止所拥有的:
INCLUDE Irvine32.inc
.data
prompt1 BYTE "Enter the first integer: ",0dh,0ah,0
prompt2 BYTE "Enter the second integer: ",0dh,0ah,0
prompt3 BYTE "The first integer entered is not valid ",0dh,0ah,0
prompt4 BYTE "The second integer entered is not valid ",0dh,0ah,0
X byte 0
Y byte 0
diff byte 0
.code
main PROC
L1:
mov edx, OFFSET prompt1
call writeString
xor edx, edx
call readInt
js printError1
cmp eax, 0ffh
jg printError1
mov X, al
xor eax, eax
L2:
mov edx, OFFSET prompt2
call writeString
xor edx, edx
call readInt
js printError2
cmp eax, 0ffh
jg printError2
mov Y, al
xor eax, eax
jmp calculation
printError1:
mov edx, OFFSET prompt3
call writeString
xor edx, edx
jmp L1
printError2:
mov edx, OFFSET prompt4
call writeString
xor edx, edx
jmp L2
calculation:
mov ebx, 0
mov diff, 0
mov ecx, 7
subtract:
mov al, X
and al, 1h
mov dl, Y
and dl, 1h
xor al, dl
xor al, bl
mov diff, al
rol X, 1
rol Y, 1
loop subtract
exit
main ENDP
END main
该算法从计算循环标签开始。我需要保存存储在al
寄存器中的值,以实现算法的最后一行,但是由于使用了dl
and bl
,我应该使用哪个通用寄存器来存储 的值al
?