News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Re: Latest 64 bit macro file.

Started by jj2007, April 27, 2021, 09:57:12 AM

Previous topic - Next topic

jj2007

Any idea why this crashes with an exception?
include \masm32\include64\masm64rt.inc

entry_point proc
  print "Hello World"
  invoke ExitProcess, 0
entry_point endp

end


Btw Firefox complains that there is a virus or malware in the archive. It does so for practically all attachments posted here. In this case, for a plain text file. I submitted a bug report at Mozilla.

hutch--

It doesn't here. Just add a .code label.

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

    include \masm32\include64\masm64rt.inc

    .code

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

entry_point proc
  ; print "Hello World"

  conout "Howdy Awl",lf

  waitkey

  invoke ExitProcess, 0

entry_point endp

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

    end

jj2007

Oops, you are right, I forgot the .code! But it doesn't depend on that, unfortunately:
include \masm32\include64\masm64rt.inc

.code ; with or without, doesn't matter
entry_point proc
  conout "Hellooo...",lf ; works fine
  print "Hello World" ; <<<<<<<< crashes
  invoke ExitProcess, 0
entry_point endp

end

0000000140001000 | C8 8000 00               | enter 80,0               |
0000000140001004 | 48:83EC 60               | sub rsp,60               |
0000000140001008 | 48:8B0D 5C200000         | mov rcx,[14000306B]      | 000000014000306B:&"Hellooo..."
000000014000100F | E8 3C000000              | call <sub_140001050>     |
0000000140001014 | 48:8B0D 5B200000         | mov rcx,[140003076]      |
000000014000101B | E8 30000000              | call <sub_140001050>     |
0000000140001020 | 48:8B0D 65200000         | mov rcx,[14000308C]      | 000000014000308C:&"Hello World"
0000000140001027 | 48:C7C2 00000000         | mov rdx,0                | rdx:EntryPoint
000000014000102E | E8 8D000000              | call <sub_1400010C0>     |
0000000140001033 | 48:8B0D 72200000         | mov rcx,[1400030AC]      | 00000001400030AC:&"Hello World"
000000014000103A | E8 11000000              | call <sub_140001050>     |
000000014000103F | 48:C7C1 00000000         | mov rcx,0                |
0000000140001046 | FF15 D8210000            | call [<&RtlExitUserProce |

... print:
00000001400010C0 | C8 8000 00               | enter 80,0               |
00000001400010C4 | 48:81EC 80000000         | sub rsp,80               |
00000001400010CB | 4C:8965 88               | mov [rbp-78],r12         |
00000001400010CF | 48:894D 10               | mov [rbp+10],rcx         |
00000001400010D3 | 48:8955 18               | mov [rbp+18],rdx         | rdx:EntryPoint
00000001400010D7 | 4C:8945 20               | mov [rbp+20],r8          |
00000001400010DB | 4C:894D 28               | mov [rbp+28],r9          | r9:EntryPoint
00000001400010DF | 48:894D 90               | mov [rbp-70],rcx         |
00000001400010E3 | 48:8955 80               | mov [rbp-80],rdx         | rdx:EntryPoint
00000001400010E7 | 48:C745 98 00000000      | mov [rbp-68],0           |
00000001400010EF | 49:C7C4 20000000         | mov r12,20               | 20:' '
00000001400010F6 | 48:8B4D 90               | mov rcx,[rbp-70]         |
00000001400010FA | 4A:8B5425 00             | mov rdx,[rbp+r12]        | rdx:EntryPoint
00000001400010FF | 4C:8B45 98               | mov r8,[rbp-68]          |
0000000140001103 | E8 28000000              | call <sub_140001130>     |
0000000140001108 | 48:8945 98               | mov [rbp-68],rax         |
000000014000110C | 49:83C4 08               | add r12,8                |
0000000140001110 | 48:836D 80 01            | sub [rbp-80],1           |
0000000140001115 | 75 DF                    | jne 1400010F6            |
0000000140001117 | 48:8B45 98               | mov rax,[rbp-68]         |
000000014000111B | 4C:8B65 88               | mov r12,[rbp-78]         |
000000014000111F | C9                       | leave                    |
0000000140001120 | C3                       | ret                      |

...inside print:
0000000140001130 | 4C:8BC9                  | mov r9,rcx               | rcx:"Hello World"
0000000140001133 | 48:8BCA                  | mov rcx,rdx              | rcx:"Hello World"
0000000140001136 | 4D:03C8                  | add r9,r8                |
0000000140001139 | 48:C7C0 FFFFFFFF         | mov rax,FFFFFFFFFFFFFFFF |
0000000140001140 | 48:83C0 01               | add rax,1                |
0000000140001144 | 48:0FB61401              | movzx rdx,[rcx+rax]      | rcx+rax*1:"llo World" <<<<<<<< CRASH <<<
0000000140001149 | 41:881401                | mov [r9+rax],dl          |
000000014000114D | 48:85D2                  | test rdx,rdx             |
0000000140001150 | 75 EE                    | jne 140001140            |
0000000140001152 | 49:03C0                  | add rax,r8               |
0000000140001155 | C3                       | ret                      |

hutch--


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

    include \masm32\include64\masm64rt.inc

    .code

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

entry_point proc

    LOCAL pmem  :QWORD

    mov pmem, alloc(2048)

    print pmem,"Howdy Awl",lf,str$(12345678),lf,"This is a test",lf

    waitkey

    .exit

entry_point endp

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

    end

;     print MACRO pmem:REQ,args:VARARG
;       mcat pmem, args
;       invoke StdOut,pmem
;     ENDM

It should have an mfree to release the allocated memory.

jj2007


jj2007

This works like a charm, but the SYSTEMTIME structure is missing in the SDK:

include \masm32\include64\masm64rt.inc
SYSTEMTIME STRUCT
  wYear             WORD      ?
  wMonth            WORD      ?
  wDayOfWeek        WORD      ?
  wDay              WORD      ?
  wHour             WORD      ?
  wMinute           WORD      ?
  wSecond           WORD      ?
  wMilliseconds     WORD      ?
SYSTEMTIME ENDS

.data
wFatDate WORD 1+32*5+32*16*(2021-1980)
wFatTime WORD 0
ftime FILETIME <>
stime SYSTEMTIME <>

.code
entry_point proc
  invoke DosDateTimeToFileTime, wFatDate, wFatTime, addr ftime
  invoke FileTimeToSystemTime, addr ftime, addr stime
  conout "Today is the ", str$(stime.wDay), ".", str$(stime.wMonth), ".", str$(stime.wYear)
  invoke ExitProcess, 0
entry_point endp

end

greenozon

I came across the same question:
why does the \masm64\include64\win64.inc  missing SYSTEMTIME  struct definition?
also if we compare win64.inc (masm64) to windows.inc  from masm32 it's like 200KB less... why such a decisiion was taken... just wondering

BugCatcher

Does the linker command  /ENTRY:entry_point create a code section?

TimoVJL

only tells linker to use that symbol.

/ENTRY (Entry-Point Symbol)

MS linker knows these symbols internally:
[w]mainCRTStartup for CONSOLE app
[w]WinMainCRTStartup for GUI app
_DllMainCRTStartup for DLL
May the source be with you