Question

need help converting a code in c++ over into MARIE assembly language // C++ program to...

need help converting a code in c++ over into MARIE assembly language

// C++ program to find (a^b) mod n for 'a'
#include<bits/stdc++.h>
using namespace std;

// calculate a%n
unsigned int aModM(string s, unsigned int mod)
{
   unsigned int number = 0;
   for (unsigned int i = 0; i < s.length(); i++)
   {
       // (s[i]-'0') gives the digit value and form
       // the number
       number = (number*10 + (s[i] - '0'));
       number %= mod;
   }
   return number;
}

// Returns find (a^b) % m
unsigned int ApowBmodM(string &a, unsigned int b,
                               unsigned int n)
{
   // Find a%n
   unsigned int ans = aModM(a, n);
   unsigned int mul = ans;

   // now multiply ans by b-1 times and take
   // mod with n
   for (unsigned int i=1; i<b; i++)
       ans = (ans*mul) % n;

   return ans;
}

// Driver program
int main()
{
int a,b,n;

cin>>a>>b>>n;
  
   cout << ApowBmodM(a, b, n);
   return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER-

   .file   "untitled2.cpp"
   .text
   .section .rdata,"dr"
_ZStL19piecewise_construct:
   .space 1
_ZStL13allocator_arg:
   .space 1
_ZStL6ignore:
   .space 1
.lcomm _ZStL8__ioinit,1,1
   .align 4
_ZN9__gnu_cxxL21__default_lock_policyE:
   .long   2
_ZStL10defer_lock:
   .space 1
_ZStL11try_to_lock:
   .space 1
_ZStL10adopt_lock:
   .space 1
   .align 4
_ZNSt15regex_constantsL5icaseE:
   .long   1
   .align 4
_ZNSt15regex_constantsL6nosubsE:
   .long   2
   .align 4
_ZNSt15regex_constantsL8optimizeE:
   .long   4
   .align 4
_ZNSt15regex_constantsL7collateE:
   .long   8
   .align 4
_ZNSt15regex_constantsL10ECMAScriptE:
   .long   16
   .align 4
_ZNSt15regex_constantsL5basicE:
   .long   32
   .align 4
_ZNSt15regex_constantsL8extendedE:
   .long   64
   .align 4
_ZNSt15regex_constantsL3awkE:
   .long   128
   .align 4
_ZNSt15regex_constantsL4grepE:
   .long   256
   .align 4
_ZNSt15regex_constantsL5egrepE:
   .long   512
   .align 4
_ZNSt15regex_constantsL12__polynomialE:
   .long   1024
   .align 4
_ZNSt15regex_constantsL13match_defaultE:
   .space 4
   .align 4
_ZNSt15regex_constantsL13match_not_bolE:
   .long   1
   .align 4
_ZNSt15regex_constantsL13match_not_eolE:
   .long   2
   .align 4
_ZNSt15regex_constantsL13match_not_bowE:
   .long   4
   .align 4
_ZNSt15regex_constantsL13match_not_eowE:
   .long   8
   .align 4
_ZNSt15regex_constantsL9match_anyE:
   .long   16
   .align 4
_ZNSt15regex_constantsL14match_not_nullE:
   .long   32
   .align 4
_ZNSt15regex_constantsL16match_continuousE:
   .long   64
   .align 4
_ZNSt15regex_constantsL16match_prev_availE:
   .long   128
   .align 4
_ZNSt15regex_constantsL14format_defaultE:
   .space 4
   .align 4
_ZNSt15regex_constantsL10format_sedE:
   .long   256
   .align 4
_ZNSt15regex_constantsL14format_no_copyE:
   .long   512
   .align 4
_ZNSt15regex_constantsL17format_first_onlyE:
   .long   1024
   .align 4
_ZNSt15regex_constantsL13error_collateE:
   .space 4
   .align 4
_ZNSt15regex_constantsL11error_ctypeE:
   .long   1
   .align 4
_ZNSt15regex_constantsL12error_escapeE:
   .long   2
   .align 4
_ZNSt15regex_constantsL13error_backrefE:
   .long   3
   .align 4
_ZNSt15regex_constantsL11error_brackE:
   .long   4
   .align 4
_ZNSt15regex_constantsL11error_parenE:
   .long   5
   .align 4
_ZNSt15regex_constantsL11error_braceE:
   .long   6
   .align 4
_ZNSt15regex_constantsL14error_badbraceE:
   .long   7
   .align 4
_ZNSt15regex_constantsL11error_rangeE:
   .long   8
   .align 4
_ZNSt15regex_constantsL11error_spaceE:
   .long   9
   .align 4
_ZNSt15regex_constantsL15error_badrepeatE:
   .long   10
   .align 4
_ZNSt15regex_constantsL16error_complexityE:
   .long   11
   .align 4
_ZNSt15regex_constantsL11error_stackE:
   .long   12
   .align 4
_ZNSt8__detailL19_S_invalid_state_idE:
   .long   -1
   .text
   .globl   _Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
   .def   _Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj;   .scl   2;   .type   32;   .endef
   .seh_proc   _Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
_Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj:
.LFB8368:
   pushq   %rbp
   .seh_pushreg   %rbp
   pushq   %rbx
   .seh_pushreg   %rbx
   subq   $56, %rsp
   .seh_stackalloc   56
   leaq   128(%rsp), %rbp
   .seh_setframe   %rbp, 128
   .seh_endprologue
   movq   %rcx, -48(%rbp)
   movl   %edx, -40(%rbp)
   movl   $0, -84(%rbp)
   movl   $0, -88(%rbp)
.L3:
   movl   -88(%rbp), %ebx
   movq   -48(%rbp), %rcx
   call   _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv
   cmpq   %rax, %rbx
   setb   %al
   testb   %al, %al
   je   .L2
   movl   -84(%rbp), %edx
   movl   %edx, %eax
   sall   $2, %eax
   addl   %edx, %eax
   addl   %eax, %eax
   movl   %eax, %ebx
   movl   -88(%rbp), %eax
   movq   %rax, %rdx
   movq   -48(%rbp), %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEy
   movzbl   (%rax), %eax
   movsbl   %al, %eax
   addl   %ebx, %eax
   subl   $48, %eax
   movl   %eax, -84(%rbp)
   movl   -84(%rbp), %eax
   movl   $0, %edx
   divl   -40(%rbp)
   movl   %edx, -84(%rbp)
   addl   $1, -88(%rbp)
   jmp   .L3
.L2:
   movl   -84(%rbp), %eax
   addq   $56, %rsp
   popq   %rbx
   popq   %rbp
   ret
   .seh_endproc
   .globl   _Z9ApowBmodMRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj
   .def   _Z9ApowBmodMRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj;   .scl   2;   .type   32;   .endef
   .seh_proc   _Z9ApowBmodMRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj
_Z9ApowBmodMRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj:
.LFB8369:
   pushq   %rbp
   .seh_pushreg   %rbp
   pushq   %rbx
   .seh_pushreg   %rbx
   subq   $88, %rsp
   .seh_stackalloc   88
   leaq   128(%rsp), %rbp
   .seh_setframe   %rbp, 128
   .seh_endprologue
   movq   %rcx, -16(%rbp)
   movl   %edx, -8(%rbp)
   movl   %r8d, 0(%rbp)
   leaq   -96(%rbp), %rax
   movq   -16(%rbp), %rdx
   movq   %rax, %rcx
.LEHB0:
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_
.LEHE0:
   movl   0(%rbp), %edx
   leaq   -96(%rbp), %rax
   movq   %rax, %rcx
.LEHB1:
   call   _Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
.LEHE1:
   movl   %eax, -52(%rbp)
   leaq   -96(%rbp), %rax
   movq   %rax, %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
   movl   -52(%rbp), %eax
   movl   %eax, -60(%rbp)
   movl   $1, -56(%rbp)
.L7:
   movl   -56(%rbp), %eax
   cmpl   -8(%rbp), %eax
   jnb   .L6
   movl   -52(%rbp), %eax
   imull   -60(%rbp), %eax
   movl   $0, %edx
   divl   0(%rbp)
   movl   %edx, -52(%rbp)
   addl   $1, -56(%rbp)
   jmp   .L7
.L6:
   movl   -52(%rbp), %eax
   jmp   .L11
.L10:
   movq   %rax, %rbx
   leaq   -96(%rbp), %rax
   movq   %rax, %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
   movq   %rbx, %rax
   movq   %rax, %rcx
.LEHB2:
   call   _Unwind_Resume
.LEHE2:
.L11:
   addq   $88, %rsp
   popq   %rbx
   popq   %rbp
   ret
   .def   __gxx_personality_seh0;   .scl   2;   .type   32;   .endef
   .seh_handler   __gxx_personality_seh0, @unwind, @except
   .seh_handlerdata
.LLSDA8369:
   .byte   0xff
   .byte   0xff
   .byte   0x1
   .uleb128 .LLSDACSE8369-.LLSDACSB8369
.LLSDACSB8369:
   .uleb128 .LEHB0-.LFB8369
   .uleb128 .LEHE0-.LEHB0
   .uleb128 0
   .uleb128 0
   .uleb128 .LEHB1-.LFB8369
   .uleb128 .LEHE1-.LEHB1
   .uleb128 .L10-.LFB8369
   .uleb128 0
   .uleb128 .LEHB2-.LFB8369
   .uleb128 .LEHE2-.LEHB2
   .uleb128 0
   .uleb128 0
.LLSDACSE8369:
   .text
   .seh_endproc
   .def   __main;   .scl   2;   .type   32;   .endef
   .globl   main
   .def   main;   .scl   2;   .type   32;   .endef
   .seh_proc   main
main:
.LFB8370:
   pushq   %rbp
   .seh_pushreg   %rbp
   pushq   %rbx
   .seh_pushreg   %rbx
   subq   $88, %rsp
   .seh_stackalloc   88
   leaq   128(%rsp), %rbp
   .seh_setframe   %rbp, 128
   .seh_endprologue
   call   __main
   leaq   -80(%rbp), %rax
   movq   %rax, %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev
   leaq   -80(%rbp), %rax
   movq   %rax, %rdx
   movq   .refptr._ZSt3cin(%rip), %rcx
.LEHB3:
   call   _ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE
   movq   %rax, %rcx
   leaq   -84(%rbp), %rax
   movq   %rax, %rdx
   call   _ZNSirsERj
   movq   %rax, %rcx
   leaq   -88(%rbp), %rax
   movq   %rax, %rdx
   call   _ZNSirsERj
   movl   -88(%rbp), %ecx
   movl   -84(%rbp), %edx
   leaq   -80(%rbp), %rax
   movl   %ecx, %r8d
   movq   %rax, %rcx
   call   _Z9ApowBmodMRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjj
   movl   %eax, %edx
   movq   .refptr._ZSt4cout(%rip), %rcx
   call   _ZNSolsEj
.LEHE3:
   movl   $0, %ebx
   leaq   -80(%rbp), %rax
   movq   %rax, %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
   movl   %ebx, %eax
   jmp   .L16
.L15:
   movq   %rax, %rbx
   leaq   -80(%rbp), %rax
   movq   %rax, %rcx
   call   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
   movq   %rbx, %rax
   movq   %rax, %rcx
.LEHB4:
   call   _Unwind_Resume
.LEHE4:
.L16:
   addq   $88, %rsp
   popq   %rbx
   popq   %rbp
   ret
   .seh_handler   __gxx_personality_seh0, @unwind, @except
   .seh_handlerdata
.LLSDA8370:
   .byte   0xff
   .byte   0xff
   .byte   0x1
   .uleb128 .LLSDACSE8370-.LLSDACSB8370
.LLSDACSB8370:
   .uleb128 .LEHB3-.LFB8370
   .uleb128 .LEHE3-.LEHB3
   .uleb128 .L15-.LFB8370
   .uleb128 0
   .uleb128 .LEHB4-.LFB8370
   .uleb128 .LEHE4-.LEHB4
   .uleb128 0
   .uleb128 0
.LLSDACSE8370:
   .text
   .seh_endproc
   .def   __tcf_0;   .scl   3;   .type   32;   .endef
   .seh_proc   __tcf_0
__tcf_0:
.LFB9738:
   pushq   %rbp
   .seh_pushreg   %rbp
   movq   %rsp, %rbp
   .seh_setframe   %rbp, 0
   subq   $32, %rsp
   .seh_stackalloc   32
   .seh_endprologue
   leaq   _ZStL8__ioinit(%rip), %rcx
   call   _ZNSt8ios_base4InitD1Ev
   nop
   addq   $32, %rsp
   popq   %rbp
   ret
   .seh_endproc
   .def   _Z41__static_initialization_and_destruction_0ii;   .scl   3;   .type   32;   .endef
   .seh_proc   _Z41__static_initialization_and_destruction_0ii
_Z41__static_initialization_and_destruction_0ii:
.LFB9737:
   pushq   %rbp
   .seh_pushreg   %rbp
   movq   %rsp, %rbp
   .seh_setframe   %rbp, 0
   subq   $32, %rsp
   .seh_stackalloc   32
   .seh_endprologue
   movl   %ecx, 16(%rbp)
   movl   %edx, 24(%rbp)
   cmpl   $1, 16(%rbp)
   jne   .L20
   cmpl   $65535, 24(%rbp)
   jne   .L20
   leaq   _ZStL8__ioinit(%rip), %rcx
   call   _ZNSt8ios_base4InitC1Ev
   leaq   __tcf_0(%rip), %rcx
   call   atexit
.L20:
   nop
   addq   $32, %rsp
   popq   %rbp
   ret
   .seh_endproc
   .def   _GLOBAL__sub_I__Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj;   .scl   3;   .type   32;   .endef
   .seh_proc   _GLOBAL__sub_I__Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
_GLOBAL__sub_I__Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj:
.LFB9761:
   pushq   %rbp
   .seh_pushreg   %rbp
   movq   %rsp, %rbp
   .seh_setframe   %rbp, 0
   subq   $32, %rsp
   .seh_stackalloc   32
   .seh_endprologue
   movl   $65535, %edx
   movl   $1, %ecx
   call   _Z41__static_initialization_and_destruction_0ii
   nop
   addq   $32, %rsp
   popq   %rbp
   ret
   .seh_endproc
   .section   .ctors,"w"
   .align 8
   .quad   _GLOBAL__sub_I__Z5aModMNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj
   .ident   "GCC: (tdm64-1) 9.2.0"
   .def   _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6lengthEv;   .scl   2;   .type   32;   .endef
   .def   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEy;   .scl   2;   .type   32;   .endef
   .def   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_;   .scl   2;   .type   32;   .endef
   .def   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev;   .scl   2;   .type   32;   .endef
   .def   _Unwind_Resume;   .scl   2;   .type   32;   .endef
   .def   _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev;   .scl   2;   .type   32;   .endef
   .def   _ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE;   .scl   2;   .type   32;   .endef
   .def   _ZNSirsERj;   .scl   2;   .type   32;   .endef
   .def   _ZNSolsEj;   .scl   2;   .type   32;   .endef
   .def   _ZNSt8ios_base4InitD1Ev;   .scl   2;   .type   32;   .endef
   .def   _ZNSt8ios_base4InitC1Ev;   .scl   2;   .type   32;   .endef
   .def   atexit;   .scl   2;   .type   32;   .endef
   .section   .rdata$.refptr._ZSt4cout, "dr"
   .globl   .refptr._ZSt4cout
   .linkonce   discard
.refptr._ZSt4cout:
   .quad   _ZSt4cout
   .section   .rdata$.refptr._ZSt3cin, "dr"
   .globl   .refptr._ZSt3cin
   .linkonce   discard
.refptr._ZSt3cin:
   .quad   _ZSt3cin

One easy way to do this

Download g++ compiler and install it then Open through MiniGW Command Prompt and then type the following command

gcc -S nameOfFile.cpp

HAPPY TO HELP PLEASE COMMENT OFR ANY FURTHER HELP!!!!!!!

Add a comment
Know the answer?
Add Answer to:
need help converting a code in c++ over into MARIE assembly language // C++ program to...
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
  • I am trying to write this code which asks "Write a program that ask the user,...

    I am trying to write this code which asks "Write a program that ask the user, the question: What is a^b? //The program generates two signed integers and gives the user four attempts to get the correct answer //a=- , b = + //a= + , b = - " So far this what I wrote. I am not sure how to do this correctly. #include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main() {    srand(time(0));    int guess,a,ans,b, k;...

  • Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int...

    Convert this C++ program to x86 assembly language using the Irvine library: #include <iostream> unsigned int x; unsigned int c; unsigned int result; // f(x) = 8x + c // Make sure to push and pop all necessary registers to the stack to // ensure only the EAX register is modified upon return from the function unsigned int Equation(unsigned int x, unsigned int c) { // You CANNOT use the mul or imul operations to perform the multiplication return (8...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Convert this C++ code to C to print all possible palindromes of a string #include <bits/stdc++.h>...

    Convert this C++ code to C to print all possible palindromes of a string #include <bits/stdc++.h> #include <iostream> #include<vector> using namespace std; bool isPalindrome(string strData, int first, int last) { while (first < last) { if (strData[first] != strData[last]) return false; first++; last--; } return true; } void allPalPartUtility(vector<vector<string> >&allPart, vector<string> &currentPart, int startPos, int endPos, string strData) { if (startPos >= endPos) { allPart.push_back(currentPart); return; } for (int co = startPos; co < endPos; co++) { if (isPalindrome(strData, startPos,...

  • In PEP8 code. assembly pep8 code. 30. Write an assembly language program that corresponds to the...

    In PEP8 code. assembly pep8 code. 30. Write an assembly language program that corresponds to the following C+ program #include <iostream> using namespace std; int num; int main() cin >> num: num = num/ 16; cout << "num = " << num << endl; return 0; 21 de

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • CAN YU HELP ME CONSTRUCT A FLOW CHART FOR THE FOLLOW PROGRAM ? C++ CODE: #include<iostream>...

    CAN YU HELP ME CONSTRUCT A FLOW CHART FOR THE FOLLOW PROGRAM ? C++ CODE: #include<iostream> using namespace std; int main() { //declaring variable num int num; //prompting user to enter a number cout<<"Input a number to check prime or not:"; //reading input from user cin>>num; //loop to check user input for positive number while(num<0) { cout<<"Error! Positive Integers Only.\n"; cout<<"Input a number to check prime or not:"; cin>>num; } //initializing isPrime variable with false bool isPrime = true; //loop...

  • #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a...

    #include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a string to dashes string to_dash(string s){ for(int i = 0; i < s.length(); i++){ } return s; } int main(){ string s; cin >> s; s = to_dash(s); cout << s << endl; }

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