本文介绍了你怎么知道x86中寄存器的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么知道如何在下面的汇编代码中填写下划线:

mov_ %eax, (%rsp)

b"代表字节,w"代表字,l"代表双字,或q"代表四元.寄存器的语法应该(我认为)指示移动了多少数据.我翻阅了我的书,似乎无法确定这是如何确定的.

有没有通用的方法来解决这个问题?

解决方案

如果 mov 的一个操作数是一个寄存器,那么大小是隐含的:AL 是一个字节,AX 两个,EAX 四个,RAX 八个.如果一个操作数是内存位置而另一个是立即数,必须指定所需的大小:

mov BYTE PTR [RAX], 1 ;*(uint8_t *)(rax) = 1mov WORD PTR [RAX], 1 ;*(uint16_t *)(rax) = 1mov DWORD PTR [RAX], 1 ;*(uint32_t *)(rax) = 1mov QWORD PTR [RAX], 1 ;*(uint64_t *)(rax) = 1

以上是架构手册中使用的 Intel 语法.在 AT&T 语法中,第一行是 movb $1, (%rax);AT&T 语法使用诸如 movbmovwmovdmovq 等后缀指令来表示操作数宽度.>

How would you know how to fill in the underscore in the following assembly code:

mov_ %eax, (%rsp)

It's either "b" for byte, "w" for word, "l" for double word, or "q" for quad. The syntax of the registers is supposed to (I think) indicate how much data is getting moved. I've looked through my book and can't seem to sort how this is determined.

Is there a general way of figuring this out?

解决方案

If one operand of mov is a register, then the size is implied: AL is one byte, AX two, EAX four and RAX eight. If one operand is a memory location and the other an immediate value, you have to specify the desired size:

mov  BYTE PTR [RAX], 1    ;  *(uint8_t *)(rax) = 1
mov  WORD PTR [RAX], 1    ; *(uint16_t *)(rax) = 1
mov DWORD PTR [RAX], 1    ; *(uint32_t *)(rax) = 1
mov QWORD PTR [RAX], 1    ; *(uint64_t *)(rax) = 1

The above is Intel syntax as used by the architecture manual. In AT&T syntax, the first line would be movb $1, (%rax); AT&T syntax uses suffixed instructions like movb, movw, movd and movq to indicate operand widths.

这篇关于你怎么知道x86中寄存器的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 16:23
查看更多