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

查看:40
本文介绍了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 resp.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天全站免登陆