{"id":44,"date":"2014-03-24T04:43:39","date_gmt":"2014-03-24T04:43:39","guid":{"rendered":"http:\/\/blog.catalystlogic.com.au\/?p=44"},"modified":"2026-03-01T01:44:18","modified_gmt":"2026-02-28T14:44:18","slug":"masm-masm32-visual-studio-2013","status":"publish","type":"post","link":"http:\/\/54.253.247.134\/?p=44","title":{"rendered":"MASM, MASM32 &#038; Visual Studio 2013"},"content":{"rendered":"<p>Though I would give an assembly Hello World a go, and get into some low level programming.<\/p>\n<p>After reading up in MASM, NASM &amp; FASM, I decided on MASM, and soon came across a <a href=\"http:\/\/scriptbucket.wordpress.com\/2011\/10\/19\/setting-up-visual-studio-10-for-masm32-programming\/\">great blog<\/a> detailing how to set up VS2013 to run with MASM32.<\/p>\n<p>After setting up the environment, and running the hello world app below, I noticed that this use of the MASM32 libraries seemed to vary greatly from the Assembly code I have previously seen that typically utilsie a series of 3 and 4 letter instructions mixed with memory addresses,<\/p>\n<pre class=\"toolbar:2 lang:asm decode:true\">.386\n.model flat, stdcall\n.stack 4096\noption casemap : none\n\ninclude windows.inc\ninclude masm32.inc\ninclude user32.inc\ninclude kernel32.inc\ninclude macros.asm\n\nincludelib masm32.lib\nincludelib user32.lib\nincludelib kernel32.lib\n\n.data\nmessage   db \"Hello world!\", \"$\"\n\n.code\nmain PROC\n\tprint \"Hello World!\"\n\tinvoke ExitProcess, eax\nmain ENDP\nEND main<\/pre>\n<p>In my travels, the assembly I have glanced upon seemed to be much more like the below example, which I bumped into while I was setting up Visual Studio<\/p>\n<pre class=\"toolbar:2 lang:asm decode:true\">.model small\n.stack\n.data\nmessage   db \"Hello world\", \"$\"\n.code\nmain    proc\nmov   ax, seg message\nmov   ds, ax\nmov   ah, 09\nlea   dx, message\nint   21h\n\nmov   ax, 4c00h\nint   21h\nmain    endp\nend main<\/pre>\n<p>I naively assumed that this was what MASM was like when you didn't utilise the MASM32 Libraries references in the first example. That was, until trying to compile the above code hit me with this...<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">1&gt;  Assembling source.asm...\n1&gt;source.asm(7): error A2004: symbol type conflict\n1&gt;source.asm(16): warning A4023: with \/coff switch, leading underscore required for start address : main<\/pre>\n<p>As it seem this is a common mistake, replies at the <a href=\"http:\/\/masm32.com\/board\/index.php?topic=1853.0\">masm32 forums<\/a>, and stackoverflow pointed out the difference between 16bit MASM, and MASM32.<\/p>\n<p>I still wanted to push forward with 16bit MASM, but with Win7 x64 not supporing 16bit, I figured I may have to use DOSbox.<\/p>\n<p>I now knew I needed a\u00a0<a href=\"http:\/\/www.masmforum.com\/board\/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&amp;topic=14154.msg112459#msg112459\">16bit Linker<\/a>, and a bit of digging showed me that there was one in my MASM32 install. I tried looking in the project configuration, such as the Microsoft macro assembler to see if I could find a place to poitn to the linker16.exe, with no luck.<\/p>\n<p>I then came across <a href=\"http:\/\/kipirvine.com\/asm\/gettingStartedVS2012\/index.htm\">this very detailed article<\/a> on both 16 and 32 bit set up in VS2012 by Kip Irvine.<\/p>\n<p>With his directions. I then went down the path of a batch file triggered by Visual Studio \u00a0External Tools. Hoeever I wanted to dig a bit deeper and make my own batch file.<\/p>\n<p>After finding a githib reference to the <a href=\"https:\/\/github.com\/wildicv\/Code\/blob\/master\/SchoolCode\/CallingCFromAsm\/DifferenceAsmProject\/Irvine\/make16.bat\">make16.bat<\/a> in his tutorial, it seemed that he utilised ml.exe that was part of Visual Studio, not the<a href=\"http:\/\/www.masm32.com\/masmdl.htm\"> MASM32 downloads<\/a>. Running a modified version gave me the following error.<\/p>\n<pre class=\"toolbar:2 lang:c# highlight:0 decode:true\">MASM : warning A4018: invalid command-line option : -omf<\/pre>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/s0ksfwcf.aspx\">MSDN ML Command Line Reference<\/a> advised me that this was due to my 64bit install.<\/p>\n<pre class=\"toolbar:2 lang:c# highlight:0 decode:true\">Generates object module file format (OMF) type of object module. \/omf implies \/c; ML.exe does not support linking OMF objects.\nNot available in ml64.exe.<\/pre>\n<p><span style=\"line-height: 1.8; font-size: 1rem;\">I decided to go with the ML.EXE installed with the MASM32 libraries, along with the commands I came across on <\/span><a style=\"line-height: 1.8; font-size: 1rem;\" href=\"http:\/\/stackoverflow.com\/questions\/14692582\/assembly-fatal-error-lnk1190-invalid-fixup-found-type-0x0001\">stack overflow<\/a><span style=\"line-height: 1.8; font-size: 1rem;\">. I Modified the bat to utilise the args passed from VS External Tools.<\/span><\/p>\n<p><a href=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/ExternalTools.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-46\" alt=\"ExternalTools\" src=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/ExternalTools.png\" width=\"471\" height=\"460\" srcset=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/ExternalTools.png 471w, http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/ExternalTools-300x293.png 300w\" sizes=\"auto, (max-width: 471px) 100vw, 471px\" \/><\/a><\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">ML.EXE \/DMASM \/DDOS \/Zm \/c \/nologo \/I\"c:\\masm32\\Include\" \"%1.asm\"\nlink16.exe \/NOLOGO \"%1.obj\" ;<\/pre>\n<p>The semicolon I added at the end of the link16.exe args use default settings, so do not require input. Perfect if you want the build result in the VS output window instead of a DOS window.<\/p>\n<p><a href=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/MASMBuild1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-50\" alt=\"MASMBuild\" src=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/MASMBuild1.png\" width=\"777\" height=\"157\" srcset=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/MASMBuild1.png 777w, http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/MASMBuild1-300x61.png 300w, http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/MASMBuild1-768x155.png 768w\" sizes=\"auto, (max-width: 777px) 100vw, 777px\" \/><\/a><\/p>\n<p>Now I got my MASM16 hello world assembled, I just needed a 16bit platform to run it.<\/p>\n<p>I went with DOSbox as it has the command line arguments i was hoping for, so I could integrate it with VS External Tools.<\/p>\n<p>I created the following batch file, accepting the filename from External Tools as %1.<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">\"C:\\Program Files (x86)\\DOSBox-0.74\\dosbox.exe\" C:\\Dev\\MASM\\Masm32\\%1.exe<\/pre>\n<p>Though, it seems that External Tools wraps this in quotes, resulting in the location of the newly assembled exe for DOSbox to run, not being valid.<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">C:\\Dev\\MASM\\Masm32&gt;\"C:\\Program Files (x86)\\DOSBox-0.74\\dosbox.exe\" C:\\Dev\\MASM\\M\nasm32\\\"source16\".exe<\/pre>\n<p>The build scripts seemed to be ok with this, as it also ucrred there. However the following command trimmed the double quotes and allowed the exe to be passed into Dos Box<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">SET FILE=%1\nSET FILE=%FILE:\"=%\n\"C:\\Program Files (x86)\\DOSBox-0.74\\dosbox.exe\" C:\\Dev\\MASM\\Masm32\\%FILE%.exe<\/pre>\n<p>And success.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-45\" style=\"font-size: 1rem; line-height: 1;\" alt=\"DOSBox\" src=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/DOSBox.png\" width=\"656\" height=\"438\" srcset=\"http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/DOSBox.png 656w, http:\/\/54.253.247.134\/wp-content\/uploads\/2014\/03\/DOSBox-300x200.png 300w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Though I would give an assembly Hello World a go, and get into some low level programming. After reading up in MASM, NASM &amp; FASM, I decided on MASM, and soon came across a great blog detailing how to set up VS2013 to run with MASM32. After setting up the environment, and running the hello <a class=\"read-more\" href=\"http:\/\/54.253.247.134\/?p=44\">...continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,18],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-assembly","category-visual-studio"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/54.253.247.134\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":1,"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":240,"href":"http:\/\/54.253.247.134\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions\/240"}],"wp:attachment":[{"href":"http:\/\/54.253.247.134\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/54.253.247.134\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/54.253.247.134\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}