News:

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

Main Menu

64 bit masm program structures

Started by markallyn, September 30, 2017, 07:06:30 AM

Previous topic - Next topic

markallyn

Hello everyone,

Still working on my education.  Here is a small program that multiplies to integers via a procedure called from a start: end start
block.  It won't assemble.  I can't figure why unless 64 bit rules have changed.  Anyway, here it is:

Quote
/include \masm32\include64\masm64rt.inc

printf PROTO :QWORD, :VARARG
mult2ints PROTO :QWORD, :QWORD

.data
frmt1   BYTE   "%d",13,10,0

.code
start:

mov   rax, 10
mov   rdx, 20

invoke    mult2ints, rax, rdx
invoke   printf, frmt1, rax
invoke   ExitProcess, 0


mult2ints PROC   val1:QWORD, val2:QWORD
mov   rbx, val1
mov   rcx, val2
imul   rbx, rcx
mov   rax, rbx
ret
mult2ints ENDP
end start

The assembler kicks out 2 error message, one line 27 and the other for line 33.  Line 37:  "syntax error : start"; line 33: "END directive required at end of file.  Adding an END" after "end start" makes the latter complaint go away, but the "start" syntax error remains. 

I've looked at a lot of 32-bit masm code to understand this, but the examples (Including Iczelion's) all follow the structure shown herein.  Was there some change in 64 bits that invalidates this structure?

Regards to all,
Mark Allyn

hutch--

Mark,

This one caught me when I first started on 64 bit MASM. You need to put your startup code in a procedure. I did all of mine with a start procedure called "entry_point" and you put this on the link command line so the linker finds the entry point.

/ENTRY:entry_point

Use any name you like as long as you tell the linker the start procedure.

markallyn

Good morning from SouthEastern Penn.,

Thanks for your help.  So, I made the changes I think you were suggesting.  The new program looks like this:

Quoteinclude \masm32\include64\masm64rt.inc

printf PROTO :QWORD, :VARARG
mult2ints PROTO :QWORD, :QWORD

.data
frmt1   BYTE   "%d",13,10,0

.code
main   PROC

mov   rax, 10
mov   rdx, 20

invoke    mult2ints, rax, rdx
invoke   printf, frmt1, rax
ret
main   ENDP

mult2ints PROC   val1:QWORD, val2:QWORD
mov   rbx, val1
mov   rcx, val2
imul   rbx, rcx
mov   rax, rbx
ret
mult2ints ENDP
END

This one assembles and links without a problem.  However, it crashes immediately and with no information.  Unfortunately, I don't have a working 64 bit debugger so I'm rather out of luck troubleshooting.  I'm in the market for one, but thus far I've not had any luck.

Vortex

Hi markallyn,

include \masm32\include64\masm64rt.inc

printf      PROTO :QWORD,:VARARG
mult2ints   PROTO :QWORD,:QWORD

.data

frmt1       BYTE    "%d",13,10,0

.code

main PROC

    invoke  mult2ints,10,20
    invoke  printf,ADDR frmt1,rax
    invoke  ExitProcess,0

main ENDP

mult2ints PROC val1:QWORD, val2:QWORD

; rcx -> val1
; rdx -> val2

    imul    rcx,rdx
    mov     rax, rcx
    ret
   
mult2ints ENDP

END

markallyn

Vortex--

Thanks very much.  Super informative.  I had been wondering about the invoke macro and how it handled the 64-bit calling convention.  You explained it.

Mark