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

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

问题描述

你快问你们,在我的循环,我需要使用CMP,BLT和BGT比较某些值。如何将使用表示,在下面的循环说明?

我想因为我需要他们做我的应用程序工作中使用BGT,BLT和CMP。麻烦的是我不知道如何使用它们。如果我想用CMP比较R6与R4并把差异变成R7,我会怎么做呢?同样的问题,如果我想用BLT如果R7是小于0,我会怎么做呢?

  BGT ??????? ;如果分公司大于5
  CMP ???????? ;比较R6与R4,把差到R7
  BLT ????????分支如果R7是小于0
  BGT ????????分支如果R7是大于0

下面是我的整个循环:

 环路启动  BL WaitBUT1
  BL readTemp
  BL checkTemp
  BGT ??????? ;如果分公司大于5
  BL errorVal
  CMP ???????? ;比较R6与R4,把差到R7
  BLT ????????分支如果R7是小于0
  BL法农
  BL errorLedOn
  BL systemLedOn
  BL heaterOn
  BGT ????????分支如果R7是大于0
  BL FanOff
  BL errorLedOff
  BL systemLedOff
  BL heaterOff
  BL WaitBUT2
  BL FanOff
  BL errorLedOff
  BL systemLedOff
  BL heaterOff  乙环路启动


解决方案

您不能做一个条件分支不首先以某种方式设置条件寄存器。这可以用 CMP 或通过添加取值来大多数指令来完成。查看详情ARM汇编文件。简单的例子:

如果科 R0 大于5:结果

  CMP R0,#5,执行r0-5并设置条件寄存器
BGT label_foo;分行以label_foo如果条件寄存器设置为GT

比较 R6 R4 ,把差成 R7 ,如果分支 R7< 0 :结果

 潜艇R7,R6,R4; R7执行= R6  -  R4,并设置条件寄存器
BLT label_bar;分行以label_bar如果R7< 0(在这种情况下,R 6所述; R 4)

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?

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

Here's my entire loop:

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

解决方案

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:

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

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天全站免登陆