Question

1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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
Add a comment
Know the answer?
Add Answer to:
1.Write an assembly language program that corresponds to the following C++ program: #include <iostream> using namespace...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT