flat assembler
Message board for the users of flat assembler.
Index
> Linux > a more basic ELF64 example? |
Author |
|
Feryno 13 Sep 2006, 05:44
AMD64 CPU in long mode (64-bit) zero extends operations with 32-bit GPR (general purpose registers) into the whole 64-bit register. You can use this feature to reduce code size, because using 64-bit register requires 1 extra byte for REX opcode prefix. You can easily mistake with this feature, like when you do this: cmp eax,... the upped dword of RAX is zeroed.
If you want to put like 1 into rax, you can use mov eax,1 xor edi,edi is one old assembler trick to put 0 into register. ASM coders like it because opcode size is only 2 bytes instead of 5 bytes for mov edi,0. The most of asm coders like asm because they can reduce program size using their art and mind... another example for reduce code size is or rax,rax ; you can do other choices here: and rax,rax... test rax,rax jz... instead of cmp rax,0 / jz Please use this to improve you code: ... db '1','2','3', 0Ah To find more ELF64 examples - please try to search flatassembler.net page more carrefuly Last edited by Feryno on 14 Sep 2006, 04:59; edited 1 time in total |
|||
13 Sep 2006, 05:44 |
|
DrenThales 13 Sep 2006, 18:23
ok, that makes sense, machine-code wise
Do you know of any opcode size listings for AMD64? Or how to retrieve the opcode size of a particular instruction? Also, as to the size growth caused by REX prefix, is that something inherit in use of 64-bit registers?, or is it just the price paid for legacy 32-bit support? (if they made a pure 64-bit processor, ie no 32-bit legacy, would it even need the REX prefix?) In any case though, as to the ELF file format, I think that, instead, I'll just use flat binary, for the time being [ edit: ...or not..., how would I test execution with flat binary? ] I assume the reason you used an uppercase 'A' instead of 'a' in your '0Ah' hex number is ease of reading? Is it typical for assembler programmers to prefer upper case letters when reading hex numbers? (I suppose it helps keep it separate from the base prefix at the end, ie the 'h' and such, for one thing) |
|||
13 Sep 2006, 18:23 |
|
vid 13 Sep 2006, 19:51
Quote: Do you know of any opcode size listings for AMD64? see AMD manuals... it depends on many things.. for example simple address can have 1 to 6 bytes.. there can be several optional prefixes... don't try to find some system in it, processor done to be efficient (and unfortunately, backward-compatible), not to be "clean" Quote: Or how to retrieve the opcode size of a particular instruction? Quote: Also, as to the size growth caused by REX prefix, is that something inherit in use of 64-bit registers?, or is it just the price paid for legacy 32-bit support? (if they made a pure 64-bit processor, ie no 32-bit legacy, would it even need the REX prefix?) if they would make pure 64bit, they will loose backward compatibility, and save one byte for REX prefix, but loose 4 bytes with every constant, because it would have to be 64bit constant, instead of 32bit. Quote: I assume the reason you used an uppercase 'A' instead of 'a' in your '0Ah' hex number is ease of reading? Is it typical for assembler programmers to prefer upper case letters when reading hex numbers? (I suppose it helps keep it separate from the base prefix at the end, ie the 'h' and such, for one thing) yes, i would say it's because of ease of reading, and it is good standard among asmers. for example, the space looks more equally filled with upcase letters in dump: 0A 4B 4C FF 13 20 2D than with lowcase, where a-f visually appears to be something other than 0-9, but they are all digits: 0a 4b 4c ff 13 20 2d ... imho |
|||
13 Sep 2006, 19:51 |
|
Feryno 14 Sep 2006, 05:12
For opcode size, you can avoid to waste the time with manuals: use biew or other disassemblers, or debuggers.
Or use fdbg for Linux AMD64 (maybe the smallest toy to do it at present time - look into projects and ides section of the forum) which shows you it after command: c c means 'code', you can use it without any param then it dumps code from RIP or from the end of its previous output, with params you can do something like c rip+2A c 40104c numbers there are hexa, I hadn't time to do it better (with h at the end) REX prefix is 1 extra byte only Yes, every programmer uses it's own style 0xA = 0xa = 0x0A = 0x0a = 0Ah = 0ah = 0AH = 0aH |
|||
14 Sep 2006, 05:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.