In: Computer Science
Assembly Language Programming
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.
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