[go: up one dir, main page]

0% found this document useful (0 votes)
15 views3 pages

Practical Exercise 1

Uploaded by

roseateankhs.0g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Practical Exercise 1

Uploaded by

roseateankhs.0g
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

XJTLU 1/3 CPT101

Practical Exercise 1 (not assessed)

1. Aims and objectives

Familiarise yourselves with the environment we will use in our assignments, that is, Microsoft Visual
Studio and Microsoft Visual C++, and try to compile and run the program supplied with this
guideline.

2. Tasks

2.1. Start Microsoft Visual Studio

Start Microsoft Visual Studio from the Start Menu. Create a new project by selecting:

[File] -> [New] -> [Project…],

then choose in New Project dialog:

[Visual C++] -> [Win32] -> [Win32 Console Application].

Now in the text field labeled Name: type in the name of your project, say, Practical1. In the
following window click the button Finish.

2.2. Configure your project

Copy the program supplied with this guideline into the created source file Practical1.cpp. Before
you can run the program you must configure your project as follows:

[Project] -> [Project properties] -> [Configuration properties] -> [C\C++]


-> [Code generation] -> [Runtime Library] -> Multi-threaded/MT,

and,

[Project] -> [Project properties] -> [Configuration properties] -> [C\C++]


-> [Precompiled Headers] -> [Precompiled Header] -> Not Using Precompiled
Headers.

2.3. Debug and execute

Once you have done the above settings, try the following:

 Press F5 to build executable code;


 Press F10 to start single stepping in a debugger.

Yellow arrow will appear in the main window pointing out the instruction to be executed. Several new
windows will appear. Familiarise yourselves with the windows. You can switch them on and off. Try
different executions modes - step into, step over, step out of - by pressing suitable buttons on the top
tool bar. In the window Autos you can see how the execution of instruction changes the content of
registers and variables.
XJTLU 2/3 CPT101

3. The program

Copy-and-paste the code below into the CPP file generated by your preferred
version of Visual Studio.

char message1[] = "Give me a first number: ";


char message2[] = "\nGive me a second number: ";
char message3[] = "\nThe numbers are equal! \n";
char message4[] = "\nThe numbers are not equal! \n";
char message5[] = "Type in any integer and press RETURN key to finish: ";
char format[] = "%d"; // format string for the scanf function

int first;
int second;
int end;
_asm {
lea eax, message1 ;
push eax ; PRINTING the FIRST MESSAGE
call printf ;
add esp,4 ;

lea eax,first ;
push eax ;
lea eax,format ; READING the FIRST NUMBER
push eax ;
call scanf_s ;
add esp,8 ;

lea eax, message2 ;


push eax ; PRINTING the SECOND MESSAGE
call printf ;
add esp,4 ;

lea eax,second ;
push eax ;
lea eax,format ; READING the SECOND NUMBER
push eax ;
call scanf_s ;
add esp,8 ;

mov eax,first ;
sub eax,second ; COMPARE TWO NUMBERS, JUMP to suitable section
jnz nequal ;
XJTLU 3/3 CPT101

equal: lea eax, message3 ;


push eax ;
call printf ; PRINTING "Numbers are equal"
add esp,4 ;
jmp finish ; JUMP to finish

nequal: lea eax, message4 ;


push eax ; PRINTING "Numbers are not equal"
call printf ;
add esp,4 ;

finish: lea eax, message5 ;


push eax ; PRINTING the FIFTH MESSAGE
call printf ;
add esp,4 ;

lea eax, end ;


push eax ;
lea eax, format ;
push eax ;
call scanf_s ;
add esp, 8 ;
}
return 0;

You might also like