【问题标题】:if-else logic simplificationif-else 逻辑简化
【发布时间】:2019-03-01 15:53:54
【问题描述】:

我有两个寄存器如下,

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

我无法像if(HL > DE) 那样直接比较HLDE。相反,我必须将寄存器分别比较为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

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

【问题讨论】:

  • 签名还是未签名?
  • @YvesDaoust 未签名
  • 然后是 Iłya Bursov 的回答。 h &gt; d or (h = d and l &gt; e)
  • @YvesDaoust 是的,先生,它就像一个魅力,但我想知道它们的使用方式是如何简化的。你能说吗?
  • 你的提议太复杂了。

标签: algorithm if-statement logic boolean-logic


【解决方案1】:

unsigned hl > de有两种情况:

  1. h &gt; d
  2. h == d AND l &gt; e

【讨论】:

  • 它就像一个魅力,但我想知道它们的使用方式是如何简化的。你能说吗?
  • @snr 我不确定我是否理解问题,你的意思是什么?
  • 我的意思是你如何得到简化?你用什么方法?
  • @snr 我想是structural induction
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多