if-else逻辑简化

时间:2019-03-01 15:53:54

标签: algorithm if-statement logic boolean-logic

我有以下两个寄存器,

HL(consecutive), H holds 8-bit, L holds 8-bit so HL is 16-bit register pair
DE(consecutive), D holds 8-bit, E holds 8-bit so DE is 16-bit register pair

我无法像HL那样直接比较DEif(HL > DE)。相反,我必须将寄存器分别比较为H, L, D, E。我构造了if-else结构来了解if(HL > DE)

1。

if (l < e)
   if(h > d)
      do what I want
... if not checking other possibilities 2, 3

2。

if (l > e)
   if(h > d)
      do what I want
... if not checking other possibilities 1, 3

3。

if (h > d)
     do what I want
... if not checking other possibilities 1, 2

我不确定我是否做对了。但是,如果这样,可以简化其中三个吗?

1 个答案:

答案 0 :(得分:1)

无符号hl> de有两种情况:

  1. h > d
  2. h == d AND l > e