I am trying to learn Assembly, and, as for now, I only barely got started. I don't know much of the style conventions, since I haven't really looked into it yet.
I know comments begin with a semicolon, since the end of an instruction is marked with an end-of-line character (\n); most of the code examples I've seen separate with blank characters the semicolon and the comment from the instruction, as anyone would expect.
global some_rnd_labl
section .data
hifive dd 0x00000005
section .text
some_rnd_labl:
mov eax, [esp+4] ; Adds the second last item in the stack...
add eax, [esp+8] ; and then the third last one.
add eax, [hifive] ; Good job, accumulator! Hi-5!
mov edx, eax ; Now store the result in dx...
ret
However,
would it universally be considered bad practice to write the semicolon immediately next to the instruction, and only then put the blank characters, or is it just a matter of taste / subjective opinion?
...
mov eax, [esp+4]; Adds the second last item in the stack...
add eax, [esp+8]; and then the third last one.
add eax, [hifive]; Good job, accumulator! Hi-5!
mov edx, eax; Now store the result in dx...
...
The reason I'm asking this seemingly (and likely) self-answering question is the way I'm acquainted with C++ and Java, both of which end instructions with semicolons and mark inline comments with "//", and separating the comment marker from the comment itself could be unintuitive and/or misleading; I think that style is easier to read, but I'm not sure that the average programmer wouldn't find it less readable just because it is unusual.
EG, you could see:
; Assembly code for my compiler / OS / CPU
mov eax, [esp+4]; Adds the second last item in the stack...
as it's C++ ~counterpart:
// C++ based pseudocode
// (notice how the semicolon and "//" are mashed together)
std::vector<int> stack(DEFINED_ELSEWHERE);
int
var1 = stackArray[1];// Adds the second last item in the stack...
Yes, I realize this is a silly (and apparently non-objective) question, but I think it is still worth asking.
User contributions licensed under CC BY-SA 3.0