SlideShare a Scribd company logo
1 of 1
Write a MIPS assembly language program that - asks and gets answers for following Y/N
questions: a. Are you attending most sessions of this course (Y/N) ? b. Are you spending
considerable effort for this course (Y/N) ? c. Are you curious about how does a computer work
(Y/N)? - Prints out "You will PASS this course!" if both answers to question a. AND b. are Y
"You will DO WELL!" if all answers are Y "You will FAIL this course!" if all answers are N.
Show test runs for each of the possible outputs.
This should compile and run on MARS.
Solution
.globl main .text main: li $v0, 4 # print welcome message la $a0, welcome syscall la $a0, prompt
# prompt for user input syscall #receive input li $v0, 5 syscall add $s1, $v0, $zero # $s1 = user
input beq $s1, $zero, quit # if input == zero, quit #print 1st prime li $v0, 1 # print int addi $a0,
$zero, 2 # argument = 2 syscall li $v0, 4 # print new line la $a0, line syscall addi $s2, $s2, 1 #
$s2 = 1 (prime counter) add $a2, $a0, $zero # $a2 = $a0 loop: addi $a2, $a2, 1 # argument++
#beq $s2, $s1, quit # if prime counter == input, quit jal test_prime beq $v1, $zero, loop # if
test_prime returns false, repeat addi $s2, $s2, 1 # else $s2++ #print next prime li $v0, 1 # print
int add $a0, $a2, $zero # argument = $a2 syscall li $v0, 4 # print new line la $a0, line syscall beq
$s2, $s1, quit # if prime counter == input, quit j loop test_prime: add $t1, $a2, $zero # $t1 =
argument addi $t2, $zero, 1 # $t2 = 1 loop2: addi $t2, $t2, 1 # $t2++ beq $t2, $t1, true # if $t2 ==
$t1, return div $t3, $t1, $t2 # $t3 = $t1 / $t2 mfhi $t4 # $t4 = remainder beq $t4, $zero, false j
loop2 false: li $v1, 0 # $v1 = false jr $ra true: li $v1, 1 # $v1 = true jr $ra quit: # program exit li
$v0, 10 syscall .data welcome: .asciiz "Prime Numbers " prompt: .asciiz "How many primes?
" line: .asciiz " "

More Related Content

Similar to Write a MIPS assembly language program that - asks and gets answers fo (1).docx

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
tinypigdotcom
 
C programs
C programsC programs
C programs
Minu S
 
1582627
15826271582627
1582627
tabish
 

Similar to Write a MIPS assembly language program that - asks and gets answers fo (1).docx (20)

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Call Execute For Everyone
Call Execute For EveryoneCall Execute For Everyone
Call Execute For Everyone
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
Final assignment sem2.docx
Final assignment sem2.docxFinal assignment sem2.docx
Final assignment sem2.docx
 
C programs
C programsC programs
C programs
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
C code examples
C code examplesC code examples
C code examples
 
PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319PL /SQL program UNIT 5 DMS 22319
PL /SQL program UNIT 5 DMS 22319
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Data Types Master
Data Types MasterData Types Master
Data Types Master
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAP
 
1582627
15826271582627
1582627
 
21221
2122121221
21221
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 

More from noreendchesterton753

Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docxSpongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
noreendchesterton753
 

More from noreendchesterton753 (20)

Suppose the population of interest in a particular study is all Queen'.docx
Suppose the population of interest in a particular study is all Queen'.docxSuppose the population of interest in a particular study is all Queen'.docx
Suppose the population of interest in a particular study is all Queen'.docx
 
Suppose the Federal Reserve increases deposits at financial institutio.docx
Suppose the Federal Reserve increases deposits at financial institutio.docxSuppose the Federal Reserve increases deposits at financial institutio.docx
Suppose the Federal Reserve increases deposits at financial institutio.docx
 
Suppose that Edison and Hilary represent the only two consumers of blu.docx
Suppose that Edison and Hilary represent the only two consumers of blu.docxSuppose that Edison and Hilary represent the only two consumers of blu.docx
Suppose that Edison and Hilary represent the only two consumers of blu.docx
 
Suppose that 42- of Americans are obese- A) If 100 people are randomly.docx
Suppose that 42- of Americans are obese- A) If 100 people are randomly.docxSuppose that 42- of Americans are obese- A) If 100 people are randomly.docx
Suppose that 42- of Americans are obese- A) If 100 people are randomly.docx
 
Suppose I am teaching a class and the test comes and goes with two stu.docx
Suppose I am teaching a class and the test comes and goes with two stu.docxSuppose I am teaching a class and the test comes and goes with two stu.docx
Suppose I am teaching a class and the test comes and goes with two stu.docx
 
Suppose an economy is given by the following- Population -274 million.docx
Suppose an economy is given by the following- Population -274 million.docxSuppose an economy is given by the following- Population -274 million.docx
Suppose an economy is given by the following- Population -274 million.docx
 
Suppose a researcher conducted a study examining the effectiveness of.docx
Suppose a researcher conducted a study examining the effectiveness of.docxSuppose a researcher conducted a study examining the effectiveness of.docx
Suppose a researcher conducted a study examining the effectiveness of.docx
 
Supoese you have 'n' different individuals- and all of them to rearran.docx
Supoese you have 'n' different individuals- and all of them to rearran.docxSupoese you have 'n' different individuals- and all of them to rearran.docx
Supoese you have 'n' different individuals- and all of them to rearran.docx
 
