el tema bandera de acarreo!
-
04-10-2019 - |
Pregunta
Supongamos AX y BX = FFFE = 1234
Ahora bien, si escribimos cmp ax,bx
gratis (BX se restará de hacha y se actualizará los flages approprite)
Ahora la representación binaria de los números de hacha y BX está dada por
AX = 1111 1111 1111 1110
BX= 0001 0010 0011 0100
Como bx será restado de hacha lo que tenemos que cambiar signo BX (como Resultado = ax + (- bx))
por lo que el BX negada (complemento a 2 de bx) viene dada por.
BX= 1110 1101 1100 1100
Ahora añadir tanto hacha y BX (como la resta se lleva a cabo mediante la adición de ordenador)
AX= 1111 1111 1111 1110
BX= 1110 1101 1100 1100
------------------------------------
1 1110 1101 1100 1010
Ahora bien, como se puede ver el resultado es de 17 bits ahora el bit 17a debe entrar en acarreo flage, pero cuando he comprobado que la bandera de acarreo es 0 que es CF = 0 por qué?
Solución
Found a link here: http://oopweb.com/Assembly/Documents/ArtOfAssembly/Volume/Chapter_6/CH06-2.html
It is as I expected. The carry flag is set only if "borrow" was required. When doing subtraction, you set the carry flag prior to doing the "subtract" and the new carry flag tells if you had to borrow. Your example omitted the addition of 1 for the pre-set carry flag in bit 17 which will cause no carry in the result.
Otros consejos
Think of the carry flag as a borrow bit when subtraction is performed. It is initialized to 1 so the operation is a−b−C
, i.e., a + not(b) + C
instead of a + not(b) + 1
as you described. In other words, the carry is inverted for subtract so it can be used to do multiple-precision subtract.