Вопрос

I want to substract 92H-64H in two's complementary and state whether carry flag bit C and overflow flag bit V are 1 or 0. So far no problem to convert and check in decimal that it is 146-100=46=2EH But I get lost in performing substraction to check bits bit by bit. I can imagine it's done in binary, but how? Appreciate any help!!

Это было полезно?

Решение

You have to operate in binary. Hexadecimal is no more than an easy (=less digits) way to show numbers that are binary internally.

That said, your two numbers:

92h - 64h . I assume you work with 8 bits. Translating them to binary: 1001 0010 - 0110 0100

To substract using c2, take the second number, 0110 0100

Invert its bits: 1001 1011

Add one: 1001 1011 + 1 = 1001 1100

Add this new number to the previous first number:

 1001 0010
 1001 1100
 ---------
10010 1110

The carry is the 9-th bit of this addition. In this case is 1. The overflow bit is calculated as follows: take the 8-th bit of each number in the addition: they are 1, 1, and 0. These are the sign bits of each number.

There is overflow if both signs of operands 1 and 2 are the same, bit the sign of the result is different. In any other case, there's no overflow.

In this addition, signs of both operands are the same (1) but sign of the result is not (it's 0), so there is overflow here.

By the way, the result of this addition (taking its lower 8 bits, discarding the carry bit) is the result of the original substraction.

The result of the addition is 0010 1110, which is 2E in hexadecimal.

So 92h - 64h = 2Eh, Carry is 1, Overflow is 1.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top