组装"movdqa"访问冲突 [英] Assembly "movdqa" access violation

查看:77
本文介绍了组装"movdqa"访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试用汇编语言编写一个函数,我想将位于 rdx 中的内存地址处的字符串的128位移到 xmm1 寄存器中.

I am currently trying to write a function in assembly and i want to move 128 bits of a string located at the memory address stored in rdx into the xmm1 register.

如果我使用 movdqa xmm1 [rdx] ,则在位置 0xFFFFFFFFFFFFFFFFFFFF 读取时会遇到访问冲突异常.

If i use movdqa xmm1, [rdx], i get a access violation exception while reading at position 0xFFFFFFFFFFFFFFFF.

如果我尝试使用 movdqu xmm1,[rdx] ,我没有得到例外.问题是如果我使用movdqu,位的顺序将反转.

If i try to use movdqu xmm1, [rdx] instead, i dont get the exception. The problem is if i use movdqu, the order of the bits is inverted.

所以我不知道为什么在使用 movdqa 时会出现异常,但在使用 movdqu

So i do not know why i get an exception when using movdqa but not when i am using movdqu

推荐答案

大部分内容已在评论中提及,但让我总结一下.您的代码/问题提出了三个问题:

Most of this has been said in the comments already, but let me summarise. There are three problems raised by your code/question:

1) MOVDQA 要求其处理的地址(在您的情况下为 [rdx] )与16字节边界对齐,否则会触发访问冲突.这就是您所看到的.对齐到16字节(DQWORD)边界意味着,使用示例,您应该阅读例如 0xFFFFFFFFFFFFFFFFF0 而不是 0xFFFFFFFFFFFFFFFF ,因为后者不能被16整除.

1) MOVDQA requires the addresses it deals with ([rdx] in your case) to be aligned to a 16-byte boundary and will trigger an access violation otherwise. This is what you are seeing. Alignment to a 16-byte (DQWORD) boundary means that, using your example, you should read from e.g. 0xFFFFFFFFFFFFFFF0 rather than 0xFFFFFFFFFFFFFFFF, because the latter number is not divisible by 16.

2)您使用的地址 0xFFFFFFFFFFFFFFFFFF 几乎肯定是无效的.

2) The address you use, 0xFFFFFFFFFFFFFFFF, is almost certainly invalid.

3)假设您使用 MOVDQA 从有效的16字节对齐的内存位置读取,结果(在您的情况下为 xmm1 )将为当您使用 MOVDQU 时为IDENTICAL .两者之间唯一相关的区别是, movdqU 允许您从未对齐(因此为U)的 U 内存中读取,而 movdqA 则需要一个(16字节) A 限定的内存位置.(后一种情况通常会更快,但我认为您在此阶段无需担心.)

3) Provided you use MOVDQA to read from a valid 16-byte-aligned memory location, the results (in xmm1 in your case) will be IDENTICAL to when you use MOVDQU. The only relevant difference between the two here is that movdqU allows you to read from Unaligned (hence the U) memory whereas movdqA requires a (16-byte) Aligned memory location. (The latter case will often be faster, but I don't think you need to worry about that at this stage.)

这篇关于组装"movdqa"访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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