如何在 ARM 程序集中屏蔽字节? [英] How to mask bytes in ARM assembly?

查看:18
本文介绍了如何在 ARM 程序集中屏蔽字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 32 位(十六进制)字 0xaabbccdd,必须交换 2. 和 3. 字节.最后它应该看起来像 0xaaccbbdd

i have got an 32bit (hexadecimal)word 0xaabbccdd and have to swap the 2. and the 3. byte. in the end it should look like 0xaaccbbdd

我如何屏蔽"第二个和第三个字节以首先将它们加载到寄存器 r1 和 r2 并交换它们..我也知道我必须使用 lsl 和 lsr 命令,但不知道如何开始.

how can i "mask" the 2nd and the 3rd byte to first load them up to register r1 and r2 and the swap them.. i also know that i have to work with lsl and lsr commands but dont know how to start.

抱歉我的英语不好.希望任何人都可以帮助我!

sorry for my bad english.hope anyone could help me out!

问候,塞巴斯蒂安

推荐答案

回到过去,我们曾经严重依赖 EOR 来处理这种诡计.

Back in the day we used to rely heavily on EOR for this kind of trickery.

您可以在 4 个周期内完成.

You can do it in 4 cycles.

首先,我们需要这样一个事实:A ^ (A^B) = B

First off, we need the fact that: A ^ (A^B) = B

我们从 0xAABBCCDD 开始,我们想要 0xAACCBBDD.为了到达那里,我们需要 0x00EEEE00^0xAABBCCDD,其中 EE = BB^CC.

We start with 0xAABBCCDD, and we want 0xAACCBBDD. To get there, we need 0x00EEEE00^0xAABBCCDD, where EE = BB^CC.

现在,我们需要几个周期来构建 00EEEE00:

Now, we need a few cycles to build 00EEEE00:

eor     r1,r0,r0,lsr #8
and     r1,r1,#0xFF00
orr     r1,r1,r1,lsl #8
eor     r0,r0,r1

在 c:

t=x^(x>>8);
t=t&0xFF00;
t=t|(t<<8);
x^=t;

在每一行之后,计算的结果是:开头:AABBCCDD

After each line, the result calculated is: starting with: AABBCCDD

eor  XXXXEEXX
and  0000EE00
orr  00EEEE00
eor  AACCBBDD

这适用于任何 32 位 ARM 内核.

This will work on any 32bit ARM core.

这篇关于如何在 ARM 程序集中屏蔽字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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