ARM 中的 CMP 和 TST 指令有什么区别? [英] What's the difference between the CMP and TST instructions in ARM?

查看:41
本文介绍了ARM 中的 CMP 和 TST 指令有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 ARM 中这两条指令之间的区别.据我了解,

I'm having trouble understanding the difference between these two instructions in ARM. From what I understand,

CMP R1, R2

将执行操作 R1-R2,但不存储结果.然后它会在状态寄存器中设置标志,例如 N(负,如果 R1

我不明白的是 TST 的做法有何不同.在我的笔记中,它说 TST 不会改变其操作数的值......但我认为 CMP 也没有.这两个指令有何不同?

Would perform the action R1-R2, but not store the result. It would then set flags in the status register such as N (negative, if R1

What I don't get is what TST does differently. In my notes it says that TST doesn't change the values of its operands.. but I thought CMP didn't either. How do the two instructions differ?

怎么样

CMP R1, R2

不同于

TST R1, R2

?在此先感谢您的帮助!

? Thanks in advance for any help!

推荐答案

TST R1, R2 计算 R1R2 的按位与然后丢弃结果,同时 CMP R1, R2 将两者相减.TST 主要在 ARM 上用于确定给定位是否设置在数字中.例如,要检查 R1 是否为奇数,您可以这样做:

TST R1, R2 computes the bitwise AND of R1 and R2 and then discards the result while CMP R1, R2 subtracts the two. TST is mainly useful on ARM for finding out if a given bit is set in a number. For example, to check if R1 is odd, you might do:

TST R1, #1    @ is R1 odd?

如果 R1 是奇数,这会将 Z 标志设置为 0.

This sets the Z flags to 0 iff R1 is odd.

这篇关于ARM 中的 CMP 和 TST 指令有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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