有人可以将以下加载和存储指令解释为 ARM ISA 的一部分吗? [英] Can someone explain the following load and store instructions as part of the ARM ISA?

查看:17
本文介绍了有人可以将以下加载和存储指令解释为 ARM ISA 的一部分吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习 ARM,我无法理解加载和存储指令的确切作用.

I'm just starting to learn ARM and I'm having trouble understanding what the load and store instructions do exactly.

加载指令:

ldrsb
ldrb
ldrsh
ldrh
ldr

商店说明:

strb
strh
str

加载半字"有符号或无符号是什么意思?还是加载字节"有符号或无符号?有符号和无符号之间有什么区别,某些加载/存储指令在哪些特定应用程序中实用?总而言之,我正在寻找对这些指令的作用的直观理解,因为我仍然对它们的工作方式和目的感到困惑.

What does it mean to "load halfword" signed or unsigned? Or to "load byte" signed or unsigned? What is the difference between signed and unsigned, and in what particular applications would some of the load/store instructions be practical to use? All in all, I'm looking for an intuitive understanding of what these instructions do, as I'm still confused about how they work and what their purposes are.

推荐答案

在谈论 ARM 时,字"是 32 位,半字"是 16 位,而字节"是 8 位.如果您阅读 ARM 架构参考手册中的指令集文档(如果您不知道要获取哪个,请获取 ARMv5 的指令集文档,infocenter.arm.com)您会看到 ldrb 将字节加载到低 8 位目标寄存器将高 24 位填充为零.ldrsb 将符号扩展而不是用零填充.半字也是如此.

When talking ARM a "word" is 32 bits, a "halfword" is 16 bits, and a "byte" is 8 bits. If you read the instruction set documentation in the ARM Architectural Reference Manual (just get the one for ARMv5 if you dont know which one to get, infocenter.arm.com) you will see that a ldrb loads the byte into the lower 8 bits of the destination register padding the upper 24 bits to zeros. A ldrsb will sign extend instead of pad with zeros. Same goes for halfword.

如果你有这样的代码:

char a,b,c;
...
c = a+b;
if(c<0)
{
}

并且 a 或 b 或两者在您需要进行此加法时都在内存中,那么您最好进行符号扩展(假设您已告诉编译器 char 已签名)加载以保存指令符号扩展寄存器,以便您可以执行数学运算并为比较设置正确的标志.

And either a or b or both were in memory at the time that you needed to do this addition then you would ideally want to do a sign extended (assuming you have told your compiler that char is signed) load to save instructions sign extending the registers so you can perform the math and have the flags set right for the comparison.

来自 ARM ARM.

From the ARM ARM.

LDRSB(加载寄存器有符号字节)从内存加载一个字节,对其进行符号扩展以形成一个 32 位字,并将结果写入通用寄存器.

LDRSB (Load Register Signed Byte) loads a byte from memory, sign-extends it to form a 32-bit word, and writes the result to a general-purpose register.

LDRB(加载寄存器字节)从内存中加载一个字节,将其零扩展以形成一个 32 位字,并将结果写入通用寄存器.

LDRB (Load Register Byte) loads a byte from memory, zero-extends it to form a 32-bit word, and writes the result to a general-purpose register.

这篇关于有人可以将以下加载和存储指令解释为 ARM ISA 的一部分吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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