The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: jj2007 on October 06, 2016, 09:33:02 PM

Title: No retn in ML64
Post by: jj2007 on October 06, 2016, 09:33:02 PM
  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

Title: Re: No retn in ML64
Post by: MichaelW on October 06, 2016, 10:22:06 PM
Did not ML32 equate ret to retn? Does ML64 recognize retf?
Title: Re: No retn in ML64
Post by: jj2007 on October 07, 2016, 12:21:27 AM
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.
Title: Re: No retn in ML64
Post by: hutch-- on October 07, 2016, 12:23:54 AM
 :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