简体   繁体   English

如何将此代码从 Intel(nasm) 转换为 AT&T(gas) 语法?

[英]How to translate this code from Intel(nasm) to AT&T(gas) syntax?

gdt64:
  dq 0 ; zero entry
.code: equ $ - gdt64
  ; 0x08 kernel CS 0x8
  ; bits set: descriptor type, present, executable, 64bit
  dq (1<<53) | (1<<47) |                     (1<<44) | (1<<43) ; kernel
  ; 0x10 user CS
  ; works when its set to kernel mode, but when in user mode, it doesnt, duh
  ;dq (1<<53) | (1<<47) |                     (1<<44) | (1<<43) ; kernel
  dq (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

I understand that dq is.long.我知道 dq 是.long。 And I can translate first part of this:我可以翻译第一部分:

gdt64:
  .long 0 // zero entry
.code = . - gdt64

But How to translate line like this:但是如何翻译这样的行:

  dq (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

First of all, dq in NASM assembles an 8-byte quadword, whereas .long in x86 GAS is a 4-byte doubleword, so that's not what you want.首先,NASM 中的dq组装一个 8 字节的四字,而 x86 GAS 中的.long是一个 4 字节的双字,所以这不是你想要的。 The correct equivalent is .quad .正确的等价物是.quad

Your (1<<53) |... is just an arithmetic expression using C-like shift and bitwise operators, and dq (1 << 53) |... assembles a quadword having as its value the result of this expression.您的(1<<53) |...只是一个使用类 C 移位和按位运算符的算术表达式,而dq (1 << 53) |...组装了一个四字,其值为该表达式的结果。 GAS accepts this syntax as well, so you can simply write GAS 也接受这种语法,所以你可以简单地写

.quad (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM