ARM 汇编器 - 如何使用 CMP、BLT 和 BGT?

2023-11-24

问你们一个简单的问题,在我的循环中,我需要使用 CMP 、 BLT 和 BGT 来比较一些值。如何在下面的循环中使用所述指令?

我正在尝试使用 BGT 、 BLT 和 CMP 因为我需要它们来使我的应用程序正常工作。问题是我不知道如何使用它们。如果我想使用 CMP 比较 r6 和 r4 并将差异放入 r7 中,我该怎么做?同样的问题,如果我想在 r7 小于 0 的情况下使用 BLT,我该怎么做?

  BGT ??????? ; branch if greater than 5
  CMP ???????? ; compare r6 with r4 , put difference into r7
  BLT ???????? ;branch if r7 is less than 0
  BGT ???????? ;branch if r7 is greater than 0

这是我的整个循环:

LoopStart

  BL WaitBUT1
  BL readTemp
  BL checkTemp
  BGT ??????? ; branch if greater than 5
  BL errorVal
  CMP ???????? ; compare r6 with r4 , put difference into r7
  BLT ???????? ;branch if r7 is less than 0
  BL FanOn
  BL errorLedOn
  BL systemLedOn
  BL heaterOn
  BGT ???????? ;branch if r7 is greater than 0
  BL FanOff
  BL errorLedOff
  BL systemLedOff
  BL heaterOff
  BL WaitBUT2
  BL FanOff
  BL errorLedOff
  BL systemLedOff
  BL heaterOff

  B LoopStart

如果不先以某种方式设置条件寄存器,就无法执行条件分支。这可以通过以下方式完成cmp或者通过添加s大多数指令。有关详细信息,请查看 ARM 汇编文档。快速示例:

分支如果r0大于 5:

cmp r0, #5 ;Performs r0-5 and sets condition register
bgt label_foo ;Branches to label_foo if condition register is set to GT

Compare r6 with r4,将差值代入r7, 分支如果r7 < 0:

subs r7, r6, r4 ;Performs r7 = r6 - r4 and sets condition register
blt label_bar ;Branches to label_bar if r7 < 0 (in which case r6 < r4)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ARM 汇编器 - 如何使用 CMP、BLT 和 BGT? 的相关文章

随机推荐