using Assembly language C Starting with the windows32 projec
using Assembly language C++
Starting with the windows32 project located in Figure 3.11, modify the example program and already in the project. Prompt for, input and add three numbers, and display the sum.
Use the sub mnemonic to subtract another input value from the sum calculated in the problem stated above. Display the result.
windows32:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2012
Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"windows32\", \"windows32\\windows32.vcxproj\", \"{6B479473-FF1D-447F-9B62-0693B729278A}\"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6B479473-FF1D-447F-9B62-0693B729278A}.Debug|Win32.ActiveCfg = Debug|Win32
{6B479473-FF1D-447F-9B62-0693B729278A}.Debug|Win32.Build.0 = Debug|Win32
{6B479473-FF1D-447F-9B62-0693B729278A}.Release|Win32.ActiveCfg = Release|Win32
{6B479473-FF1D-447F-9B62-0693B729278A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
3-11 figure:
; Example assembly language program -- adds two numbers
; Author: R. Detmer
; Date: 6/2013
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA
number1 DWORD ?
number2 DWORD ?
prompt1 BYTE \"Enter first number\", 0
prompt2 BYTE \"Enter second number\", 0
string BYTE 40 DUP (?)
resultLbl BYTE \"The sum is\", 0
sum BYTE 11 DUP (?), 0
.CODE
_MainProc PROC
input prompt1, string, 40 ; read ASCII characters
atod string ; convert to integer
mov number1, eax ; store in memory
input prompt2, string, 40 ; repeat for second number
atod string
mov number2, eax
mov eax, number1 ; first number to EAX
add eax, number2 ; add second number
dtoa sum, eax ; convert to ASCII characters
output resultLbl, sum ; output label and sum
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END ; end of source code
Solution
#include <iostream>
int main()
{
int number1;
int number2;
int number3;
int sum;
std::cout << \"Enter first number: \"; // prompt user for data
std::cin >> number1;
std::cout << \"Enter second number: \"; // prompt user for data
std::cin >> number2;
std::cout << \"Enter second number: \"; // prompt user for data
std::cin >> number3;
sum = number1 + number2 + number3; // add the numbers; store result in sum
std::cout << \"Sum is \" << sum << std::endl; // display sum;
}

