Write an assembly language program that corresponds to the following C++ program
ID: 643749 • Letter: W
Question
Write an assembly language program that corresponds to the following C++ program. Comment each line except STOP & .END.
Add something to the output that makes this program uniquely yours.
Cut & paste the Source Code into your document.
#include
<iostream>
using
namespace std;
int a;
int b;
int c;
int sum;
int out;
int main() {
cin>>a>>b>>c;
sum = a + b + c;
out = sum / 2;
cout<<"first input=" <<a <<endl;
cout<<"second input=" <<b <<endl;
cout<<"third input=" <<c <<endl;
cout<<endl;
cout<<"sum=" <<sum <<endl;
cout<<"output=" <<out <<endl;
return 0;
}
Explanation / Answer
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
INCLUDE io.h ; header file for input/output
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; line feed
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
number1 DWORD ?
number2 DWORD ?
number3 DWORD ?
prompt1 BYTE "Enter first number: ", 0
prompt2 BYTE "Enter second number: ", 0
prompt3 BYTE "Enter third number: ", 0
string BYTE 40 DUP (?)
label1 BYTE cr, Lf, "The sum is "
sum BYTE 11 DUP (?)
BYTE cr, Lf, 0
.CODE ; start of main program code
_start:
output prompt1 ; prompt for first number
input string, 40 ; read ASCII characters
atod string ; convert to integer
mov number1, eax ; store in memory
output prompt2 ; repeat for second number
input string, 40
atod string
mov number2, eax
output prompt3 ;repeat for third number
input string, 40
atod string
mov number3, eax
mov eax, number1 ; first number to EAX
add eax, number2 ; add second number
mov eax, number2 ; second number to EAX
add eax, number3 ; add third number
mov eax, number3 ; third number to EAX
dtoa sum, eax ; convert to ASCII characters
output label1 ; output label and sum
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.