News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

RET issue inside an .IF block

Started by Vortex, April 18, 2012, 08:31:51 PM

Previous topic - Next topic

Vortex

Assembling with Poasm V7.00.0,  the following code will miss a RET instruction :


.386
.model flat, stdcall
option casemap :none

.code

main PROC

    .if eax == 0
        ret
    .endif
    ret

main ENDP

END main


The resulting object file disassembled with Agner Fog's objconv tool :



_text   SEGMENT PARA PUBLIC 'CODE'

_main@0 PROC NEAR
        test    eax, eax
        jnz     ?_001
        ret
_main@0 ENDP

_text   ENDS


A RET instruction at the end of the code is missing.

After disassembling the same code assembled with MS Macro Assembler Version 6.14.8444 :


_text   SEGMENT DWORD PUBLIC 'CODE'                     ; section number 1

_main@0 PROC NEAR
        or      eax, eax                                ; 0000 _ 0B. C0
        jnz     ?_001                                   ; 0002 _ 75, 01
        ret                                             ; 0004 _ C3

?_001:  ret                                             ; 0005 _ C3
_main@0 ENDP

_text   ENDS


This issue was reported by Masm forum members.
Code it... That's all...

AlexN

I am not very familiar with assembler, but isn't the second ret in your code obsolete. Perhaps POASM tries to optimize the output code (for translating compiler output) .

If it is part of a larger code sequense with the same result, forget this post. ;)
best regards
Alex ;)

Vortex

#2
Hi AlexN,

There is a problem concerning the RET instruction. An other example :

.386
.model flat, stdcall
option casemap :none

.code

main PROC x:DWORD,y:DWORD

    .if eax == 0
        xor ecx,ecx
        ret
    .endif

    ret

main ENDP

start:

     invoke main,10,20
     ret

END start


Output of Masm :



_text   SEGMENT DWORD PUBLIC 'CODE'

_main@8 PROC NEAR
        push    ebp
        mov     ebp, esp
        or      eax, eax
        jnz     ?_001
        xor     ecx, ecx
        leave       
        ret     8

?_001:  leave                                         
        ret     8                                     
_main@8 ENDP

_start  PROC NEAR
        push    20                                     
        push    10                                     
        call    _main@8                                 
        ret                                             
_start  ENDP

_text   ENDS


Output of Poasm :


_text   SEGMENT PARA PUBLIC 'CODE'

_main@8 PROC NEAR
        push    ebp
        mov     ebp, esp                               
        test    eax, eax                               
        jnz     _start                                 
        xor     ecx, ecx                               
        leave                                         
        ret     8                                     
_main@8 ENDP

_start  PROC NEAR
        push    20
        push    10
        call    _main@8
        ret             
_start  ENDP

_text   ENDS


Poasm should not direct the code execution to the _start label. The stack remains unbalanced after this jump.

jnz     _start
Code it... That's all...

Pelle

I can reproduce it - will look at it.
/Pelle

Vortex

Code it... That's all...