SWI 中的条件位(ARM 指令) [英] Condition bits in SWI (ARM Instruction)

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

问题描述

在 ARM SWI 指令中,32 位分为 3 组:0:23(系统调用号)、24:27(0b1111)和 28:31(条件).条件是什么?

In ARM SWI instruction 32 bits are divided into 3 sets: 0:23 (System Call Number), 24:27 (0b1111), and 28:31 (Condition). What is the condition?

ARM SoC 架构"一书提到如果条件通过,指令进入监督模式."当我检查示例代码时,该示例在 SWI 之前有一个 CMP 条件,但我是仍然无法理解这种情况的原因.此外,互联网上出现的一些关于SWI for ARM"的介绍在 SWI 之前没有任何 CMP 条件.所以我很困惑我们是否需要它,如果是,那么需要什么?

The book 'ARM SoC Architecture' mentions that 'If condition is passed the instruction enters supervisor mode.' When i check the sample code then the example has one CMP condition before the SWI but I am still not able to understand the reason for the condition. Moreover, several presentations on 'SWI for ARM' present on the Internet don't have any CMP condition before SWI. So I am confused that whether we need it or not and if yes, then what is the need?

请帮助并提前致谢.

推荐答案

这是一个基本的 ARM 概念.尝试 google ARM 条件执行 OR 指令.例如,今天 Dave 的空间帖子很好地概述了这个概念.同样,维基百科文章引用自Stackoverflow ARM wiki 有关于这个主题的信息.

This is a fundamental ARM concept. Try to google ARM conditional execution OR instructions. For instance, today the Dave's space post gives a good overview of this concept. As well, the Wikipedia article referenced from the Stackoverflow ARM wiki has information on this topic.

简而言之,ARM有四个条件位或标志NZCVnote;这些是任何汇编程序/机器语言的标准概念.他们是,

In brief, ARM has four condition bits or flags NZCVnote; these are standard concepts to any assembler/machine language. They are,

  1. N 表示否定.
  2. Z 表示零.
  3. C 用于携带.
  4. V 表示溢出.
  1. N for negative.
  2. Z for zero.
  3. C for carry.
  4. V for overflow.

ARM 有 16 个条件执行前缀,用四位字段表示,用于测试条件位的变化,

ARM has 16 conditional execution prefixes represented in a four bit field that test variations of the condition bits,

  • 0000 - EQ 意味着 Equal 设置了 Zero 标志.
  • 0001 - NE 表示 不等于Zero 清除.
  • 0010 - CS 表示 Carry setHS 表示 无符号更高或相同Carry 设置.
  • 0011 - CC 表示 Carry clearLO 表示 unsigned lower with Carry> 清楚.
  • 0100 - MI 表示 ,带有 Negative 标志.
  • 0101 - PL 表示 Plus(包括零),Negative 标志清除.
  • 0110 - VS 表示 Overflow 并设置了 Overflow 标志.
  • 0111 - VC 表示 无溢出溢出 清除.
  • 1000 - HI 表示 无符号更高,带有 Carry 集合 AND 清楚.
  • 1001 - LS 表示 无符号更低或相同Carry 清除 AND > 设置.
  • 1010 - GE 表示 Signed 大于或等于Negative 等于 Overflow.
  • 1011 - LT 表示签名小于不等于溢出.
  • 1100 - GT 表示 Signed 大于清除 AND 等于溢出.
  • 1101 - LE 表示 签名小于或等于AND em> 不等于溢出.
  • 1110 - AL 意思是总是.如果汇编程序中没有条件部分,则使用此编码.
  • 1111 - NV;这是历史性的且已弃用,但对于 ARMv3,这意味着从不.即一个 nop.对于较新的 ARM (ARMv5+),这扩展了操作码范围.
  • 0000 - EQ meaning Equal with Zero flag set.
  • 0001 - NE meaning Not equal with the Zero clear.
  • 0010 - CS meaning Carry set or HS meaning unsigned higher or same with Carry set.
  • 0011 - CC meaning Carry clear or LO meaning unsigned lower with Carry clear.
  • 0100 - MI meaning Minus or negative with the Negative flag set.
  • 0101 - PL meaning Plus (including zero) with the Negative flag clear.
  • 0110 - VS meaning Overflow with the Overflow flag set.
  • 0111 - VC meaning No overflow with the Overflow clear.
  • 1000 - HI meaning an Unsigned higher with Carry set AND Zero clear.
  • 1001 - LS meaning Unsigned lower or same with Carry clear AND Zero set.
  • 1010 - GE meaning Signed greater than or equal with Negative equal to Overflow.
  • 1011 - LT meaning Signed less than with Negative not equal to Overflow.
  • 1100 - GT meaning Signed greater than with Zero clear AND Negative equal to Overflow.
  • 1101 - LE meaning Signed less than or equal with Zero set AND Negative not equal to Overflow.
  • 1110 - AL meaning Always. If there is no conditional part in assembler this encoding is used.
  • 1111 - NV; this is historical and deprecated, but for ARMv3 it meant never. Ie a nop. For newer ARMs (ARMv5+), this extends the op-code range.

几乎所有 ARM 指令都以这个四位字段为前缀.这不适用于 ThumbThumb2 说明.在统一汇编器(为 Thumb2ARM 汇编)中,IT 前缀被使用.

Almost all ARM instructions are prefixed with this four bit field. This does not apply to Thumb or Thumb2 instructions. In unified assembler (assembles for either Thumb2 or ARM), the IT prefix is used.

一个例子可能如下.你有这个'C'代码,

An example might be as follows. You have this 'C' code,

 if(size > 0)
    write(fd, buffer, size);

调用 write() 是一个操作系统调用.以下是一些示例汇编程序,

The call write() is an OS call. The following is some sample assembler,

 ; fd is in r0, buffer in r1, size in r2

 cmp  r2, #0         ; if(size > 0)
 movgt r7, #NR_write ; OS constant for write().
 swigt #0            ; call OS write() if(size > 0)

 ; code resumes here whether or not the OS was called.

ARM 条件有许多其他用途.

注意:所有现代 ARM CPU 都有一个 Q(饱和度)标志.它的行为方式不同,因为它是指令集的扩展.

Note: All modern ARM CPUs have a Q (saturation) flag. It behaves in a different way as it is an extension to the instruction set.

这篇关于SWI 中的条件位(ARM 指令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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