问题是:
adc eax, ebx
指令将寄存器eax
,寄存器ebx
和进位标志的内容相加,然后将结果存储回eax
。假设不允许使用adc
指令,请写几条与adc eax, ebx
产生完全相同行为的指令。
会是这样吗?
add eax, ebx
add eax, 1
您需要做的是使用条件跳转来处理进位标志。您可能有几种方法可以解决此问题。这是我的方法:
push ebx ; We want to preserve ebx. This seems lazy but it's
; an easy approach.
jnc carry_handled ; If the carry is set:
add ebx, 1 ; Add 1 to summand. We are using
; ADD here, because INC does not
; set the carry flag.
;
jz carry_overflowed ; If it overflows (ebx is 0), then
; skip the addition. We don't want
; to add 0 which will clear the
; carry flag.
carry_handled: ;
add eax, ebx ; Add the adjusted summand.
carry_overflowed:
pop ebx
要注意的重要事项是您希望正确设置CPU标志,就像执行adc
一样。在上述方法中,如果您以后不关心进位标志,则jz carry_overflowed
是多余的。