0

In this question: GCC-Assemby Error: Relocation R_X86_64_32S against '.data', is a example of 'hello world` in x64. I came on this, because I was finding a good GAS asm book with for x64 architecture (why to learn old 32bit asm), but most tutors and books are for 32 only. (such as profesional asm language, which is a lot recommended). My purpose, or why I even want to learn asm (GAS not nasm), is so I can understand kernel *.S files. But in the example above (first url) there is shown COMPLETELY different hello world in x64, then is in 32.

So my question is: How different is x64 from 32-bit x86 and how much does kernel use each other (that is the reason I want to learn x64)?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Herdsman
  • 799
  • 1
  • 7
  • 24
  • gas manual, intel manuals, abi pdf, kernel source. For generic kernel drivers you barely need any asm apart from the inline functions already provided. – Jester Jan 16 '20 at 19:55
  • but why does your program of x64 differ a lot from x86? – Herdsman Jan 16 '20 at 19:58
  • 2
    Depends on your definition of "a lot". It uses different conventions and has more registers which are of course 64 bit. Still, people tend to say that it's not a lot different because you still get to use most of the same instructions and you still have the 32/16/8 bit registers. – Jester Jan 16 '20 at 20:00
  • I am talking about the conventions, you said, you cannot imediate value to push. But why this convention in x64? what is the rational behind it, so you can push only from reg, and memory? – Herdsman Jan 16 '20 at 20:03
  • You can push an immediate just fine (`push 42` works). The calling convention uses registers to pass most arguments instead of the stack (conditions apply). This is faster and even 32 bit had a fastcall convention. – Jester Jan 16 '20 at 20:05
  • And, if you said, asm is not needed in kernel drivers and kernel modules, the when is real usage of asm in practice? Where you are using it? I thought embbeded systems needs it, which kernel modules could be – Herdsman Jan 16 '20 at 20:06
  • I've deleted the off-topic question from your post, otherwise your question would have to be closed. – Ross Ridge Jan 16 '20 at 20:06
  • 1
    The kernel already has all of the asm it requires such as setup code, interrupt, system call and signal handling, task switching. It also provides synchronization primitives and i/o access via inline functions. Device drivers just use those unless you are writing drivers for special things such as virtualization or hardware encryption. – Jester Jan 16 '20 at 20:08
  • @Jester again, then where does asm have REAL usage? – Herdsman Jan 16 '20 at 20:09
  • @Jester because I have read about embbeded systems. So if they are (embb. sys.) not a part e.g. custom kernel module (and thus there is no reason for usage of asm - as you are writing), then where is the true and desire usage of asm in real life? – Herdsman Jan 16 '20 at 20:20
  • 2
    @Herdsman Assembly is needed to access a device *interface* or in general a specific architecture interface (e.g. virtualization). But once you have **abstracted** these accesses, you don't need assembly anymore. Example: to access an IO port you use `in/out` on x86, but once you have a `READ_PORT_BYTE` (and similar) you don't need `in` anymore. Abstraction is good: portability and readability. – Margaret Bloom Jan 17 '20 at 18:38

0 Answers0