ARM 汇编器 - 如何使用 CMP、BLT 和 BGT? [英] ARM Assembler - How do I use CMP, BLT and BGT?

查看:187
本文介绍了ARM 汇编器 - 如何使用 CMP、BLT 和 BGT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给你们的快速问题,在我的循环中,我需要使用 CMP 、 BLT 和 BGT 来比较一些值.如何在以下循环中使用所述指令?

Quick question for you guys, in my loop I need to use CMP , BLT and BGT to compare some values. How would use said instructions in the following loop?

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

I'm trying to use BGT , BLT and CMP as I need them to make my application work. The trouble is I have no idea how to use them. If I wanted to use CMP to compare r6, with r4 and put the difference into r7, how would I do this? The same question if I wanted to use BLT if r7 is less than 0, how would I do this?

  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 程序集文档.快速示例:

You cannot do a conditional branch without first setting the condition register somehow. This can be done with cmp or by adding s to most instructions. Check out the ARM assembly documentation for details. Quick example:

如果 r0 大于 5,则分支:

Branch if r0 greater than 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

比较 r6r4 ,将差值放入 r7 中,如果 r7 则分支0:

Compare r6 with r4 , put difference into r7, branch if 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)

这篇关于ARM 汇编器 - 如何使用 CMP、BLT 和 BGT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