Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my code: There are many lottery schemes available across the world. Writ

ID: 3740012 • Letter: H

Question

Here is my code:

There are many lottery schemes available across the world. Write a MIPS Assembly language program that will calculate the odds of winning the Jackpot prizes For example o The Euro Millions lottery requires matching 5 numbers from a pool of 50 numbers and matching 2 numbers from a second pool of 11 numbers o The Mega Millions lottery requires matching 5 from 70 and 1 from 25 o The Thunderball lottery requires matching 5 from 39 and matching 1 from 14 o The PowerBall lottery requires matching 5 from 69 and 1 from 26 The subroutine example on the following page, calculates the Factorial of an input integer Starting with the code in the example, write a correct program in MIPS - QtSpim assembly language that 1) Calculates the odds of winning each of the lottery jackpot grand prizes 2) The calculated value is to be displayed on the QtSpim console screen with an appropriate commentary text. Such as "The odds are 1 in nnnn." 3) The program is to accept as input, four values An integer representing the large pool of possible numbers A second integer representing the count of numbers to be selected from the large pool. An integer representing the size of the second smaller pool of numbers A fourth integer representing the count of numbers to be selected from the second pool. 4) Test your program by calculating the odds of choosing a set of 8 numbers from a pool of 15 numbers, and 1 from 2, small pool. The value is " in 12870". Test other combinations Note: Because the largest MIPS single precision integer value will not hold the value of more than 12!, you will need to use some algebra to simplify the calculations. With the simplifications, all of the math can be and must be done using the integer multiply and divide instructions Your program should display a message when it stops Use the System Service calls on page A-44 of the textbook for the input and output

Explanation / Answer

Answer:

Assembly Language Code :

.LC0:

.string "player.dat"

.LC1:

.string "WinningDigits: "

.LC2:

.string " "

.LC3:

.string " Player: "

.LC4:

.string " There are "

.LC5:

.string " matching elements "

.LC6:

.string " "

main:

push rbp

mov rbp, rsp

push rbx

sub rsp, 632

mov DWORD PTR [rbp-40], 7

mov DWORD PTR [rbp-20], 0

lea rax, [rbp-640]

mov rdi, rax

call std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream()

lea rax, [rbp-640]

mov edx, 8

mov esi, OFFSET FLAT:.LC0

mov rdi, rax

call std::basic_ifstream<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)

mov DWORD PTR [rbp-24], 0

.L4:

cmp DWORD PTR [rbp-24], 6

jg .L2

call rand

mov ecx, eax

mov edx, 1717986919

mov eax, ecx

imul edx

sar edx, 2

mov eax, ecx

sar eax, 31

sub edx, eax

mov eax, edx

sal eax, 2

add eax, edx

add eax, eax

sub ecx, eax

mov edx, ecx

mov eax, DWORD PTR [rbp-24]

cdqe

mov DWORD PTR [rbp-80+rax*4], edx

lea rax, [rbp-112]

mov edx, DWORD PTR [rbp-24]

movsx rdx, edx

sal rdx, 2

add rdx, rax

lea rax, [rbp-640]

mov rsi, rdx

mov rdi, rax

call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

mov eax, DWORD PTR [rbp-24]

cdqe

mov edx, DWORD PTR [rbp-80+rax*4]

mov eax, DWORD PTR [rbp-24]

cdqe

mov eax, DWORD PTR [rbp-112+rax*4]

cmp edx, eax

jne .L3

add DWORD PTR [rbp-20], 1

.L3:

add DWORD PTR [rbp-24], 1

jmp .L4

.L2:

mov esi, OFFSET FLAT:.LC1

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*)

mov DWORD PTR [rbp-28], 0

.L6:

cmp DWORD PTR [rbp-28], 6

jg .L5

mov eax, DWORD PTR [rbp-28]

cdqe

mov eax, DWORD PTR [rbp-80+rax*4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC2

mov rdi, rax

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*)

add DWORD PTR [rbp-28], 1

jmp .L6

.L5:

mov esi, OFFSET FLAT:.LC3

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*)

mov DWORD PTR [rbp-32], 0

.L8:

cmp DWORD PTR [rbp-32], 6

jg .L7

mov eax, DWORD PTR [rbp-32]

cdqe

mov eax, DWORD PTR [rbp-112+rax*4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC2

mov rdi, rax

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*)

add DWORD PTR [rbp-32], 1

jmp .L8

.L7:

mov esi, OFFSET FLAT:.LC4

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*)

mov rdx, rax

mov eax, DWORD PTR [rbp-20]

mov esi, eax

mov rdi, rdx

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC5

mov rdi, rax

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 DWORD PTR [rbp-36], 0

.L11:

cmp DWORD PTR [rbp-36], 6

jg .L9

mov eax, DWORD PTR [rbp-36]

cdqe

mov edx, DWORD PTR [rbp-80+rax*4]

mov eax, DWORD PTR [rbp-36]

cdqe

mov eax, DWORD PTR [rbp-112+rax*4]

cmp edx, eax

jne .L10

mov eax, DWORD PTR [rbp-36]

add eax, 1

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC2

mov rdi, rax

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*)

.L10:

add DWORD PTR [rbp-36], 1

jmp .L11

.L9:

mov esi, OFFSET FLAT:.LC6

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-640]

mov rdi, rax

call std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()

mov eax, 0

jmp .L15

mov rbx, rax

lea rax, [rbp-640]

mov rdi, rax

call std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()

mov rax, rbx

mov rdi, rax

call _Unwind_Resume

.L15:

add rsp, 632

pop rbx

pop rbp

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 .L18

cmp DWORD PTR [rbp-8], 65535

jne .L18

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

.L18:

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote