Write a simple program in assembly language to read three nu
Write a simple program in assembly language to read three numbers from the input with the appropriate message, calculates the following logic function and prints the output to the console along with a message. Suppose the three numbers are A, B, C the logic function is the following:
F=(A OR C)’ AND (B AND C)’
Code must compile and run in QtSpim.
Solution
Answer:
MIPS Assembly Language Code:
.zero 1
 .LC0:
 .string \"Enter three numbers: \"
 main:
 push rbp
 mov rbp, rsp
 sub rsp, 16
 mov esi, OFFSET FLAT:.LC0
 mov edi, OFFSET FLAT:std::cout
 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*)
 lea rax, [rbp-8]
 mov rsi, rax
 mov edi, OFFSET FLAT:std::cin
 call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
 mov rdx, rax
 lea rax, [rbp-12]
 mov rsi, rax
 mov rdi, rdx
 call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
 mov rdx, rax
 lea rax, [rbp-16]
 mov rsi, rax
 mov rdi, rdx
 call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
 mov edx, DWORD PTR [rbp-8]
 mov eax, DWORD PTR [rbp-16]
 mov ecx, edx
 or ecx, eax
 mov edx, DWORD PTR [rbp-12]
 mov eax, DWORD PTR [rbp-16]
 and eax, edx
 and eax, ecx
 mov DWORD PTR [rbp-4], eax
 mov eax, DWORD PTR [rbp-4]
 mov esi, eax
 mov edi, OFFSET FLAT:std::cout
 call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
 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:std::__ioinit
 call std::ios_base::Init::Init()
 mov edx, OFFSET FLAT:__dso_handle
 mov esi, OFFSET FLAT:std::__ioinit
 mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
 call __cxa_atexit
 .L5:
 nop
 leave
 ret
 push rbp
 mov rbp, rsp
 mov esi, 65535
 mov edi, 1
 call __static_initialization_and_destruction_0(int, int)
 pop rbp
 ret