Sunspot Beverages- Limited- of Fiji uses the weighted-average method i.docx
Sunspot Beverages- Limited- of Fiji uses the weighted-average method i.docxSunspot Beverages- Limited- of Fiji uses the weighted-average method i.docx
Sunspot Beverages- Limited- of Fiji uses the weighted-average method i.docx
 
Sunland Company has the following data-Compute total manufacturing cos.docx
Sunland Company has the following data-Compute total manufacturing cos.docxSunland Company has the following data-Compute total manufacturing cos.docx
Sunland Company has the following data-Compute total manufacturing cos.docx
 
Successful negotiating includes some kind of manipulation in order to.docx
Successful negotiating includes some kind of manipulation in order to.docxSuccessful negotiating includes some kind of manipulation in order to.docx
Successful negotiating includes some kind of manipulation in order to.docx
 
Subsidiary holds an allocated net operating loss (NOL) when it leaves.docx
Subsidiary holds an allocated net operating loss (NOL) when it leaves.docxSubsidiary holds an allocated net operating loss (NOL) when it leaves.docx
Subsidiary holds an allocated net operating loss (NOL) when it leaves.docx
 
Substances that dissolve readily in water are termed hydrophilic- They.docx
Substances that dissolve readily in water are termed hydrophilic- They.docxSubstances that dissolve readily in water are termed hydrophilic- They.docx
Substances that dissolve readily in water are termed hydrophilic- They.docx
 
subject FASHION The combination of which Roman terms most closely co.docx
subject FASHION   The combination of which Roman terms most closely co.docxsubject FASHION   The combination of which Roman terms most closely co.docx
subject FASHION The combination of which Roman terms most closely co.docx
 
Styling Conventions By only changing the case of some of the letters-.docx
Styling Conventions By only changing the case of some of the letters-.docxStyling Conventions By only changing the case of some of the letters-.docx
Styling Conventions By only changing the case of some of the letters-.docx
 
Students spend an average of $520 each semester on textbooks- Suppose.docx
Students spend an average of $520 each semester on textbooks- Suppose.docxStudents spend an average of $520 each semester on textbooks- Suppose.docx
Students spend an average of $520 each semester on textbooks- Suppose.docx
 
Species interactions determine an organism's fundamental niche- True F.docx
Species interactions determine an organism's fundamental niche- True F.docxSpecies interactions determine an organism's fundamental niche- True F.docx
Species interactions determine an organism's fundamental niche- True F.docx
 
Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docxSpongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
Spongy moths- Lymantria dispar- have four life cycle stages- egg- cate.docx
 
SPSS output of a binomial probability distribution with succes probabi.docx
SPSS output of a binomial probability distribution with succes probabi.docxSPSS output of a binomial probability distribution with succes probabi.docx
SPSS output of a binomial probability distribution with succes probabi.docx
 
Starting on the day Holly was born- her mother has invested $30 at the.docx
Starting on the day Holly was born- her mother has invested $30 at the.docxStarting on the day Holly was born- her mother has invested $30 at the.docx
Starting on the day Holly was born- her mother has invested $30 at the.docx
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
Krashi Coaching
 

Recently uploaded (20)

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
Envelope of Discrepancy in Orthodontics: Enhancing Precision in Treatment
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

Write a MIPS assembly language program that - asks and gets answers fo (1).docx

  • 1. Write a MIPS assembly language program that - asks and gets answers for following Y/N questions: a. Are you attending most sessions of this course (Y/N) ? b. Are you spending considerable effort for this course (Y/N) ? c. Are you curious about how does a computer work (Y/N)? - Prints out "You will PASS this course!" if both answers to question a. AND b. are Y "You will DO WELL!" if all answers are Y "You will FAIL this course!" if all answers are N. Show test runs for each of the possible outputs. This should compile and run on MARS. Solution .globl main .text main: li $v0, 4 # print welcome message la $a0, welcome syscall la $a0, prompt # prompt for user input syscall #receive input li $v0, 5 syscall add $s1, $v0, $zero # $s1 = user input beq $s1, $zero, quit # if input == zero, quit #print 1st prime li $v0, 1 # print int addi $a0, $zero, 2 # argument = 2 syscall li $v0, 4 # print new line la $a0, line syscall addi $s2, $s2, 1 # $s2 = 1 (prime counter) add $a2, $a0, $zero # $a2 = $a0 loop: addi $a2, $a2, 1 # argument++ #beq $s2, $s1, quit # if prime counter == input, quit jal test_prime beq $v1, $zero, loop # if test_prime returns false, repeat addi $s2, $s2, 1 # else $s2++ #print next prime li $v0, 1 # print int add $a0, $a2, $zero # argument = $a2 syscall li $v0, 4 # print new line la $a0, line syscall beq $s2, $s1, quit # if prime counter == input, quit j loop test_prime: add $t1, $a2, $zero # $t1 = argument addi $t2, $zero, 1 # $t2 = 1 loop2: addi $t2, $t2, 1 # $t2++ beq $t2, $t1, true # if $t2 == $t1, return div $t3, $t1, $t2 # $t3 = $t1 / $t2 mfhi $t4 # $t4 = remainder beq $t4, $zero, false j loop2 false: li $v1, 0 # $v1 = false jr $ra true: li $v1, 1 # $v1 = true jr $ra quit: # program exit li $v0, 10 syscall .data welcome: .asciiz "Prime Numbers " prompt: .asciiz "How many primes? " line: .asciiz " "