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

thanks in advance,

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  
 
 [ 2 post ] 

 Relevant Pages 

1. compare two numbers with one string (true/false) output

2. how to compare two columns in two files?

3. Two's complement and -32768

4. Two's Complement

5. Angles don't map nicely to two's complement turns

6. Two's Complement Shifter Code

7. Two's Complement Multiplication in Verilog

8. 16-bit Two's complement Multiplier

9. twos complement integer support in Verilog simulators

10. Two's complement signed binary addition and subtraction

11. Another Question on Two's Complement

12. two's complement

 

 
Powered by phpBB® Forum Software