Hacker News new | ask | show | jobs
by joebo 4198 days ago
This greatly helped my understanding of how compilers work.

How different would the implementation be for x64? Would it primarily be a matter of translating opcodes and calling conventions? For example, pop ecx is 59 [1], and on x64 it looks like it would be pop rcx, which is also 59 [2][3].

[1] - http://sparksandflames.com/file/x86InstructionChart.html

[2] - https://defuse.ca/online-x86-assembler.htm#disassembly

[3] - http://msdn.microsoft.com/en-us/library/windows/hardware/ff5...

1 comments

For x64 under both *nix and Windows sizeof(int) remains at 4 while the sizes of pointers increase to 8 bytes (64 bits), so anything in the compiler that depends on those sizes would also have to change. As for the opcodes, with x86/x64 it's a little weird since 64-bit mode actually defaults to 32-bit data sizes and uses mostly the same opcodes as 32-bit mode, with a prefix byte needed to override this to 64 bits. Addresses default to 64 bits, however. The 32-bit environment is "nice" in that pointers and integers are the same size; not true for most 64-bit in general (http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_mo... )

But still, trying to fit the x64 version in 64 lines is probably going to be the harder problem. ;-)