Convert the following c++ code into MIPS Assembly code. 1. The user is allowed t
ID: 642597 • Letter: C
Question
Convert the following c++ code into MIPS Assembly code.
1. The user is allowed to type in 10 positive integers plus an occurrence value (meaning 11 inputs). a. The 10 integers should be handled in a loop where each value input by the user is stored into memory in an array like structure. b. The input occurrence is also an integer which represents a value present (or not) in the input array. 2. Then, the program will loop through the array and find any matching with the input occurrence value. 3. When finding a matching, its index inside the array will be output and the number of occurrences found will be incremented by 1. 4. At the end of the loop, the program will print out the number of occurrences found. The C++ code for this program is as such:
main()
{
int x[10], occur, count = 0;
Cout << "Type in array numbers:" << endl;
for (int i=0; i<10; i++) // reading in integers
{
Cin >> X[i];
}
Cout << "Type in occurrence value:" << endl;
Cin >> occur;
// Finding and printing out occurrence indexes in the array
Cout << "Occurrences indexes are:" << endl;
for (int i=0; i<10; i++)
{
If (x[i] == occur)
{
Cout << i;
count ++;
}
}
Cout << "Number of occurrences found:" << endl;
Cout << count;
exit(0); }
Explanation / Answer
.Ltext0:
.globl x
.bss
.align 32
x:
0000 00000000 .zero 40
00000000
00000000
00000000
00000000
.globl occur
.align 4
occur:
0028 00000000 .zero 4
.globl count
.align 4
count:
002c 00000000 .zero 4
.text
.Letext0:
0000 55 pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
0001 4889E5 movq %rsp, %rbp
.cfi_def_cfa_register 6
0004 4883EC10 subq $16, %rsp
.LBB2:
0008 C745F802 movl $2, -8(%rbp)
000000
000f 8B55F8 movl -8(%rbp), %edx
0012 89D0 movl %edx, %eax
0014 C1E002 sall $2, %eax
0017 01D0 addl %edx, %eax
0019 C1E002 sall $2, %eax
001c 83C002 addl $2, %eax
001f 8945F8 movl %eax, -8(%rbp)
0022 C745FC00 movl $0, -4(%rbp)
000000
0029 EB0A jmp .L2
.L3:
0031 8345FC01 addl $1, -4(%rbp)
002b 8B45FC movl -4(%rbp), %eax
002e 0145F8 addl %eax, -8(%rbp)
.L2:
0035 837DFC63 cmpl $99, -4(%rbp)
0039 7EF0 jle .L3
003b 8B45F8 movl -8(%rbp), %eax
003e 89C6 movl %eax, %esi
0040 BF000000 movl $.LC0, %edi
00
0045 B8000000 movl $0, %eax
00
004a E8000000 call printf
00
004f B8000000 movl $0, %eax
00
.LBE2:
0054 C9 leave
.cfi_def_cfa 7, 8
0055 C3 ret
.cfi_endproc
.LFE2:
.Letext0: