Lab 01 - Getting - Started
Lab 01 - Getting - Started
Objectives
This lab introduces you how to install and use Visual studio 2019 for programming and debugging an
assembly language program. Building and running a 32-bit program a 64-bit program
Lab Work
Run the VS installer, select the Desktop development with C++ button in the installer window, look at
the Summary list on the right side to verify that VC++ is selected, and click the Modify button in the
lower right corner of the window, as below in Figure
The Visual C++ language includes the Microsoft Assembler (MASM). To verify that MASM is installed,
open a Windows Explorer window and look for the file named ml.exe in the Visual Studio installation
directory, such as C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\VC\Tools\MSVC\14.xx.xxxx\bin\HostX64\x86. (The "x" characters above
indicate digits in the version number of your current VS installation.)
Setting up Visual Studio and Building and running a 32-bit program
4. Then write the Project name, without spaces, and make sure you select Place solution and
project in the same directory, and finally create.
5. Once the project has been created, you will see the project name in Visual Studio's Solution
Explorer window. You should also see a C++ source file in the project named Lab1.cpp. Double-
click the file name to open it in the editor.
Remove Lab1.cpp by right click on the file and delete it
6. Add a new .asm file to the project, right click on the Source Files folder and select from the
menu Add, and add New Item.
7. Once the project has been opened, you will see the project name in Visual Studio's Solution
Explorer window. You should also see an assembly language source file in the project named
Task1.asm. Double-click the file name to open it in the editor.
The asm file Task1.asm is empty file; copy the code below into the Task1.asm and save it.:
.code
main proc
mov eax,5
add eax,6
invoke ExitProcess,0
main endp
end main
8. Right click on the Project, and select form the menu Build Dependences, then Build
Customizations.
9. A new window will open, select masm from the available build customizations files, and then
OK.
10. Return back to the Task1.asm, right click on Task1.asm file, select properties, from the General
tab, select No for to Excluded From Build, and select Microsoft Macro Assembler for the Item
Type
11. Right click on Lab1 Project, select properties, from linker options select Advanced, then specify
the Entry point to main
Build the Program
Now you will build (assemble and link) the sample program. Select Build Project from the Build menu. In
the Output window for Visual Studio at the bottom of the screen, you should see messages similar to the
following, indicating the build progress:
First, you must set a breakpoint. When you set a breakpoint in a program, you can use the debugger to
execute the program a full speed (more or less) until it reaches the breakpoint. At that point, the
debugger drops into single-step mode. Here's how to do it:
1. Make sure the ASM source code file is open in the editor window.
2. Right click the mouse along the border to the left of the mov eax,5 statement, select breakpoint,
then insert breakpoint, A large red dot should appear in the margin.
3. Select Start Debugging from the Debug menu. The program should run and pause on the line
with the breakpoint. (Optionally, you can close the Diagnostic Tools, Autos, and Call Stack
windows.)
4. Press the F10 key (called Step Over) to execute the current statement. Continue pressing F10
until the program is about to execute the invoke statement.
5. A small black window icon should appear on either your Windows desktop or status bar. The
window should be blank because this program does not display any output.
6. Press F10 one more time to end the program.
You can remove a breakpoint by right clicking its dot then delete the breakpoint. Take a few minutes to
experiment with the Debug menu commands. Set more breakpoints and run the program again.
mov eax,5
add eax,6
invoke ExitProcess,0
2. Run the same code in 64-bit Debug mode, select x64 and Build your project, list the error you
see and explain what they means :_________________________________________________
.data
sum qword 0
.code
main proc
mov rax,5
add rax,6
mov sum,rax
mov ecx,0
call ExitProcess
main endp
end
The following three lines, which were in the 32-bit version of the Task1.asm program are not
used in the 64-bit version:
.386
.model flat,stdcall
.stack 4096
Statements using the PROTO keyword do not have parameters in 64-bit programs. :
ExitProcess PROTO
Lines 14–15 use two instructions to end the program (mov and call). The 32-bit version used an
INVOKE statement to do the same thing. The 64-bit version of MASM does not support the
INVOKE directive.
In line 17 (end), the end directive does not specify a program entry point. The 32-bit version of
the program did.
Right click on Lab1 Project, select properties, from linker options select Advanced, and then specify the
Entry point to main
You should see the following program in the editor window:
Insert the variable name (sum), and press enter. Run the program and observe the value of the variable,
after you finish the run, what is the new values of the sum variable_________
Memory window
The Memory windows are available only during a debugging session.
To open a Memory window