ARM 汇编中的双重条件 [英] Double Conditions in ARM assembly

查看:20
本文介绍了ARM 汇编中的双重条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ARM 的新手,正在为一门课做作业.我感到困惑的是双重条件,例如 if (x > 0 && x < 100) 做某事.

I am very new to ARM and doing an assignment for a class. What I am confused about is a double condition like, if (x > 0 && x < 100) do something.

我要做的是检查地址存储器中的信息是大写还是小写字符.

What I am trying to get done is check to see if in an address memory, if the information is a upper or lower case character.

我在这里找到了一个链接,但它不适用于 ARM,而且似乎对我没有帮助.

I found a link on here but it is not for ARM and doesn't seem like it can help me.

我尝试了类似的方法:

BGT r2, #0x60

BLT r2, #0x7B

但是会抛出关于期望地址表达式的错误,所以我假设您不能将值直接与 int 进行比较.

But is throwing errors about expecting an address expression so I am assuming you can not compare a value stright to an int.

已编辑,修复了我的情况,输入速度太快并且放错了 GT LT 箭头

Edited, fixed my condition, was typing too fast and put wrong GT LT arrows

推荐答案

我很困惑的是双重条件......

What I am confused about is a double condition...

您可以使用带有优化功能的编译器和反汇编器来查看它是如何实现的.使用 GNU 工具,这是 gccobjdump -S.

You can use a compiler with optimizations and a disassembler to see how it implements this. With the GNU tools, this is gcc and objdump -S.

如果 (x > 0 && x <100)

if (x > 0 && x < 100)

您需要检查两个条件并设置标志的汇编程序.假设值 xr0 中.

You need assembler that checks both conditions and sets a flag. Say the value x is in r0.

  sub r1, r0, #1    ; change zero test to minus.
  cmp r1, #98       ; allow equal.
  ; condition 'ls' (lower and same) for true
  movls r2, #42     ; set r2 to 42 if(x > 0 && x < 100)
  ; condition 'hi' (high unsigned) opposite flags
  movhi r2, #24

这是任何 CPU 的典型特征.编译器将测试转换为更好地映射到底层指令集的东西.您的示例测试有不同的运算符.

This is typical of any CPU. The compiler translates the tests to something that maps better to the underlying instruction set. Your example tests have different operators.

一些需要较少概念的代码更容易理解,

It is easier to understand some code that needs less concepts,

  if(x > 0 && y > 0)

这在汇编程序中转化为更直接的东西,

This translates to something more straight forward in assembler,

  cmp r0, #0
  cmpgt r1,#0
  movgt r0,#42 ; condition passed (here with signed conditions).

如果测试是针对相同的条件(通常是相同的C"运算符),则更直接,因为条件代码允许在这些情况下进行条件比较.

It is more straight forward if the tests are for the same conditions (usually the same 'C' operators) as the condition codes allow a conditional compare in these cases.

这篇关于ARM 汇编中的双重条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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