SlideShare a Scribd company logo
1 of 8
Download to read offline
Consider the following C code snippet:
// C code
void setArray(int num) {
int i;
int array[10];
for (i=0; i < 10; i=i+1) {
array[i]=compare(num, i);
}
}
int compare(int a, int b) {
if (sub(a, b) >= 0)
return 1;
else
return 0;
}
int sub(int a, int b) {
return ab;
}
Implement the C code snippet above in MIPS assembly language. Use $s0 to hold the variable i.
Be sure to handle the stack pointer appropriately. The array is stored on the stack of the setArray
function (i.e. when setArray function is called it allocates space for the array on the stack.).
Solution
I have used the Test function i.e ain function to get this module of the fuction definition working.
Thw below is the MIPS code for the complete program:-
.file 1 ""
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.abicalls
.text
.align 2
.globl _Z3subii
$LFB0 = .
.set nomips16
.ent _Z3subii
.type _Z3subii, @function
_Z3subii:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
.mask 0x40000000,-4
.fmask 0x00000000,0
.set noreorder
.set nomacro
addiu $sp,$sp,-8
$LCFI0:
sw $fp,4($sp)
$LCFI1:
move $fp,$sp
movz $31,$31,$0
$LCFI2:
sw $4,8($fp)
sw $5,12($fp)
lw $3,8($fp)
lw $2,12($fp)
nop
subu $2,$3,$2
move $sp,$fp
lw $fp,4($sp)
addiu $sp,$sp,8
j $31
nop
.set macro
.set reorder
.end _Z3subii
$LFE0:
.size _Z3subii, .-_Z3subii
.align 2
.globl _Z7compareii
$LFB1 = .
.set nomips16
.ent _Z7compareii
.type _Z7compareii, @function
_Z7compareii:
.frame $fp,32,$31 # vars= 0, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-32
$LCFI3:
sw $31,28($sp)
$LCFI4:
sw $fp,24($sp)
movz $31,$31,$0
$LCFI5:
move $fp,$sp
$LCFI6:
.cprestore 16
sw $4,32($fp)
sw $5,36($fp)
lw $4,32($fp)
lw $5,36($fp)
lw $2,%got(_Z3subii)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
nor $2,$0,$2
srl $2,$2,31
andi $2,$2,0x00ff
beq $2,$0,$L4
nop
li $2,1 # 0x1
b $L5
nop
$L4:
move $2,$0
$L5:
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
.set macro
.set reorder
.end _Z7compareii
$LFE1:
.size _Z7compareii, .-_Z7compareii
.align 2
.globl _Z8setArrayi
$LFB2 = .
.set nomips16
.ent _Z8setArrayi
.type _Z8setArrayi, @function
_Z8setArrayi:
.frame $fp,88,$31 # vars= 48, regs= 3/0, args= 16, gp= 8
.mask 0xc0010000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-88
$LCFI7:
sw $31,84($sp)
$LCFI8:
sw $fp,80($sp)
movz $31,$31,$0
$LCFI9:
sw $16,76($sp)
$LCFI10:
move $fp,$sp
$LCFI11:
.cprestore 16
sw $4,88($fp)
sw $0,24($fp)
b $L8
nop
$L9:
lw $16,24($fp)
lw $4,88($fp)
lw $5,24($fp)
lw $2,%got(_Z7compareii)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $3,$2
sll $2,$16,2
addiu $4,$fp,24
addu $2,$4,$2
sw $3,4($2)
lw $2,24($fp)
nop
addiu $2,$2,1
sw $2,24($fp)
$L8:
lw $2,24($fp)
nop
slt $2,$2,10
andi $2,$2,0x00ff
bne $2,$0,$L9
nop
move $sp,$fp
lw $31,84($sp)
lw $fp,80($sp)
lw $16,76($sp)
addiu $sp,$sp,88
j $31
nop
.set macro
.set reorder
.end _Z8setArrayi
$LFE2:
.size _Z8setArrayi, .-_Z8setArrayi
.align 2
.globl main
$LFB3 = .
.set nomips16
.ent main
.type main, @function
main:
.frame $fp,48,$31 # vars= 16, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-48
$LCFI12:
sw $31,44($sp)
$LCFI13:
sw $fp,40($sp)
movz $31,$31,$0
$LCFI14:
move $fp,$sp
$LCFI15:
.cprestore 16
li $2,5 # 0x5
sw $2,32($fp)
li $2,10 # 0xa
sw $2,28($fp)
li $2,8 # 0x8
sw $2,24($fp)
li $4,5 # 0x5
lw $2,%got(_Z8setArrayi)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $4,28($fp)
lw $5,24($fp)
lw $2,%got(_Z7compareii)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
lw $4,28($fp)
lw $5,24($fp)
lw $2,%got(_Z3subii)($28)
nop
move $25,$2
jalr $25
nop
lw $28,16($fp)
move $2,$0
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
addiu $sp,$sp,48
j $31
nop
.set macro
.set reorder
.end main

