Question

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 MARS
• For more information of how to input/output values in MIPS refer to MARS help manual

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

The MIPS program is:

$LC0:

.ascii "Enter the Number to check Prime: \000"

$LC1:

.ascii "not prime.\000"

$LC2:

.ascii "prime.\000"

main:

addiu $sp,$sp,-48

sw $31,44($sp)

sw $fp,40($sp)

move $fp,$sp

sw $0,32($fp)

sw $0,28($fp)

lui $2,%hi($LC0)

addiu $5,$2,%lo($LC0)

lui $2,%hi(_ZSt4cout)

addiu $4,$2,%lo(_ZSt4cout)

jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >  (std::basic_ostream<char, std::char_traits<char> >&, char const*)

nop

addiu $2,$fp,36

move $5,$2

lui $2,%hi(_ZSt3cin)

addiu $4,$2,%lo(_ZSt3cin)

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

nop

lw $2,36($fp)

nop

srl $3,$2,31

addu $2,$3,$2

sra $2,$2,1

sw $2,32($fp)

li $2,2 # 0x2

sw $2,24($fp)

$L4:

lw $3,24($fp)

lw $2,32($fp)

nop

slt $2,$2,$3

bne $2,$0,$L2

nop

lw $3,36($fp)

lw $2,24($fp)

nop

bne $2,$0,1f

div $0,$3,$2

break 7

1:

mfhi $2

bne $2,$0,$L3

nop

lui $2,%hi($LC1)

addiu $5,$2,%lo($LC1)

lui $2,%hi(_ZSt4cout)

addiu $4,$2,%lo(_ZSt4cout)

jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> > (std::basic_ostream<char, std::char_traits<char> >&, char const*)

nop

move $3,$2

lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

move $4,$3

jal 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> >&))

nop

li $2,1 # 0x1

sw $2,28($fp)

b $L2

nop

$L3:

lw $2,24($fp)

nop

addiu $2,$2,1

sw $2,24($fp)

b $L4

nop

$L2:

lw $2,28($fp)

nop

bne $2,$0,$L5

nop

lui $2,%hi($LC2)

addiu $5,$2,%lo($LC2)

lui $2,%hi(_ZSt4cout)

addiu $4,$2,%lo(_ZSt4cout)

jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

nop

move $3,$2

lui $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

addiu $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

move $4,$3

jal 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> >&))

nop

$L5:

move $2,$0

move $sp,$fp

lw $31,44($sp)

lw $fp,40($sp)

addiu $sp,$sp,48

j $31

nop

__static_initialization_and_destruction_0(int, int):

addiu $sp,$sp,-32

sw $31,28($sp)

sw $fp,24($sp)

move $fp,$sp

sw $4,32($fp)

sw $5,36($fp)

lw $3,32($fp)

li $2,1 # 0x1

bne $3,$2,$L9

nop

lw $3,36($fp)

li $2,65535 # 0xffff

bne $3,$2,$L9

nop

lui $2,%hi(_ZStL8__ioinit)

addiu $4,$2,%lo(_ZStL8__ioinit)

jal std::ios_base::Init::Init() [complete object constructor]

nop

lui $2,%hi(__dso_handle)

addiu $6,$2,%lo(__dso_handle)

lui $2,%hi(_ZStL8__ioinit)

addiu $5,$2,%lo(_ZStL8__ioinit)

lui $2,%hi(_ZNSt8ios_base4InitD1Ev)

addiu $4,$2,%lo(_ZNSt8ios_base4InitD1Ev)

jal __cxa_atexit

nop

$L9:

nop

move $sp,$fp

lw $31,28($sp)

lw $fp,24($sp)

addiu $sp,$sp,32

j $31

nop

_GLOBAL__sub_I_main:

addiu $sp,$sp,-32

sw $31,28($sp)

sw $fp,24($sp)

move $fp,$sp

li $5,65535 # 0xffff

li $4,1 # 0x1

jal __static_initialization_and_destruction_0(int, int)

nop

move $sp,$fp

lw $31,28($sp)

lw $fp,24($sp)

addiu $sp,$sp,32

j $31

nop

Add a comment
Know the answer?
Add Answer to:
Using MARS simulator, write MIPS programs according to the following scenarios: Receive a positive integer number...
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
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
ADVERTISEMENT