Author Topic: 64 bit masm program structures  (Read 146 times)

markallyn

  • Member
  • **
  • Posts: 63
64 bit masm program structures
« on: September 30, 2017, 07:06:30 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: 64 bit masm program structures
« Reply #1 on: September 30, 2017, 10:17:16 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

markallyn

  • Member
  • **
  • Posts: 63
Re: 64 bit masm program structures
« Reply #2 on: October 01, 2017, 12:40:01 AM »
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:

Quote
include \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

  • Member
  • *****
  • Posts: 1704
Re: 64 bit masm program structures
« Reply #3 on: October 01, 2017, 03:27:05 AM »
Hi markallyn,

Code: [Select]
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

  • Member
  • **
  • Posts: 63
Re: 64 bit masm program structures
« Reply #4 on: October 01, 2017, 05:16:19 AM »
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