I am new to assembly and I am trying to build my code. But when ever I try, I get this error that I don't understand:
Severity Code Description Project File Line Suppression State
Error MSB3721 The command "ml.exe /c /nologo /Zi /Fo"Debug\Main.obj" /W3 /errorReport:prompt /TaMain.asm" exited with code 1. TestProject D:\VS\vs\MSBuild\Microsoft\VC\v170\BuildCustomizations\masm.targets 70
This file is not even in my project, I think it is the compiler but I am not sure why it is giving this error. Here is my code:
.386
.model flat
.code
start PROC
mov eax, 213
add eax, 432
ret
start endp
end start
I am using the VS masm and Local Windows Debuger. The version is 2022 comunity. If anyone knows the solution, or if I need to add more details please tell me.
Thank you and have a nice day!
Related
Summary: A VS2015 solution with mixed C and Assembler, does not display symbols in assembler code when debugging after upgrading to VS2017 or VS2019).
[Oct 2109: problem solved, see note at end].
Long details:
I have a VS 2015 xxx.sln with 32 bit C code compiled by the VS 2015 compiler, with a large 32 bit assembler code parlanse0.asm assembled by a custom command line:
parlanse0.asm Property Pages
Item Type: Custom Build Tool
Command Line: ml /D SANITYCHECKS="1" /D EVENTBUFFERENABLE="1" /D TESTING="1" /D PROFILE="0" /Sg /Sl132 /Sx /Zd /Zi /c /Cx /coff /Zd /Fl "%(FullPath)"
Outputs: parlanse0.obj;%(Outputs)
Additional Dependencies: <list of MASM include file>
Link Objects: Yes
Treat Output As Content: No
I'm not sure this is relevant, but here's the Linker options:
/OUT:"Debug\run.exe" /MANIFEST /PROFILE /NXCOMPAT:NO /PDB:"Debug/erun.pdb" /DYNAMICBASE:NO "odbc32.lib" "odbccp32.lib" "netapi32.lib" "iphlpapi.lib" "psapi.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" /LARGEADDRESSAWARE /MACHINE:X86 /SAFESEH:NO /INCREMENTAL:NO /PGD:".\Debug\run.pgd" /SUBSYSTEM:CONSOLE",5.01" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:".\Debug\run.exe.intermediate.manifest" /MAP":.\Debug/run.map" /ORDER:#"RTSCFunctionOrder.txt" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Program Files\Microsoft Platform SDK\Lib" /DELAYLOAD:"iphlpapi.dll" /DELAYLOAD:"comdlg32.dll" /TLBID:1
[If this is the linker command line, where does it get the names of the .obj files it processes?]
This solution compiles/builds/runs fine under VS 2015.
I'm trying to upgrade to VS 2017 (update: Sept 2019, problem never resolved, so I just tried it again with VS 2019... same problem).
The upgrade seemed trivial: I simply started VS 2017 and pointed it at the VS 2015 solution file. Apparently
nothing changes, at least my source control (over the various MS build files like .sln don't see any changes). Magically, almost everything works: I can compile/run/debug the application.
However, the assembly source code is no longer visible when I'm in the debugger and attempt to "go to source code" when I've stepped into a bit of assembler. "Goto source code" from the assembler works fine in VS 2015. Likewise, if during debugging I choose an assmbley language source line and attempt to "Go to disassembly" I get a pop-up window "Disassembly cannot be displayed... there is no executable code associated with this location", and that's clearly wrong. Also behavior that was find under VS 2015.
What do I have to change? Are there documents somewhere that describe what is different?
[Addition: The assembler source is in a different directory than the .C sources. This causes the .sbr file for the assembler code to be produced in a different directory from the .sbr files for the C code. Apparently the assembler code .sbr is not picked up the build process; in one of the log files I can see all the .sbr files for the C code but not for the assembler.
So this doesn't look right. However, my understanding is .sbr files support VisualStudio tag lookup, not object-location-to-source-line map so I think this is a red herring. Where is the object-location-to-source-line map produced? Does the linker do it?]
[Addition: following the advice in the comments to look at another answer, I changed the /DEBUG option to /DEBUG:FULL with no apparent effect on the problem.]
[I found some article on PDB files, and how the C++ compiler "updates" it as is compiles individual .cpp (.c?) files. Is MASM supposed to generate a PDB files? So... how would MASM update the compiler's target PDB file?]
... added after 2 month delay ...
I see this in a disassembly window on my assembler code:
00480107 CC int 3
00480108 CC int 3
RTSAllocate11D_end:
00480109 8D A4 24 00 00 00 00 lea esp,[esp]
00480110 8D A4 24 00 00 00 00 lea esp,[esp]
00480117 8D A4 24 00 00 00 00 lea esp,[esp]
0048011E 8D A4 24 00 00 00 00 lea esp,[esp]
00480125 8D A4 24 00 00 00 00 lea esp,[esp]
0048012C 8D A4 24 00 00 00 00 lea esp,[esp]
00480133 8D A4 24 00 00 00 00 lea esp,[esp]
0048013A 8D 9B 00 00 00 00 lea ebx,[ebx]
allocate_2to1E_bytes:
These are my symbols, so they are clearly getting to the debugger. I ask the disassembly window to show line numbers... it does nothing. So somehow the symbols are getting through, but not the line number information or maybe not the source file location. Thoughts?
EDIT: October 9, 2019: PROBLEM CLAIMED SOLVED. A long interaction with Microsoft got them to agree this is a problem in the debugger. I verified that VS 2015 Update 1 was the last version that worked properly; VS 2015 Update 2 and later, VS 2017 and VS 2019 all suffer from the same problem. MS has told me that they have identified the problem and a fix will be available in VS 2019 v16.4 Public Release in December 2019.
for have debugging info (in pdb file) need 2 steps:
compiler must include debugging information to obj file for ml[64]
compiler this is /Zd option
linker must have /DEBUG option in command line. in this case it
get debug info (stored in .debug$S sections of obj / lib files) and
create pdb file
if command line both for compiler and linker correct (have this options) need check in following order:
look in .obj file in any text/binary viewer - are full path string
of sourse asm file name exist in file. simply search for
PARLANSE0.ASM (or how your source file named) in file as is (all
names stored as ansi plain text) - are this name is found are path
is correct ? if yes - this mean with compiler (ml in our case all
correct and we can go forward)
look in pdb file - are this strings exist here also ?
look in exe file - search for .pdb - are full (and correct) path
for your pdb exist in exe file ? again it stored as plain ansi
text
try alternative debugger use - i be suggest windbg - are he can
go to source. for easy check you even can make special temporary
build - set breakpoint before go to asm code (or direct in some asm
procedure) and call this procedure at very begin of exe. even if
this "incorrect" by logic - we need only check - are debugger
understand pdb format and can show source for asm
if windbg can go to asm source code - this mean some problem with integrated vs2017 debugger. if windbg can not - some problems with pdb format generated
Change the assembly file name P.asm to parlanse0.asm
or Add /Fo parlanse0.obj to the beginning of your custom build script.
You cannot generate parlanse0.obj and debug related files(parlanse0.iobj, parlanse0.ipdb) via yours. However, you may build without any problems since the files were compiled before.
.386
.model flat, c
.stack 100 h
.data
num1 sdword ?
num2 sdword ?
.code
main proc
mov num1,5
mov eax,num1
mov num2,eax
ret
main endp
end
I have checked the masm in the build customization of the project.
I have changed the item type to Microsoft Macro Assembler.
But, it is still showing error messages below:
Severity Code Description Project File Line Suppression State
Error A2206 missing operator in expression testing C:\Users\Kin\Desktop\assembly\testing\testing\Source.asm 3
Error A2206 missing operator in expression testing C:\Users\Kin\Desktop\assembly\testing\testing\Source.asm 2
Error MSB3721 The command "ml.exe /c /nologo /Zi /Fo"Debug\Source.obj" /W3 /errorReport:prompt /TaSource.asm" exited with code 1. testing H:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\masm.targets 50
Changed to .stack 100h
It is now showing:
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals testing C:\Users\Kin\Desktop\assembly\testing\Debug\testing.exe 1
Error LNK2001 unresolved external symbol _WinMainCRTStartup testing C:\Users\Kin\Desktop\assembly\testing\testing\LINK 1
I'm trying to get started with asm programming on Win 32 and, after searching the internet for instructions for a while and also using Irvine's online tutorial on setting this up, successfully got the following program to compile and run using VS 2015 community edition:
.386
.model flat,stdcall
option casemap:none
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.CODE
main PROC
mov eax,5 ; move 5 to the eax register
add eax,6 ; add 6 to the eax register
INVOKE ExitProcess,0
main ENDP
END main
(it's from Irvine's book).
Now I want to create a listing file. To this end I opened Properties -> Configuration Properties -> Microsoft Macro-Assembler and enabled 'Generate Preprocessed Source Listing' and 'List All Available Information' and added $(ProjectName).lst in the 'Assembled Code Listing File' entry. After that I get the error mentioned in the title when I try to build the project.
In fact, when I build the project (without these settings), no .obj file seems to be generated, just the .exe and .pdb. I can trigger building an .obj file by choosing the 'Enable Assembly Generated Code Listing' option (same path as above), but I still get the same error when I try to enable generation of the listing file as explained before. Any ideas?
(This is following instructions in Irvine's book, but without using his included files).
(I did disable my Anti Virus program before building).
I'm trying to run an assembly program using MASM in Visual Studio. This is the code I have
include Irvine32.inc
.data
str1 BYTE "a test string",0
.code
main proc
mov edx,OFFSET str1
call WriteString
exit
main endp
End main
The error I'm getting is:
error LNK2019: unresolved external symbol _WriteString#0 referenced in function _main#0"
Why am I getting this error?
Press Shift + Alt + A
find Irvine32.inc and Irvine32.lib from your HDD
Add them in your project repository.
The linker error suggests that you aren't linking against the Irvine32 library. Although you have included Irvine32.inc at the top of your assembly program, you still need to add Irvine32.lib as a library to link against in your Solution, or add it to your command line (if compiling with at a command shell), or use includelib directive inside your assembly code to link with it.
I searched and found I can not use __asm in x64 in visual studio. Instead I have to use an external assembly file.
How can I add external assembly file to my win32 console project?
How can compile them?
Can you explain step by step.
How to build a mixed-source x64-project with a x64 assembly file in Visual Studio:
1) Start Visual Studio (Community) 2015 and choose FILE - New - Project.
2) In the next window choose Win 32 Console Application.
3) You get a confirmation. Click on Next >.
4) In the next window you can accept the default settings. Click on Finish.
5) Make sure, that the project is highlighted in the Solution Explorer and and choose PROJECT - Build Customizations... from the menu.
6) In the next window tick masm(.targets,.props) and click on OK.
7) Choose Build - Configuration Manager...
8) Change the Active solution platform to x64
9) Create callee.asm: PROJECT - Add New Item.
10) In the next window choose C++File(.cpp) and - IMPORTANT! - give it a name with an .asm extension. Click on Add.
10) Now check if the .asm file has the right properties. In the Solution Explorer right-click on the file and choose Properties.
11) In the Property Page you should see at least:
Excluded From Build (empty) or No
Item Type Microsoft Macro Assembler
Under Command Line ensure that ml64.exe is chosen as the assembler.
Click on OK.
12) Now you can fill the files with content.
ConsoleApplication1.cpp:
#include <iostream>
using namespace std;
extern "C" void hello_from_asm();
int main()
{
cout << "Hello from CPP" << endl;
hello_from_asm();
return 0;
}
callee.asm:
PUBLIC hello_from_asm
EXTERN puts:PROC
.data
hello1 db "Hello from ASM.",0
.code
hello_from_asm PROC
push rbp
mov rbp, rsp
sub rsp, 32 ; Shadow Space
and spl, -16 ; Align stack at 16
lea rcx, hello1
call puts
leave ; Restore stack (rsp) & frame pointer (rbp)
ret
hello_from_asm ENDP
END
13) Build the .exe
and run it with CTRL-F5.
The application will be opened in a new window.