News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

No retn in ML64

Started by jj2007, October 06, 2016, 09:33:02 PM

Previous topic - Next topic

jj2007

  retn
  ret 0
  retn 0
  retn 1
  retn -1
  return 0  ; 32-bit macro
  return eax


C3                  retn
C3                  retn
C3                  retn
C2 0100             retn 1
C2 FFFF             retn 0FFFF
B8 00000000         mov eax, 0
C3                  retn
8BC0                mov eax, eax
C3                  retn


In contrast to 32-bit ML and the tested Watcom forks, ML64 doesn't know the retn instruction.

Workaround:
ifndef retn
retn equ <ret>
endif


MichaelW

Did not ML32 equate ret to retn? Does ML64 recognize retf?
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Quote from: MichaelW on October 06, 2016, 10:22:06 PM
Did not ML32 equate ret to retn? Does ML64 recognize retf?

Yes and yes.

hutch--

#3
 :biggrin:

It can't do PUSHAD / POPAD either, what's the point. RET works fine and unless you are trying to use 32 bit technology with push / call notation, you don't need to try and balance the stack if you don't modify it in the first place. Even with the option of no stack frame you don't need to balance the stack. It is a mistake to try and implement Win32 technology in Win64, they are different systems.

Intel on RET

Opcode  Instruction     Op/  64-Bit Compat/     Description
                        En   Mode   Leg Mode
----------------------------------------------------------------------------------------------------------------
C3      RET             NP   Valid  Valid       Near return to calling procedure.
CB      RET             NP   Valid  Valid       Far  return to calling procedure.
C2 iw   RET imm16       I    Valid  Valid       Near return to calling procedure and pop imm16 bytes from stack.
CA iw   RET imm16       I    Valid  Valid       Far  return to calling procedure and pop imm16 bytes from stack.
----------------------------------------------------------------------------------------------------------------

C2 and CA opcodes are for earlier systems with their 16 bit return count. It is not required in Win64.

If you have some need to emulate Win32 you can do it like this.
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include64\masm64rt.inc

    retn MACRO count
      db 0C2h
      dw count
    ENDM

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    LOCAL var  :QWORD
    LOCAL .rsp :QWORD

    mov var, 1234

    conout "rsp = ",str$(rsp),lf

    push var
    call testme

    conout "rsp = ",str$(rsp),lf

    waitkey
    invoke ExitProcess,0

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

NOSTACKFRAME

testme proc

    conout str$(QWORD PTR [rsp+8]),lf

    retn 8

testme endp

STACKFRAME

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end