I was playing around with hll statements tonight to see how they get assembled using the disassembler that comes
with the masm project.
I assembled a program with this do nothing function:
main proc
mov eax, offset item
inc eax
@@:
.if byte ptr [eax -1] == NULL
jmp Done
.elseif (byte ptr [eax -1] == 1) || byte ptr [eax -1] == 2
add ecx,2
jmp Done
.endif
nop
nop
@@:
xor eax, eax
Done:
or eax, 1
ret
main endp
And this is the result:
00401025 fn_00401025:
00401025 B800304000 mov eax,403000h
0040102A 40 inc eax
0040102B 8078FF00 cmp byte ptr [eax-1],0
0040102F 7504 jnz @@1
00401031 EB17 jmp @@4
00401033 EB11 jmp @@3 ; <====This jump
00401035 @@1:
00401035 8078FF01 cmp byte ptr [eax-1],1
00401039 7406 jz @@2
0040103B 8078FF02 cmp byte ptr [eax-1],2
0040103F 7505 jnz @@3
00401041 @@2:
00401041 83C102 add ecx,2
00401044 EB04 jmp @@4
00401046 @@3:
00401046 90 nop
00401047 90 nop
00401048 33C0 xor eax,eax
0040104A @@4:
0040104A 83C801 or eax,1
0040104D C3 ret
My question is, does ML put code in the final program just to pad the exe to keep alignment or for some other reason?
Because otherwise the code 'jmp @@3' labeled 'this jump' would never be executed because it is preceeded by another
JMP instruction, and its location is not referenced by anyother location.
Thanks,
Rags
as i am just learning you may not be able to take this as correct but to me that jump is from the elseif. Not everyone will put a jump in the if as it should not be needed.
The high-level constructs in MASM are very simply implemented. There is no code optimisation performed whatsoever, all they provide is a different syntax for performing comparisons and automatically named labels. An .elseif will always insert a jump to the end of the block, regardless of what code exists before it.
And as Jackal pointed out, the idea of an .if/.else/.endif block is to avoid jmp/jcc instructions altogether, so adding a check for the block ending in an unconditional jump is theoretically unnecessary.
Cheers,
Zooba :U
Thanks Zooba. :thumbu