Author Topic: Masm failing when called from c++  (Read 438 times)

armedturret

  • Guest
Masm failing when called from c++
« on: February 23, 2018, 10:21:36 AM »
I am (attempting) to write a compiler for BASIC. I can successfully generate assembly code that compiles if I manually type in the command from the console but fails if I call it from c++ with create process.
This is my compiler output:
Code: [Select]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: C:\Users\rjwhi\Desktop\compilerexamples\Basic\tmp\tmp.asm
C:\Users\rjwhi\Desktop\compilerexamples\Basic\tmp\tmp.asm(1) : error A2088: END directive required at end of file
What's even more strange, is when I had it output the command generated, it worked fine but in a directory above the target.
Here is the command:
C:\masm32\bin\ml.exe /c /Zd /coff /I"C:\masm32\Include" "C:\Users\rjwhi\Desktop\compilerexamples\Basic\tmp\tmp.asm"
I would like to note I am just testing if it can assemble first before I link it.
The generated assembly code is as follows
Code: [Select]
.386
.model flat, stdcall
option casemap :none
include windows.inc
include kernel32.inc
include masm32.inc
includelib kernel32.lib
includelib masm32.lib
.data
PrintStr0 db "Hello world!",0
PrintStr1 db "OOF",0
PrintStr2 db "OOF",0
.code
start:
invoke StdOut, addr PrintStr0
invoke StdOut, addr PrintStr1
invoke ExitProcess, 0
end start

jj2007

  • Member
  • *****
  • Posts: 8445
  • Assembler is fun ;-)
    • MasmBasic
Re: Masm failing when called from c++
« Reply #1 on: February 23, 2018, 05:02:34 PM »
I am (attempting) to write a compiler for BASIC.

Welcome to the club ;)

Quote
tmp.asm(1) : error A2088: END directive required at end of file

The assembler complains that, in line 1, it expected END and didn't find it. Which simply means that tmp.asm is an empty file! So check what the heck the IDE is producing at that point. The easiest thing is to temporarily replace ML.exe (or UAsm64.exe?) with a fake ML.exe that just produces a messagebox. While that box is showing, check if tmp.asm exists, and what's inside.

LordAdef

  • Member
  • ****
  • Posts: 588
Re: Masm failing when called from c++
« Reply #2 on: February 23, 2018, 05:06:28 PM »

Hi Armedturret, in this regard I can tell you Jochen is THE guy to help!

AW

  • Member
  • *****
  • Posts: 1305
  • Let's Make ASM Great Again!
Re: Masm failing when called from c++
« Reply #3 on: February 23, 2018, 11:22:03 PM »
It will compile fine if you escape the double quotes and the escapes themselves (if you define the command line inside the C++, otherwise no need).

"h:\\masm32\\bin\\_ml.exe /c /Zd /coff /I\"h:\\masm32\\Include\" tmp.asm"

_ml is my 21 years old masm (unfortunately it is not not whisky).

armedturret

  • Guest
Re: Masm failing when called from c++
« Reply #4 on: February 24, 2018, 01:36:17 AM »
Quote
tmp.asm(1) : error A2088: END directive required at end of file

The assembler complains that, in line 1, it expected END and didn't find it. Which simply means that tmp.asm is an empty file! So check what the heck the IDE is producing at that point. The easiest thing is to temporarily replace ML.exe (or UAsm64.exe?) with a fake ML.exe that just produces a messagebox. While that box is showing, check if tmp.asm exists, and what's inside.
Welp, turns out I forgot to close the write stream and the file was empty.

AW

  • Member
  • *****
  • Posts: 1305
  • Let's Make ASM Great Again!
Re: Masm failing when called from c++
« Reply #5 on: February 24, 2018, 10:30:44 PM »
Pity, we love to blame Masm for everything that goes wrong.