- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
Linux 64.AT&T。
GCC 4.8.2(带 -O3 -march=native)
我左手下的x86_64 abi,在第21页打开。
为了明确意图,这里是想法:
int32_t res[] = {0,0,0,0};
int32_t primo[] = {5,8,50,150};
for (int32_t x = 0; x < 4; ++x) {
res[x] = primo[x];
}
printf("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
检测到错误:
Error: `(%rsp,%esi,4)' is not a valid base/index expression
代码:
int32_t res[] = {0,0,0,0};
int32_t primo[] = {5,8,50,150};
int32_t counter = 0;
__asm__ volatile(
"start_loop:\n\t"
"movl (%1,%2,4), (%0,%2,4)\n\t"
"addl $1, %2\n\t"
"cmp $4, %2\n\t"
"jne start_loop"
: "=&r"(res)
: "r"(primo),"r"(counter)
:"cc"
);
printf("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
...
start_loop:
movl (%rsp,%edx,4), (%si,%edx,4)
addl $1, %edx
cmp $4, %edx
jne start_loop
...
如何表达正确的代码?我哪里做错了?
谢谢
将流水线改成
时movl (%rsp,%rdx,4), (%rsi,%rdx,4)
我明白了
错误:“mov”的内存引用过多
什么??
对于读者来说,似乎我的系统很特别,因为它不会放入正确的指令大小。
我必须以 int64_t
为例手动键入我的变量,以强制 r*x 事件发生。如果 c11/c++11 使用 uintptr_t
类型。
否则,gcc 会坚持使用 32 位版本,这会导致无效的基数/索引错误。
它咬了我好几次。我希望它现在不会适合你。
最佳答案
现在关闭 ABI 文档,打开 intel 手册、基本架构和指令集引用:->
首先,mov
不接受两个内存操作数,您必须通过寄存器或使用专门的字符串移动movs
。其次,在有效地址中不能混合使用 16、32 和 64 位寄存器。鉴于您的代码片段中的类型,编译器为您替换了 16 位寄存器非常可疑。此外,由于不可能的约束,它甚至不应该编译,res
是一个数组,你不能将它用作输出。此外,您正在更改 counter
变量,但您没有告诉编译器。
gcc 内联汇编是一个非常复杂的东西。如果可能,最好避免使用它,尤其是如果您是初学者,否则您将与编译器作斗争而不是学习汇编。
固定版本可能如下所示:
#include <stdint.h>
#include <stdio.h>
int main()
{
int32_t res[] = {0,0,0,0};
int32_t primo[] = {5,8,50,150};
int32_t counter = 0;
int32_t tmp;
__asm__ volatile(
"start_loop:\n\t"
"movl (%3, %q1, 4), %0\n\t"
"movl %0, (%2, %q1, 4)\n\t"
"addl $1, %1\n\t"
"cmp $4, %1\n\t"
"jne start_loop"
: "=&r" (tmp), "+r" (counter)
: "r" (res), "r"(primo)
: "cc", "memory"
);
printf("%d %d %d %d\n", res[0], res[1], res[2], res[3]);
return 0;
}
关于linux - 程序集 - 内联 asm - 从一个数组复制到另一个数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28645466/
我需要处理来自旧 Mac 时代(旧摩托罗拉 CPU)的文件。字节是大端字节序,所以我有一个函数可以将 Int64 交换为英特尔小端字节序。该函数是 ASM,可在 32 位 CPU 上运行,但不能在 6
1.概述 转载:史上最通俗易懂的ASM教程 一勺思想 We are all in the gutter, but some of us are looking at the stars. (我们都生活
1.概述 转载:ASM 与 Presto 动态代码生成简介 代码生成是很多计算引擎中常用的执行优化技术,比如我们熟悉的 Apache Spark 和 Presto 在表达式等地方就使用到代码生成技术。
我想在 C++ 程序中使用 ASM 调用地址为 774a7fdch 的函数(kernel32.dll 函数) 我正在使用 Visual Studio 2010。 我该怎么做? call 774a7fd
我是否正确转换了它? 原始 VS C++ 版本: _TEB *pTeb = NULL; _asm { mov eax, fs:[0x18];
阅读自howto_add_systemcall "In general, header files for machine architecture independent system calls
在实现无锁数据结构和时序代码时,通常需要抑制编译器的优化。通常人们使用 asm volatile 和 clobber 列表中的 memory 来执行此操作,但有时您只会看到 asm volatile
这个“strcpy”函数的目的是将src的内容复制到dest,结果很好:显示两行“Hello_src”。 #include static inline char * strcpy(char * de
我正在尝试进行一些汇编编码,我从 C 语言调用函数。代码本身运行良好,但我有两个巨大的问题在很长一段时间内无法解决。第一个是语法高亮 - 我安装了两个不同的(当时一个)asm 高亮扩展到 Visual
我正在研究一些类文件分析,并且正在研究使用 ASM 来读取类。在 Javap 中,操作码以及 tagName 和 tagValue 是内联打印的,但在每个 AbstractInsnNode 中,我只看
我正在尝试弄清楚如何将 ASM 中的 DB 变量用于内联 ASM C++ 我有这个 ASM 代码: filename db "C:\imagen.bmp" eti0: mov ah,3dh mov a
这个“strcpy”函数的目的是将src的内容复制到dest,结果很好:显示两行“Hello_src”。 #include static inline char * strcpy(char * de
在 mm/memory.c 中,它包含一个文件: #include tlb.h 是 include/asm-generic/tlb.h或 arch/arm/include/asm/tlb.h ? 最
你好我找到了一个asm代码......它被集成到c++项目中 template T returned; BYTE *tem = buffer; __asm { mov eax, tem
问题:当我运行 @ 命令提示符 >tasm HelloWorld.asm 顺便说一句,我在输入文件名 HelloWorld.asm 时使用 TAB,所以没有错字.我收到这个致命的命令行错误: Turb
尝试通过 eax 从 asm proc 返回一个 long int,后来又尝试通过 dx:ax。两者都不适合我,因为 C printf 打印的数字与所需的 320L 不同。 x.asm: .model
这是 godbolt 生成的代码. 下面是 Visual Studio 在我的 main.asm 文件上生成的相同代码(通过 Project->C/C++->Output Files->Assembl
在构建具有依赖项的 giraph jar 时,我们收到以下警告.. 真的不知道如何解决这些.. 我们已经尝试过了 useProjectArtifact 为 false 和 解压为真 两者似乎都有效 任
我正在使用 gentoo 并尝试编译一个程序来控制并行端口上的位。它的顶部附近有这条线: #include 当我尝试在其上使用 gcc 时,它会产生以下输出: port.c:4:20: error:
(原帖)将 hibernate 依赖项添加到 pom.xml 时显示错误 2011-10-11 10:36:53.710::WARN: failed guiceFilter java.lang.No
我是一名优秀的程序员,十分优秀!