aarch64中的零寄存器'zr'是否基本接地? [英] Is Zero Register 'zr' in aarch64 essentially ground?

查看:341
本文介绍了aarch64中的零寄存器'zr'是否基本接地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近开始弄乱AArch64程序集,我注意到它有一个严格分配给 zero 的寄存器,而(大多数)其他体系结构中,您只是 xor var,var

Recently started messing with AArch64 assembly and I noticed that it has an assigned register strictly for zero, whereas (most) other architectures you would just xor var, var.

我正在阅读的有关 zr 的站点将其解释为参考点为零,这听起来很像我在直流电子设备中定义接地的方式。而且由于业余爱好者使用ARM,因此在代码中将电路中的接地零归类为零对我来说很有意义。

The site I was reading about zr explained it as a reference point for zero which sounds a lot like how I define ground in DC electronics. And because ARM is used by hobbyists, tying ground in the circuit to zero in the code kinda makes sense to me.

我敢肯定它比这复杂得多,但这是一个安全的类比吗?与使用其他获得 0的方式相比,使用该寄存器会产生不同的结果吗?

I'm sure it's much more complex than this, but is this a safe analogy to make? And would using this register compared to other ways of getting '0' result in different outcomes?

推荐答案

清零寄存器 xzr wzr 是Aarch64 ISA中的一个可爱的设计技巧。它的注册号为31,就像堆栈指针 sp 一样。 wsp 。根据具体情况,寄存器号31是其中之一。

The zero register xzr resp. wzr is a cute design trick in the Aarch64 ISA. It's register number is 31, just as the stack pointer sp resp. wsp. Depending on the context, register number 31 refers to one of them.

这个可爱的技巧使Aarch64 ISA可以简化其指令集。例如, cmp xn,xm 指令实际上是 subs xzr,xn,xm ,即它与结果被丢弃。 mov xn,xm 只是 orr xn,xzr,xm 。寄存器31仅被认为是有意义的堆栈指针,并且已明智地选择了指令集,因此您几乎永远都不会碰到这个细节。

This cute trick allows the Aarch64 ISA to simplify its instruction set. For example, the cmp xn, xm instruction is actually subs xzr, xn, xm, i.e. it's a subtract with the result being discarded. A mov xn, xm is simply an orr xn, xzr, xm. Register 31 is only recognised as the stack pointer where it makes sense and the instruction set has been cleverly chosen so you almost never hit this detail.

这篇关于aarch64中的零寄存器'zr'是否基本接地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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