Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

assembly - 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. 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)
question from:https://stackoverflow.com/questions/65938270/how-to-translate-this-code-from-intelnasm-to-attgas-syntax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. The correct equivalent is .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. GAS accepts this syntax as well, so you can simply write

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...