a Write a program in a high level language c Python etc that

a) Write a program in a high level language (c++, Python, etc) that will print the following pattern 12 123 1234 12345 b) Now convert the program to MASM

Solution

a) Program in C++ to print the expected pattern

#include <iostream>
using namespace std;

// function which will print the pattern
int printpattern() {
int i,j,k;
  
   for(k=1; k<=5; k++){
   for(i=1; i<=k; i++){
   cout << i;
   }
   for(j=5-k; j>=1; j--){
   cout << \"*\";
   }
   cout << endl;
  
   }
   return 0;
}

b) if you convert the abpve c++ program into the masm code, it would turn out to be below

.LC0:
.string \"*\"
printpattern():
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-12], 1
.L7:
cmp DWORD PTR [rbp-12], 5
jg .L2
mov DWORD PTR [rbp-4], 1
.L4:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-12]
jg .L3
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)
add DWORD PTR [rbp-4], 1
jmp .L4
.L3:
mov eax, 5
sub eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-8], eax
.L6:
cmp DWORD PTR [rbp-8], 0
jle .L5
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*)
sub DWORD PTR [rbp-8], 1
jmp .L6
.L5:
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
add DWORD PTR [rbp-12], 1
jmp .L7
.L2:
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 .L11
cmp DWORD PTR [rbp-8], 65535
jne .L11
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
.L11:
nop
leave
ret
_GLOBAL__sub_I__Z12printpatternv:
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret

 a) Write a program in a high level language (c++, Python, etc) that will print the following pattern 12 123 1234 12345 b) Now convert the program to MASM Solut
 a) Write a program in a high level language (c++, Python, etc) that will print the following pattern 12 123 1234 12345 b) Now convert the program to MASM Solut

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site