News:

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

Main Menu

Mean MASM64 bugs

Started by jj2007, July 19, 2016, 08:29:09 AM

Previous topic - Next topic

jj2007

We all know that ML64 was not meant for assembly programming: no invoke, no .if, nothing useful that was invented in the 21th century 8)

But there are workarounds for Real MenTM, like .if macros etc, so one should not totally exclude the option of using ML64.

However, one should be aware that certain nerds at Microsoft are responsible for this product, and in contrast to Habran, Johnsa and nidud, they have not outed themselves as members of this forum. So they are not reachable in case of bugs.

Nonetheless, I hope they are at least lurkers here, therefore: Redmond, this is your thread! In case you are interested to know about your bugs, that is... :biggrin:

; OPT_64   1               ; sets environment variable o64
; OxPT_Assembler AsmC      ; WndProc has 4 arguments in 32 bytes
; OxPT_Assembler JWasm     ; WndProc has 4 arguments in 32 bytes
; OxPT_Assembler ML64      ; WndProc has 5 arguments in 40 bytes for (x64) Version 10.00.30319.01
; OxPT_Assembler ML        ; WndProc has 4 arguments in 16 bytes

if @Environ(o64)
DefSize equ <QWORD>
eof$ equ <end>
else
DefSize equ <DWORD> ; int, long, and pointer are 32-bit
eof$ equ <end start>
.686p
.model flat, stdcall
endif

MyProlog MACRO procname, flags, argbytes, localbytes, reglist, userparms
Local tmp$, ctArgs
  ctArgs=argbytes/DefSize
  tmp$ CATSTR <procname has >, %ctArgs, < arguments in >, %argbytes, < bytes>
  % echo tmp$
  EXITM <localbytes>
ENDM

.code
OPTION PROLOGUE:MyProlog

WndProc proc hWnd:DefSize, uMsg:DefSize, wParam:DefSize, lParam:DefSize
LOCAL var1, var2
  ret
WndProc endp

start proc
start endp
  .err ; see assembler messages instead of no console output
  ret
eof$


P.S.: Hilarious workaround for this one: Use a dummy proc with a known # of args to set a bug correction equate 8)

hutch--

#1
 :biggrin:

MASM does not have bugs, it just has features you need to understand.  :P

If you either allocate a LOCAL or place an argument after the "proc" statement, you produce a stack frame as shown in the disassembly below.


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

    include \masm64\include\masm64rt.inc

    setframe equ <anon:QWORD>

    .code

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

entry_point proc setframe

    mov rcx, 1
    mov rdx, 2
    mov r8, 3
    mov r9, 4
    call testproc

    ret

entry_point endp

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

testproc proc arg1:QWORD,arg2:QWORD,arg3:QWORD,arg4:QWORD

    mov QWORD PTR [rbp+10h], rcx
    mov QWORD PTR [rbp+18h], rdx
    mov QWORD PTR [rbp+20h], r8
    mov QWORD PTR [rbp+28h], r9

    ret

testproc endp

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

    end

.text:0000000140001000 enter 0x40, 0x0
.text:0000000140001004 mov rcx, 0x1
.text:000000014000100b mov rdx, 2
.text:0000000140001012 mov r8, 3
.text:0000000140001019 mov r9, 4
.text:0000000140001020 call sub_140001027
.text:0000000140001025 leave
.text:0000000140001026 ret
; --------------------------------------------------------------------------
; sub_140001027
; --------------------------------------------------------------------------
sub_140001027   proc
.text:0000000140001027 enter 0x40, 0x0
.text:000000014000102b mov qword ptr [rbp+0x10], rcx
.text:000000014000102f mov qword ptr [rbp+0x18], rdx
.text:0000000140001033 mov qword ptr [rbp+0x20], r8
.text:0000000140001037 mov qword ptr [rbp+0x28], r9
.text:000000014000103b leave
.text:000000014000103c ret
sub_140001027   endp