[Coco] Assembler Question???

jdaggett at gate.net jdaggett at gate.net
Fri Sep 4 14:42:22 EDT 2009

```On 4 Sep 2009 at 3:48, Tveo Loatouse wrote:

> >There is actually no sub tractor but,
>
> According to the book: Microprocessor- Microcomputer  Technology by
> Frederick F. Driscoll. It says, "In all uPs, subtraction is done by
> 2's complement arithmetic. If the result is negative, the answer is
> in 2's complement form. For example, if the problem is 4 - 7 = -3, the
> answer, -3, in 2's complement form is 11111101 (binary). Microprocessors
> have instructions that can check the logic state of bit 7, the most
> significant bit of the answer. If bit 7 is a logic 0, the answer is
> positive; if bit 7 is a logic 1, the answer is negative. Hence, a
> positive or negative answer can easily be determined."
>
> tvefoo.

Correct that all ALUs do subtraction by adding the 2's complement of the subtrahend.
That I knew. As I stated before, there is no logic circuit that does subtraction.

Per Computer Engineering hardware Design by M. Morris Mano:

"The subtraction of binary numbers can be done most conveniently by menas of
complements ... Remember that the subtraction A - B can be done by taking the 2's
complement of B and adding it to A. The 2's complement can be obtained by taking the
1's complement and adding one to the least significant bit. "

So subtraction is done by setting the carry bit, invert the B input and add it to the A input
and you have subtraction. My main concern was whether the assembler did the
complement and store it in 2's or 1's complement form in the assembler output or left the
number in binary form. Doing the 2's compliment is easy in logic prior to the adder.
Simply put XOR gates in front of the B input and use a select bit to set the XOR gates to
invertors or buffers. Invertors for Subtract and Buffers for Addition. Also in Subtraction
the carry in bit is set and you have subtraction. Simple and eligant as long as you know
what is actually inputed from an assembled program.

james

```