Question

using Mips assembly to work on Mars simulator write a program that outputs the maximum and...

using Mips assembly to work on Mars simulator

write a program that outputs the maximum and minimum values of an entered array

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

MIPS Assembly level program that outputs maximum and minimum values of an entered array:

.LC0:
.string "Enter the size of the array : "
.LC1:
.string "Enter the elements of the array : "
.LC2:
.string "Maximum element : "
.LC3:
.string "Minimum element : "
main:
push rbp
mov rbp, rsp
sub rsp, 80
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:_ZSt4cout
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-68]
mov rsi, rax
mov edi, OFFSET FLAT:_ZSt3cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:_ZSt4cout
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-4], 0
.L3:
mov eax, DWORD PTR [rbp-68]
cmp DWORD PTR [rbp-4], eax
jge .L2
lea rax, [rbp-64]
mov edx, DWORD PTR [rbp-4]
movsx rdx, edx
sal rdx, 2
add rax, rdx
mov rsi, rax
mov edi, OFFSET FLAT:_ZSt3cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
add DWORD PTR [rbp-4], 1
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-64]
mov DWORD PTR [rbp-8], eax
mov DWORD PTR [rbp-4], 0
.L6:
mov eax, DWORD PTR [rbp-68]
cmp DWORD PTR [rbp-4], eax
jge .L4
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
cmp DWORD PTR [rbp-8], eax
jge .L5
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
mov DWORD PTR [rbp-8], eax
.L5:
add DWORD PTR [rbp-4], 1
jmp .L6
.L4:
mov eax, DWORD PTR [rbp-64]
mov DWORD PTR [rbp-12], eax
mov DWORD PTR [rbp-4], 0
.L9:
mov eax, DWORD PTR [rbp-68]
cmp DWORD PTR [rbp-4], eax
jge .L7
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
cmp DWORD PTR [rbp-12], eax
jle .L8
mov eax, DWORD PTR [rbp-4]
cdqe
mov eax, DWORD PTR [rbp-64+rax*4]
mov DWORD PTR [rbp-12], eax
.L8:
add DWORD PTR [rbp-4], 1
jmp .L9
.L7:
mov esi, OFFSET FLAT:.LC2
mov edi, OFFSET FLAT:_ZSt4cout
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-8]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:.LC3
mov edi, OFFSET FLAT:_ZSt4cout
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-12]
mov esi, eax
mov rdi, rdx
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 .L13
cmp DWORD PTR [rbp-8], 65535
jne .L13
mov edi, OFFSET FLAT:_ZStL8__ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:_ZStL8__ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
call __cxa_atexit
.L13:
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

Add a comment
Know the answer?
Add Answer to:
using Mips assembly to work on Mars simulator write a program that outputs the maximum and...
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
  • MIPS 1(a): Using MARS (MIPS assembly simulator), write and debug a program with comments that will...

    MIPS 1(a): Using MARS (MIPS assembly simulator), write and debug a program with comments that will store words in a RAM array using the instruction sw and indirect addressing as specified in the data table below. Although the addresses and data are in given hexadecimal, your code will contain corresponding values in decimal. Use (268501056)_10 = (10010040)_16 as the base address of the array. Since the instruction sw and indirect addressing (using offsets) are needed to store the data in...

  • Using MARS simulator, write MIPS programs according to the following scenarios: Receive a positive integer number...

    Using MARS simulator, write MIPS programs according to the following scenarios: Receive a positive integer number from the user and print out “prime”/“not prime” result if the entered number is prime or not. Remarks: • Write your name and Id inside the program file.(my name is Nabil Mohsen Alzeqri)and (my ID: 61330237) • All programs must be commented. • A description of the method used in the program should be provided. • The program should have been already tested using...

  • The program I'm using is MIPS (mars) assembly; Write a program that in the main routine...

    The program I'm using is MIPS (mars) assembly; Write a program that in the main routine ask the user input n numbers(2<n<11) and pass n and array pointer to FillArray to stores numbers in the array. Main again passes the pointer to AddElement Function to add the elements of the array, and return the result back to main to print it.                                                                                                                                          

  • IN MIPS MACHINE LANGUAGE FOR MARS SIMULATOR Write your own short program that presents a RAW...

    IN MIPS MACHINE LANGUAGE FOR MARS SIMULATOR Write your own short program that presents a RAW data dependence condition (2-5 instructions in MIPS that exhibits a data hazard). Document the hazard condition in your code comments.

  • Need to write a MIPS assembly program that finds the minimum and maximum and sum of...

    Need to write a MIPS assembly program that finds the minimum and maximum and sum of a stored array. It also finds the locations of the minimum and maximum. The interaction between the main program and the function is solely through the stack. The function stores $ra immediately after being called and restores $ra before returning to main. The main program reserves a static C like array (index starts from 0) of 10 elements and initializes it. The maximum should...

  • Using MARS simulator, write MIPS programs according to the following scenarios: Receive an integer from the...

    Using MARS simulator, write MIPS programs according to the following scenarios: Receive an integer from the user and print out the individual bit of that number in binary format

  • Create a cache memory using mips in mars. The input of the simulator will be a file (or an array...

    Create a cache memory using mips in mars. The input of the simulator will be a file (or an array) with integers that represent a sequence of accesses to memory blocks. Each number represents a block of memory. The output of the simulator will be the number of hits for each cache configuration as well as the number of instructions executed. The results must be presented with the sequence of memory blocks delivered. While you are implementing your cache, you...

  • Program the code using MARS simulator; Loops Write a program to calculate m n (m to...

    Program the code using MARS simulator; Loops Write a program to calculate m n (m to the power of n). Sample of input/output Enter a value for m! 2 Enter a value for n! 3 2 to the power of 3 = 8

  • Linear Search: Write a MIPS assembly language program that can search for a number that entered...

    Linear Search: Write a MIPS assembly language program that can search for a number that entered by user in an array with 20 integer numbers and prints the index of the number in the array if it is found and -1 if not found

  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...

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