如何解决如何将此代码从 Intel(nasm) 转换为 AT&T(gas) 语法?
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)
我知道 dq 是 .long。我可以翻译第一部分:
gdt64:
.long 0 // zero entry
.code = . - gdt64
但是如何翻译这样的行:
dq (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)
解决方法
首先,NASM 中的 dq
组装了一个 8 字节的四字,而 x86 GAS 中的 .long
是一个 4 字节的双字,所以这不是您想要的。正确的等价物是 .quad
。
您的 (1<<53) | ...
只是一个使用类似 C 的移位和按位运算符的算术表达式,而 dq (1 << 53) | ...
组装了一个四字,其值是该表达式的结果。 GAS 也接受这种语法,所以你可以简单地写
.quad (1<<53) | (1<<47) | (1<<46) | (1<<45) | (1<<44) | (1<<43)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。