flat assembler
Message board for the users of flat assembler.
Index
> Main > I found strange asm x86 output code |
Author |
|
Tomasz Grysztar 26 Dec 2018, 16:04
Roman wrote:
As for "_src$[ebp]", it is a syntax borrowed from C - this is a pointer arithmetic expressed analogously to how C language allowed it, with square brackets being a fancy way to write down an addition of an offset to a pointer. You could even add multiple terms in separate sets of square brackets there. Back in the day, many people disliked this C-originated syntax in assembly language. Perhaps because they preferred languages more in spirit of Pascal, but much more likely because they simply disliked the messiness and lack of consistent indication when an operand is a memory. Sometimes it could be signaled by use of square brackets (in case of plain operands like [BX]), but usually not. You can see an opinion on some flaws of this syntax preserved in NASM documentation. The worst sin of MASM's syntax was that presence of PTR keyword was not a guarantee that operand would be a memory access, seemingly contrary to any logic. For many of us this was a mark of a truly horrible syntax. This reaction led to development of alternative syntaxes, notably an Ideal mode of Borland's TASM assembler (a mode that you could select instead of default MASM-compatible one). It was a syntax that required all memory operands to use square brackets, and they had to wrap around entire operand. The square brackets would no longer be a C-like pointer addition operator, they would be solely an indication of x86 memory operand. In TASM's Ideal mode the above instruction would look like: Code: mov eax, [DWORD _src$+ebp] Then came assemblers like NASM and my FASM, that evolved this concept further, moving the size override outside of square brackets. Idea was that size operator could precede any kind of operand and therefore should come first. This allowed a size override inside square brackets to take on a different meaning, indicating the size of the address and not of the operand (something that could come in handy sometimes when developing on 386+ machines where a 67h prefix could be used to make an instruction use a different addressing mode that default). Nevertheless, PTR keyword is implemented in FASM, too. Here it acts as an alternative to square brackets to specify memory operand. So you either use square brackets or PTR, but never both at the same time. Code: mov eax, DWORD [ebp+_src$] mov eax, DWORD PTR ebp+_src$ ; both are correct for FASM, and mean the same |
|||
26 Dec 2018, 16:04 |
|
Roman 26 Dec 2018, 16:52
Thanks !
|
|||
26 Dec 2018, 16:52 |
|
sinsi 26 Dec 2018, 23:24
To add to the MASM side, these are all legal
Code: mov eax, DWORD PTR _src$[ebp] mov eax, DWORD PTR [ebp+_src$] mov eax, _src$[ebp] mov eax, [ebp+_src$] DWORD PTR is assumed, since you are loading EAX. If it's ambiguous you need the override Code: mov _src$[ebp],0 ;will throw an error - 0 could be a byte/word/dword mov DWORD PTR _src$[ebp],0 |
|||
26 Dec 2018, 23:24 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.