在Objective-C中使用内联汇编对变量进行ROL/ROR [英] ROL / ROR on variable using inline assembly in Objective-C

查看:275
本文介绍了在Objective-C中使用内联汇编对变量进行ROL/ROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对Objective-C程序中的变量执行ROR和ROL操作.但是,我无法管理它-我不是组装专家.

I would like to perform ROR and ROL operations on variables in an Objective-C program. However, I can't manage it – I am not an assembly expert.

这是我到目前为止所做的:

Here is what I have done so far:

uint8_t v1 = ....;
uint8_t v2 = ....; // v2 is either 1, 2, 3, 4 or 5

asm("ROR v1, v2"); 

我得到的错误是:

后缀大小未知的指令助记符的未知使用

Unknown use of instruction mnemonic with unknown size suffix

我该如何解决?

该代码不需要使用内联汇编.但是,我还没有找到使用Objective-C/C ++/C指令执行此操作的方法.

The code does not need to use inline assembly. However, I haven't found a way to do this using Objective-C / C++ / C instructions.

推荐答案

要在标准C语言中执行此操作,您可以执行以下操作:

To do this in standard C, you can do:

var = (var << shift) | (var >> (sizeof(var)*CHAR_BIT-shift))

大多数编译器都会识别该模式并将其优化为一条指令(如果目标支持的话).

Most compilers will recognise that pattern and optimise it to a single instruction (if the target supports it) anyway.

您可以在此处了解更多信息: http://en.wikipedia.org/wiki/Circular_shift# Implementing_circular_shifts

You can read more here: http://en.wikipedia.org/wiki/Circular_shift#Implementing_circular_shifts

这篇关于在Objective-C中使用内联汇编对变量进行ROL/ROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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