News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Disassembly question

Started by rags, September 23, 2007, 02:15:18 AM

Previous topic - Next topic

rags

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
God made Man, but the monkey applied the glue -DEVO

Jackal

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.

zooba

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

rags

God made Man, but the monkey applied the glue -DEVO