More Related Content

Similar to Consider the following C code snippet C codevoid setArray(int.pdf

Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterakaptur
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9Andrey Zakharevich
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdfsrxerox
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray EnginePVS-Studio
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 
MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdfXxUnnathxX
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
Catastrophic Cancellation
Catastrophic CancellationCatastrophic Cancellation
Catastrophic CancellationC4Media
 
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -Wataru Kani
 
Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Deepak Singh
 

Similar to Consider the following C code snippet C codevoid setArray(int.pdf (20)

Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
Коварный code type ITGM #9
Коварный code type ITGM #9Коварный code type ITGM #9
Коварный code type ITGM #9
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
III MCS python lab (1).pdf
III MCS python lab (1).pdfIII MCS python lab (1).pdf
III MCS python lab (1).pdf
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Anomalies in X-Ray Engine
Anomalies in X-Ray EngineAnomalies in X-Ray Engine
Anomalies in X-Ray Engine
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
MIPS_Programming.pdf
MIPS_Programming.pdfMIPS_Programming.pdf
MIPS_Programming.pdf
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Catastrophic Cancellation
Catastrophic CancellationCatastrophic Cancellation
Catastrophic Cancellation
 
Sbaw090623
Sbaw090623Sbaw090623
Sbaw090623
 
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
第二回 冬のスイッチ大勉強会 - FullColorLED & MPU-6050編 -
 
Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000
 

More from arihantmum

In 2012, the percent of American adults who owned cell phones and us.pdf
In 2012, the percent of American adults who owned cell phones and us.pdfIn 2012, the percent of American adults who owned cell phones and us.pdf
In 2012, the percent of American adults who owned cell phones and us.pdfarihantmum
 
In a multiple regression model, the error term e is assumed tohave.pdf
In a multiple regression model, the error term e is assumed tohave.pdfIn a multiple regression model, the error term e is assumed tohave.pdf
In a multiple regression model, the error term e is assumed tohave.pdfarihantmum
 
I need help with this one method in java. Here are the guidelines. O.pdf
I need help with this one method in java. Here are the guidelines. O.pdfI need help with this one method in java. Here are the guidelines. O.pdf
I need help with this one method in java. Here are the guidelines. O.pdfarihantmum
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfarihantmum
 
Heading ibe the following picture. Main computer UART DTE Serial chan.pdf
Heading ibe the following picture. Main computer UART DTE Serial chan.pdfHeading ibe the following picture. Main computer UART DTE Serial chan.pdf
Heading ibe the following picture. Main computer UART DTE Serial chan.pdfarihantmum
 
Explain how TWO (2) different structural features can be used to dis.pdf
Explain how TWO (2) different structural features can be used to dis.pdfExplain how TWO (2) different structural features can be used to dis.pdf
Explain how TWO (2) different structural features can be used to dis.pdfarihantmum
 
Explain two (2) alternative ways in which plants can obtain nutrient.pdf
Explain two (2) alternative ways in which plants can obtain nutrient.pdfExplain two (2) alternative ways in which plants can obtain nutrient.pdf
Explain two (2) alternative ways in which plants can obtain nutrient.pdfarihantmum
 
Couldnt find the right subject that it belongs to...There ar.pdf
Couldnt find the right subject that it belongs to...There ar.pdfCouldnt find the right subject that it belongs to...There ar.pdf
Couldnt find the right subject that it belongs to...There ar.pdfarihantmum
 
Describe a mechanism that the body uses to prevent a mutation from be.pdf
Describe a mechanism that the body uses to prevent a mutation from be.pdfDescribe a mechanism that the body uses to prevent a mutation from be.pdf
Describe a mechanism that the body uses to prevent a mutation from be.pdfarihantmum
 
classify domian of life differencesSolutionClassify the domain.pdf
classify domian of life differencesSolutionClassify the domain.pdfclassify domian of life differencesSolutionClassify the domain.pdf
classify domian of life differencesSolutionClassify the domain.pdfarihantmum
 
Compare and contrast the development of a WBS in traditional project.pdf
Compare and contrast the development of a WBS in traditional project.pdfCompare and contrast the development of a WBS in traditional project.pdf
Compare and contrast the development of a WBS in traditional project.pdfarihantmum
 
B. You are an evolutionary biologist in a heated argument with a cre.pdf
B. You are an evolutionary biologist in a heated argument with a cre.pdfB. You are an evolutionary biologist in a heated argument with a cre.pdf
B. You are an evolutionary biologist in a heated argument with a cre.pdfarihantmum
 
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdf
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdfAssume Hashtable is a simple array of size 8, with indices 0..7. Num.pdf
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdfarihantmum
 
Amon the following, which has the lowest levels of dissolved iron.pdf
Amon the following, which has the lowest levels of dissolved iron.pdfAmon the following, which has the lowest levels of dissolved iron.pdf
Amon the following, which has the lowest levels of dissolved iron.pdfarihantmum
 
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdf
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdfA box contains 10 red balls and 40 black balls. Two balls are drawn .pdf
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdfarihantmum
 
As late as 1992, the United States was running budget deficits of ne.pdf
As late as 1992, the United States was running budget deficits of ne.pdfAs late as 1992, the United States was running budget deficits of ne.pdf
As late as 1992, the United States was running budget deficits of ne.pdfarihantmum
 
A bacteriophage population is introduced to a bacterial colony that .pdf
A bacteriophage population is introduced to a bacterial colony that .pdfA bacteriophage population is introduced to a bacterial colony that .pdf
A bacteriophage population is introduced to a bacterial colony that .pdfarihantmum
 
Xavier and Yolanda both have classes that end at noon and they agree .pdf
Xavier and Yolanda both have classes that end at noon and they agree .pdfXavier and Yolanda both have classes that end at noon and they agree .pdf
Xavier and Yolanda both have classes that end at noon and they agree .pdfarihantmum
 
1. Low platelet count is a recessively inherited trait. Reevaluation.pdf
1. Low platelet count is a recessively inherited trait. Reevaluation.pdf1. Low platelet count is a recessively inherited trait. Reevaluation.pdf
1. Low platelet count is a recessively inherited trait. Reevaluation.pdfarihantmum
 
1. An important contribution of Fiedlers research on the contingen.pdf
1. An important contribution of Fiedlers research on the contingen.pdf1. An important contribution of Fiedlers research on the contingen.pdf
1. An important contribution of Fiedlers research on the contingen.pdfarihantmum
 

More from arihantmum (20)

In 2012, the percent of American adults who owned cell phones and us.pdf
In 2012, the percent of American adults who owned cell phones and us.pdfIn 2012, the percent of American adults who owned cell phones and us.pdf
In 2012, the percent of American adults who owned cell phones and us.pdf
 
In a multiple regression model, the error term e is assumed tohave.pdf
In a multiple regression model, the error term e is assumed tohave.pdfIn a multiple regression model, the error term e is assumed tohave.pdf
In a multiple regression model, the error term e is assumed tohave.pdf
 
I need help with this one method in java. Here are the guidelines. O.pdf
I need help with this one method in java. Here are the guidelines. O.pdfI need help with this one method in java. Here are the guidelines. O.pdf
I need help with this one method in java. Here are the guidelines. O.pdf
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
Heading ibe the following picture. Main computer UART DTE Serial chan.pdf
Heading ibe the following picture. Main computer UART DTE Serial chan.pdfHeading ibe the following picture. Main computer UART DTE Serial chan.pdf
Heading ibe the following picture. Main computer UART DTE Serial chan.pdf
 
Explain how TWO (2) different structural features can be used to dis.pdf
Explain how TWO (2) different structural features can be used to dis.pdfExplain how TWO (2) different structural features can be used to dis.pdf
Explain how TWO (2) different structural features can be used to dis.pdf
 
Explain two (2) alternative ways in which plants can obtain nutrient.pdf
Explain two (2) alternative ways in which plants can obtain nutrient.pdfExplain two (2) alternative ways in which plants can obtain nutrient.pdf
Explain two (2) alternative ways in which plants can obtain nutrient.pdf
 
Couldnt find the right subject that it belongs to...There ar.pdf
Couldnt find the right subject that it belongs to...There ar.pdfCouldnt find the right subject that it belongs to...There ar.pdf
Couldnt find the right subject that it belongs to...There ar.pdf
 
Describe a mechanism that the body uses to prevent a mutation from be.pdf
Describe a mechanism that the body uses to prevent a mutation from be.pdfDescribe a mechanism that the body uses to prevent a mutation from be.pdf
Describe a mechanism that the body uses to prevent a mutation from be.pdf
 
classify domian of life differencesSolutionClassify the domain.pdf
classify domian of life differencesSolutionClassify the domain.pdfclassify domian of life differencesSolutionClassify the domain.pdf
classify domian of life differencesSolutionClassify the domain.pdf
 
Compare and contrast the development of a WBS in traditional project.pdf
Compare and contrast the development of a WBS in traditional project.pdfCompare and contrast the development of a WBS in traditional project.pdf
Compare and contrast the development of a WBS in traditional project.pdf
 
B. You are an evolutionary biologist in a heated argument with a cre.pdf
B. You are an evolutionary biologist in a heated argument with a cre.pdfB. You are an evolutionary biologist in a heated argument with a cre.pdf
B. You are an evolutionary biologist in a heated argument with a cre.pdf
 
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdf
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdfAssume Hashtable is a simple array of size 8, with indices 0..7. Num.pdf
Assume Hashtable is a simple array of size 8, with indices 0..7. Num.pdf
 
Amon the following, which has the lowest levels of dissolved iron.pdf
Amon the following, which has the lowest levels of dissolved iron.pdfAmon the following, which has the lowest levels of dissolved iron.pdf
Amon the following, which has the lowest levels of dissolved iron.pdf
 
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdf
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdfA box contains 10 red balls and 40 black balls. Two balls are drawn .pdf
A box contains 10 red balls and 40 black balls. Two balls are drawn .pdf
 
As late as 1992, the United States was running budget deficits of ne.pdf
As late as 1992, the United States was running budget deficits of ne.pdfAs late as 1992, the United States was running budget deficits of ne.pdf
As late as 1992, the United States was running budget deficits of ne.pdf
 
A bacteriophage population is introduced to a bacterial colony that .pdf
A bacteriophage population is introduced to a bacterial colony that .pdfA bacteriophage population is introduced to a bacterial colony that .pdf
A bacteriophage population is introduced to a bacterial colony that .pdf
 
Xavier and Yolanda both have classes that end at noon and they agree .pdf
Xavier and Yolanda both have classes that end at noon and they agree .pdfXavier and Yolanda both have classes that end at noon and they agree .pdf
Xavier and Yolanda both have classes that end at noon and they agree .pdf
 
1. Low platelet count is a recessively inherited trait. Reevaluation.pdf
1. Low platelet count is a recessively inherited trait. Reevaluation.pdf1. Low platelet count is a recessively inherited trait. Reevaluation.pdf
1. Low platelet count is a recessively inherited trait. Reevaluation.pdf
 
1. An important contribution of Fiedlers research on the contingen.pdf
1. An important contribution of Fiedlers research on the contingen.pdf1. An important contribution of Fiedlers research on the contingen.pdf
1. An important contribution of Fiedlers research on the contingen.pdf
 

Recently uploaded

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 

Recently uploaded (20)

Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 

Consider the following C code snippet C codevoid setArray(int.pdf

  • 1. Consider the following C code snippet: // C code void setArray(int num) { int i; int array[10]; for (i=0; i < 10; i=i+1) { array[i]=compare(num, i); } } int compare(int a, int b) { if (sub(a, b) >= 0) return 1; else return 0; } int sub(int a, int b) { return ab; } Implement the C code snippet above in MIPS assembly language. Use $s0 to hold the variable i. Be sure to handle the stack pointer appropriately. The array is stored on the stack of the setArray function (i.e. when setArray function is called it allocates space for the array on the stack.). Solution I have used the Test function i.e ain function to get this module of the fuction definition working. Thw below is the MIPS code for the complete program:- .file 1 "" .section .mdebug.abi32 .previous .gnu_attribute 4, 1 .abicalls .text .align 2 .globl _Z3subii $LFB0 = .
  • 2. .set nomips16 .ent _Z3subii .type _Z3subii, @function _Z3subii: .frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0 .mask 0x40000000,-4 .fmask 0x00000000,0 .set noreorder .set nomacro addiu $sp,$sp,-8 $LCFI0: sw $fp,4($sp) $LCFI1: move $fp,$sp movz $31,$31,$0 $LCFI2: sw $4,8($fp) sw $5,12($fp) lw $3,8($fp) lw $2,12($fp) nop subu $2,$3,$2 move $sp,$fp lw $fp,4($sp) addiu $sp,$sp,8 j $31 nop .set macro .set reorder .end _Z3subii $LFE0: .size _Z3subii, .-_Z3subii .align 2 .globl _Z7compareii $LFB1 = .
  • 3. .set nomips16 .ent _Z7compareii .type _Z7compareii, @function _Z7compareii: .frame $fp,32,$31 # vars= 0, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-32 $LCFI3: sw $31,28($sp) $LCFI4: sw $fp,24($sp) movz $31,$31,$0 $LCFI5: move $fp,$sp $LCFI6: .cprestore 16 sw $4,32($fp) sw $5,36($fp) lw $4,32($fp) lw $5,36($fp) lw $2,%got(_Z3subii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) nor $2,$0,$2 srl $2,$2,31 andi $2,$2,0x00ff beq $2,$0,$L4 nop
  • 4. li $2,1 # 0x1 b $L5 nop $L4: move $2,$0 $L5: move $sp,$fp lw $31,28($sp) lw $fp,24($sp) addiu $sp,$sp,32 j $31 nop .set macro .set reorder .end _Z7compareii $LFE1: .size _Z7compareii, .-_Z7compareii .align 2 .globl _Z8setArrayi $LFB2 = . .set nomips16 .ent _Z8setArrayi .type _Z8setArrayi, @function _Z8setArrayi: .frame $fp,88,$31 # vars= 48, regs= 3/0, args= 16, gp= 8 .mask 0xc0010000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-88 $LCFI7: sw $31,84($sp) $LCFI8: sw $fp,80($sp)
  • 5. movz $31,$31,$0 $LCFI9: sw $16,76($sp) $LCFI10: move $fp,$sp $LCFI11: .cprestore 16 sw $4,88($fp) sw $0,24($fp) b $L8 nop $L9: lw $16,24($fp) lw $4,88($fp) lw $5,24($fp) lw $2,%got(_Z7compareii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) move $3,$2 sll $2,$16,2 addiu $4,$fp,24 addu $2,$4,$2 sw $3,4($2) lw $2,24($fp) nop addiu $2,$2,1 sw $2,24($fp) $L8: lw $2,24($fp) nop slt $2,$2,10 andi $2,$2,0x00ff bne $2,$0,$L9
  • 6. nop move $sp,$fp lw $31,84($sp) lw $fp,80($sp) lw $16,76($sp) addiu $sp,$sp,88 j $31 nop .set macro .set reorder .end _Z8setArrayi $LFE2: .size _Z8setArrayi, .-_Z8setArrayi .align 2 .globl main $LFB3 = . .set nomips16 .ent main .type main, @function main: .frame $fp,48,$31 # vars= 16, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-48 $LCFI12: sw $31,44($sp) $LCFI13: sw $fp,40($sp) movz $31,$31,$0 $LCFI14: move $fp,$sp $LCFI15:
  • 7. .cprestore 16 li $2,5 # 0x5 sw $2,32($fp) li $2,10 # 0xa sw $2,28($fp) li $2,8 # 0x8 sw $2,24($fp) li $4,5 # 0x5 lw $2,%got(_Z8setArrayi)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) lw $4,28($fp) lw $5,24($fp) lw $2,%got(_Z7compareii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) lw $4,28($fp) lw $5,24($fp) lw $2,%got(_Z3subii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,44($sp) lw $fp,40($sp) addiu $sp,$sp,48 j $31