Monday, May 10, 2010

VHDL evaluating B GT A

So I stop screwing this up over and over,

Method for determinging A GT B for two unsigned integers using standard subtractor in VHDL:

where f(x,y) = x-y = x + 2's complement(y),

carry out of f(B-A) shows B > A. not f(A-B).

Examples:

1) is 70128 GT 65535?
for 24 bit case,
B = 70128 = x0111F0
A = 65535 = x00FFFF, 2s_comp(B) = xFF0001

B - A = x0111F0 + xFF0001 = x10011F1, carry out is 1, remainder = B-A = 4593

2) is 32768 GT 65535?
for 24 bit case,
B = 32768 = x008000
A = 65535 = x00FFFF, 2s_comp(B) = xFF0001

B - A = x008000 + xFF0001 = xFF8001, carry out is 0, remainder = B-A = -32767