Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Write an assembly language program that corresponds to the following C++ progr

ID: 645615 • Letter: 1

Question

1.Write an assembly language program that corresponds to the following C++ program:

#include <iostream>
using namespace std;

const int amount = 20000;
int num;
int sum;

int main () {

cin >> num;
sum = numb + amount;
cout << "sum = " ,<< sum << endl;
return 0;

}

2. Test the program in the previous question twice. The first time, enter a value for num to make the sum within the allowed range for the Pep/8 computer. The second time, enter a value that is in range but that makes sum outside the range. Not that the out-of-range condition does not cause an error message, but just gives an incorrect value. Explain the value.

Explanation / Answer

SYS_EXIT equ 1 SYS_READ equ 3 SYS_WRITE equ 4 STDIN equ 0 STDOUT equ 1 AMOUNT equ 20000 segment .data msg1 db "Enter a digit ", 0xA,0xD len1 equ $- msg1 msg2 db " The sum is: ", 0xA,0xD len2 equ $- msg2 segment .bss num resb 2 sum resb 1 section .text global _start ;must be declared for using gcc _start: ;tell linker entry point mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, msg1 mov edx, len1 int 0x80 mov eax, SYS_READ mov ebx, STDIN mov ecx, num mov edx, 2 int 0x80 mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, msg2 mov edx, len2 int 0x80 mov eax, SYS_READ mov ebx, STDIN mov ecx, AMOUNT mov edx, 2 int 0x80 mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, msg3 mov edx, len3 int 0x80 ; moving the first number to eax register and second number to ebx ; and subtracting ascii '0' to convert it into a decimal number mov eax, [num] sub eax, '0' mov ebx, [AMOUNT] sub ebx, '0' ; add eax and ebx add eax, ebx ; add '0' to to convert the sum from decimal to ASCII add eax, '0' ; storing the sum in memory location res mov [sum], eax ; print the sum mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, sum mov edx, 1 int 0x80 exit: mov eax, SYS_EXIT xor ebx, ebx int 0x80

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote