Question

In: Computer Science

Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...

Assembly Language Programming

  1. Construct an assembly language program fragment equivalent to the following C/C++ statement:

if (M <= N + 3 && (C == ‘N’ || C == ‘n’))

C = ‘0’;

else

C = ‘1’;

Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.

Solutions

Expert Solution

C++ program code


#include <iostream>

using namespace std;

int main()
{
    int M=10,N=20;
    char C[5]={'N','n'};
if (M <= N + 3 && (C == "N" || C == "n"))
{

char C = '0';
cout<<"The value of C is :"<<C;
}

else{

char C = '1';
cout<<"The value of C is :"<<C;
}
    return 0;
}

The Output:

Converted Assembly Language Code:

Please note( x86-64 gcc 10.2 )

.LC0:
        .string "The value of C is :"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], 10
        mov     DWORD PTR [rbp-8], 20
        mov     DWORD PTR [rbp-14], 28238
        mov     BYTE PTR [rbp-10], 0
        mov     BYTE PTR [rbp-9], 49
        mov     esi, OFFSET FLAT:.LC0
        mov     edi, OFFSET FLAT:_ZSt4cout
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
        mov     rdx, rax
        movsx   eax, BYTE PTR [rbp-9]
        mov     esi, eax
        mov     rdi, rdx
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)
        mov     eax, 0
        leave
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L5
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L5
        mov     edi, OFFSET FLAT:_ZStL8__ioinit
        call    std::ios_base::Init::Init() [complete object constructor]
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:_ZStL8__ioinit
        mov     edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
        call    __cxa_atexit
.L5:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret

Related Solutions

THE FOLLOWING QUESTION IS FOR C PROGRAMMING LANGUAGE Printing the decimal equivalent of a binary number....
THE FOLLOWING QUESTION IS FOR C PROGRAMMING LANGUAGE Printing the decimal equivalent of a binary number. Write a program that accepts an integer (5 digits or fewer) containing only 0s and 1s (i.e., binary) and prints out its decimal equivalent using the remainder and division operator to select the "binary" digits one at a time. Make sure your input is tested for multiple options: incorrect characters, too many, too few, etc. I need help making this program. No loops, if...
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
ASSEMBLY LANGUAGE PROGRAMMING Q:Write a complete assembly program that inputs a small signed integer n, whose...
ASSEMBLY LANGUAGE PROGRAMMING Q:Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6.
**C++ Programming Language** a program that computes the average of a collection of numbers and then...
**C++ Programming Language** a program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. The objective of this assignment is to select a language that you have never used before and modify the program from the text so that it outputs the number of A's, B's, C's, D's and F's. An A grade is any score that is at least 20% greater than the average. The...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace std; char ch; int main() {    cin >> ch;    cout << "You inputted " << ch << endl;    ch++;    cout << "Next character is " << ch << endl; if (ch <= ‘Z’)         cout << “Could be luppercase\n”;    return 0; }
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
Complete the AVR assembly language fragment below so that it does a multiply by 2 of...
Complete the AVR assembly language fragment below so that it does a multiply by 2 of the two's complement 32-bit quantity in registers r18:r19:r20:r21. (r18 is the most significant byte.) asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21
Complete the AVR assembly language fragment below so that it performs a division by 2 of...
Complete the AVR assembly language fragment below so that it performs a division by 2 of the 24-bit two's complement value in registers r6:r5:r4. (r6 is the most significant byte.) lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT