Comparing two number - Complement and natural
Author Message
Comparing two number - Complement and natural

Hi!

I would like two compare two number, that is, to see if A is equal,
greater or lower than B. I need an algorithm natural binary code and
other in complement code.

I have no idea how to do it in natural code. In binary code I'm stuck
in the case that A and B are both negatives and, after the operation,
I have overflow.

Could you say me how to do that (pseudo code or something like that)?

that what i have been doing:

; == Assembler 85 ==
; Cmp_Words
; complement
;
; 1st Argument: BC
; 2nd Argument; HL
; return: A
;          -1 se BC < HL; 1 se BC > HL; 0 se BC=HL
Cmp_Words:
MOV A,B
SUB H                   ; compares H
JZ zero
JM LowerA               ; the number is lower
JP GreatorA             ; the number is greater
zero:
MOV A,C                 ; compares L
SUB L
JZ igual
JM menorA               ; the number is lower
JP maiorA               ; the number is greater
igual:
MVI A,00H               ; the number is equal
RET
LowerA:
MVI A,0FFH
RET
GreaterA:
MVI A,01H
RET

Paulo Abreu

Thu, 10 Jan 2002 03:00:00 GMT
Comparing two number - Complement and natural

Quote:

>I would like two compare two number, that is, to see if A is equal,
>greater or lower than B. I need an algorithm natural binary code and
>other in complement code.

>I have no idea how to do it in natural code. In binary code I'm stuck
>in the case that A and B are both negatives and, after the operation,
>I have overflow.

Your questions makes no sense.  What is "natural code", especially as
apposed to binary code?  You also didn't say what kind of machine this is
running on.  Many machines have compare instructions and the like to
explicitly do what you are asking.

Fri, 11 Jan 2002 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages