SlideShare a Scribd company logo
1 of 7
Download to read offline
Bubble Sort ({assembly language})
To complete the MIPS (assemble code) code, you essentially must translate the two nested for
loops and if statement above from Java to MIPS.
add your code to the area marked “PUT CODE HERE.”
Do not modify anything outside that area.
do not write anything to registers $s0 or $s5.
++++++++++++++ (MIPS Code _ Assemble language)+++++++++++++
.data
nums: .word 0 : 12 # "array" of 12 words to contain values
size: .word 12 # size of "array"
.text
la $s0, nums
la $s5, size # load address of size variable
lw $s5, 0($s5)
# Populate fibs with twelve values
addi $t1, $zero, 55
sw $t1, 0($s0)
addi $t1, $zero, 88
sw $t1, 4($s0)
addi $t1, $zero, 0
sw $t1, 8($s0)
addi $t1, $zero, 22
sw $t1, 12($s0)
addi $t1, $zero, 77
sw $t1, 16($s0)
addi $t1, $zero, 44
sw $t1, 20($s0)
addi $t1, $zero, 99
sw $t1, 24($s0)
addi $t1, $zero, 33
sw $t1, 28($s0)
addi $t1, $zero, 110
sw $t1, 32($s0)
addi $t1, $zero, 66
sw $t1, 36($s0)
addi $t1, $zero, 121
sw $t1, 40($s0)
addi $t1, $zero, 11
sw $t1, 44($s0)
##################################################################
# AT THIS POINT: $s0 is the address of the start of the array
# $s5 is the size (n)
#################################################################
# PUT CODE HERE
# Java (sample code)
#++++++++++(Bubble Sort _ for loop _ sample)
#// arr[i] will be in the correct spot after every iteration
#for (int i = n-1; i > 0; i--)
# for (int j = 0; j < i; j++) // Put arr[j] and arr[j+1] in order
# if (arr[j] > arr[j+1]) { // If they are out of order, swap them
# int tmp = arr[j];
# arr[j] = arr[j+1];
# arr[j+1] = tmp;
# }
#+++++++++++(Bubble Sort _ while loop _ sample)
#int i = n-1;
# while (i > 0) {
# int j = 0;
# while(j < i){
# if (arr[j] > arr[j+1]) { // If they are out of order, swap them
# int tmp = arr[j];
# arr[j] = arr[j+1];
# arr[j+1] = tmp;
# }
# j++
# }
# i--;
#}
##################################################################
la $a0, nums # first argument for print (array)
add $a1, $s5, $zero # second argument for print (size)
jal print # call print routine.
li $v0, 10 # system call for exit
syscall # we are out of here.
######### routine to print the numbers on one line.
######### don't touch anything below this line!!!!
.data
space:.asciiz " " # space to insert between numbers
head: .asciiz "Sorted array: "
.text
print:add $s0, $zero, $a0 # starting address of array
add $t1, $zero, $a1 # initialize loop counter to array size
la $a0, head # load address of print heading
li $v0, 4 # specify Print String service
syscall # print heading
out: lw $a0, 0($s0) # load fibonacci number for syscall
li $v0, 1 # specify Print Integer service
syscall # print fibonacci number
la $a0, space # load address of spacer for syscall
li $v0, 4 # specify Print String service
syscall # output string
addi $s0, $s0, 4 # increment address
addi $t1, $t1, -1 # decrement loop counter
bgtz $t1, out # repeat if not finished
jr $ra # return
Solution
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'The contents of the array before sorting : $'
PROMPT_2 DB 0DH,0AH,'The contents of the array after sorting : $'
ARRAY DB 5,3,9,0,2,6,1,7,8,4
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
MOV BX, 10 ; set BX=10
LEA DX, PROMPT_1 ; load and display the string PROMPT_1
MOV AH, 9
INT 21H
LEA SI, ARRAY ; set SI=offset address of ARRAY
CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY
LEA SI, ARRAY ; set SI=offset address of the ARRAY
CALL BUBBLE_SORT ; call the procedure BUBBLE_SORT
LEA DX, PROMPT_2 ; load and display the string PROMPT_2
MOV AH, 9
INT 21H
LEA SI, ARRAY ; set SI=offset address of ARRAY
CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
;**************************************************************************;
;**************************************************************************;
;------------------------- Procedure Definitions ------------------------;
;**************************************************************************;
;**************************************************************************;
;**************************************************************************;
;----------------------------- PRINT_ARRAY ------------------------------;
;**************************************************************************;
PRINT_ARRAY PROC
; this procedure will print the elements of a given array
; input : SI=offset address of the array
; : BX=size of the array
; output : none
PUSH AX ; push AX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
MOV CX, BX ; set CX=BX
@PRINT_ARRAY: ; loop label
XOR AH, AH ; clear AH
MOV AL, [SI] ; set AL=[SI]
CALL OUTDEC ; call the procedure OUTDEC
MOV AH, 2 ; set output function
MOV DL, 20H ; set DL=20H
INT 21H ; print a character
INC SI ; set SI=SI+1
LOOP @PRINT_ARRAY ; jump to label @PRINT_ARRAY while CX!=0
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP AX ; pop a value from STACK into AX
RET ; return control to the calling procedure
PRINT_ARRAY ENDP
;**************************************************************************;
;---------------------------- BUBBLE_SORT -------------------------------;
;**************************************************************************;
BUBBLE_SORT PROC
; this procedure will sort the array in ascending order
; input : SI=offset address of the array
; : BX=array size
; output : none
PUSH AX ; push AX onto the STACK
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
PUSH DI ; push DI onto the STACK
MOV AX, SI ; set AX=SI
MOV CX, BX ; set CX=BX
DEC CX ; set CX=CX-1
@OUTER_LOOP: ; loop label
MOV BX, CX ; set BX=CX
MOV SI, AX ; set SI=AX
MOV DI, AX ; set DI=AX
INC DI ; set DI=DI+1
@INNER_LOOP: ; loop label
MOV DL, [SI] ; set DL=[SI]
CMP DL, [DI] ; compare DL with [DI]
JNG @SKIP_EXCHANGE ; jump to label @SKIP_EXCHANGE if DL<[DI]
XCHG DL, [DI] ; set DL=[DI], [DI]=DL
MOV [SI], DL ; set [SI]=DL
@SKIP_EXCHANGE: ; jump label
INC SI ; set SI=SI+1
INC DI ; set DI=DI+1
DEC BX ; set BX=BX-1
JNZ @INNER_LOOP ; jump to label @INNER_LOOP if BX!=0
LOOP @OUTER_LOOP ; jump to label @OUTER_LOOP while CX!=0
POP DI ; pop a value from STACK into DI
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX
POP AX ; pop a value from STACK into AX
RET ; return control to the calling procedure
BUBBLE_SORT ENDP
;**************************************************************************;
;-------------------------------- OUTDEC --------------------------------;
;**************************************************************************;
OUTDEC PROC
; this procedure will display a decimal number
; input : AX
; output : none
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
XOR CX, CX ; clear CX
MOV BX, 10 ; set BX=10
@OUTPUT: ; loop label
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC CX ; increment CX
OR AX, AX ; take OR of Ax with AX
JNE @OUTPUT ; jump to label @OUTPUT if ZF=0
MOV AH, 2 ; set output function
@DISPLAY: ; loop label
POP DX ; pop a value from STACK to DX
OR DL, 30H ; convert decimal to ascii code
INT 21H ; print a character
LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0
POP DX ; pop a value from STACK into DX
POP CX ; pop a value from STACK into CX
POP BX ; pop a value from STACK into BX
RET ; return control to the calling procedure
OUTDEC ENDP
END MAIN

More Related Content

Similar to Bubble Sort ({assembly language})To complete the MIPS (assemble co.pdf

Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfFOREVERPRODUCTCHD
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++prashant_sainii
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfadnankhan605720
 
Assembly language
Assembly languageAssembly language
Assembly languagebryle12
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly LanguageMotaz Saad
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAPsapdocs. info
 

Similar to Bubble Sort ({assembly language})To complete the MIPS (assemble co.pdf (20)

Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
 
Les03
Les03Les03
Les03
 
Regexp Master
Regexp MasterRegexp Master
Regexp Master
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
Unit 4
Unit 4Unit 4
Unit 4
 
runtimestack
runtimestackruntimestack
runtimestack
 
you need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdfyou need to complete the r code and a singlepage document c.pdf
you need to complete the r code and a singlepage document c.pdf
 
Assembly language
Assembly languageAssembly language
Assembly language
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
4sem dbms(1)
4sem dbms(1)4sem dbms(1)
4sem dbms(1)
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Taller Ensambladores
Taller EnsambladoresTaller Ensambladores
Taller Ensambladores
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
Introduction to Assembly Language
Introduction to Assembly LanguageIntroduction to Assembly Language
Introduction to Assembly Language
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
List Processing in ABAP
List Processing in ABAPList Processing in ABAP
List Processing in ABAP
 
CARACTERES ASCII ENSAMBLADOR
CARACTERES ASCII ENSAMBLADORCARACTERES ASCII ENSAMBLADOR
CARACTERES ASCII ENSAMBLADOR
 

More from kourystephaniamari30

I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfkourystephaniamari30
 
How would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdfHow would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdfkourystephaniamari30
 
Explain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdfExplain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdfkourystephaniamari30
 
Ethidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdfEthidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdfkourystephaniamari30
 
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdfBMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdfkourystephaniamari30
 
Describe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdfDescribe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdfkourystephaniamari30
 
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdfCollected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdfkourystephaniamari30
 
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdfBased on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdfkourystephaniamari30
 
About 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdfAbout 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdfkourystephaniamari30
 
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdfAssume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdfkourystephaniamari30
 
An example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdfAn example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdfkourystephaniamari30
 
A group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdfA group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdfkourystephaniamari30
 
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdfkourystephaniamari30
 
6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdf6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdfkourystephaniamari30
 
You can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdfYou can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdfkourystephaniamari30
 
why do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdfwhy do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdfkourystephaniamari30
 
When a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdfWhen a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdfkourystephaniamari30
 
Using an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdfUsing an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdfkourystephaniamari30
 
What are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdfWhat are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdfkourystephaniamari30
 
What are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdfWhat are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdfkourystephaniamari30
 

More from kourystephaniamari30 (20)

I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdf
 
How would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdfHow would you design an experiment to test whether M-CSF growth fact.pdf
How would you design an experiment to test whether M-CSF growth fact.pdf
 
Explain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdfExplain what is meant by a positive relationship between two variabl.pdf
Explain what is meant by a positive relationship between two variabl.pdf
 
Ethidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdfEthidium homodimer is responsible for the red color observed. How is.pdf
Ethidium homodimer is responsible for the red color observed. How is.pdf
 
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdfBMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
BMP signaling can be fine-tuned at the level of Smad158 linker phos.pdf
 
Describe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdfDescribe the specific brain region(s) associated with language, spee.pdf
Describe the specific brain region(s) associated with language, spee.pdf
 
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdfCollected from flower of mountain laurel (Kalmia latifolia) plant.  T.pdf
Collected from flower of mountain laurel (Kalmia latifolia) plant. T.pdf
 
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdfBased on the number of Barr bodies seen in the somatic cells of the f.pdf
Based on the number of Barr bodies seen in the somatic cells of the f.pdf
 
About 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdfAbout 13 of the population is nervous around strangers. If two peop.pdf
About 13 of the population is nervous around strangers. If two peop.pdf
 
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdfAssume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
Assume that a cross is made between tall and dwarf Alsatian red-ribb.pdf
 
An example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdfAn example would be height in humans Traits have a wide range of valu.pdf
An example would be height in humans Traits have a wide range of valu.pdf
 
A group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdfA group of BIOL 1114 students were able to measure various metabolic.pdf
A group of BIOL 1114 students were able to measure various metabolic.pdf
 
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf2) By the mid-1950s, there was an increases study inFixed asset m.pdf
2) By the mid-1950s, there was an increases study inFixed asset m.pdf
 
6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdf6. Which of the following has the lowest orbit a. weather satel.pdf
6. Which of the following has the lowest orbit a. weather satel.pdf
 
You can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdfYou can fill the cell background with color or an image A.color b.pdf
You can fill the cell background with color or an image A.color b.pdf
 
why do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdfwhy do people eating outside rather than home cook SolutionFi.pdf
why do people eating outside rather than home cook SolutionFi.pdf
 
When a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdfWhen a judge sends an innocent person to jail he is making aa. Ty.pdf
When a judge sends an innocent person to jail he is making aa. Ty.pdf
 
Using an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdfUsing an inoculating loop, demonstrate how to aseptically remove some.pdf
Using an inoculating loop, demonstrate how to aseptically remove some.pdf
 
What are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdfWhat are the common DSS analysis techniquesSolutionDSS analys.pdf
What are the common DSS analysis techniquesSolutionDSS analys.pdf
 
What are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdfWhat are the vulnerabilities in the boot process What can an attack.pdf
What are the vulnerabilities in the boot process What can an attack.pdf
 

Recently uploaded

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 

Recently uploaded (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

Bubble Sort ({assembly language})To complete the MIPS (assemble co.pdf

  • 1. Bubble Sort ({assembly language}) To complete the MIPS (assemble code) code, you essentially must translate the two nested for loops and if statement above from Java to MIPS. add your code to the area marked “PUT CODE HERE.” Do not modify anything outside that area. do not write anything to registers $s0 or $s5. ++++++++++++++ (MIPS Code _ Assemble language)+++++++++++++ .data nums: .word 0 : 12 # "array" of 12 words to contain values size: .word 12 # size of "array" .text la $s0, nums la $s5, size # load address of size variable lw $s5, 0($s5) # Populate fibs with twelve values addi $t1, $zero, 55 sw $t1, 0($s0) addi $t1, $zero, 88 sw $t1, 4($s0) addi $t1, $zero, 0 sw $t1, 8($s0) addi $t1, $zero, 22 sw $t1, 12($s0) addi $t1, $zero, 77 sw $t1, 16($s0) addi $t1, $zero, 44 sw $t1, 20($s0) addi $t1, $zero, 99 sw $t1, 24($s0) addi $t1, $zero, 33 sw $t1, 28($s0) addi $t1, $zero, 110 sw $t1, 32($s0) addi $t1, $zero, 66 sw $t1, 36($s0)
  • 2. addi $t1, $zero, 121 sw $t1, 40($s0) addi $t1, $zero, 11 sw $t1, 44($s0) ################################################################## # AT THIS POINT: $s0 is the address of the start of the array # $s5 is the size (n) ################################################################# # PUT CODE HERE # Java (sample code) #++++++++++(Bubble Sort _ for loop _ sample) #// arr[i] will be in the correct spot after every iteration #for (int i = n-1; i > 0; i--) # for (int j = 0; j < i; j++) // Put arr[j] and arr[j+1] in order # if (arr[j] > arr[j+1]) { // If they are out of order, swap them # int tmp = arr[j]; # arr[j] = arr[j+1]; # arr[j+1] = tmp; # } #+++++++++++(Bubble Sort _ while loop _ sample) #int i = n-1; # while (i > 0) { # int j = 0; # while(j < i){ # if (arr[j] > arr[j+1]) { // If they are out of order, swap them # int tmp = arr[j]; # arr[j] = arr[j+1]; # arr[j+1] = tmp; # } # j++ # } # i--; #}
  • 3. ################################################################## la $a0, nums # first argument for print (array) add $a1, $s5, $zero # second argument for print (size) jal print # call print routine. li $v0, 10 # system call for exit syscall # we are out of here. ######### routine to print the numbers on one line. ######### don't touch anything below this line!!!! .data space:.asciiz " " # space to insert between numbers head: .asciiz "Sorted array: " .text print:add $s0, $zero, $a0 # starting address of array add $t1, $zero, $a1 # initialize loop counter to array size la $a0, head # load address of print heading li $v0, 4 # specify Print String service syscall # print heading out: lw $a0, 0($s0) # load fibonacci number for syscall li $v0, 1 # specify Print Integer service syscall # print fibonacci number la $a0, space # load address of spacer for syscall li $v0, 4 # specify Print String service syscall # output string addi $s0, $s0, 4 # increment address addi $t1, $t1, -1 # decrement loop counter bgtz $t1, out # repeat if not finished jr $ra # return Solution .MODEL SMALL .STACK 100H .DATA PROMPT_1 DB 'The contents of the array before sorting : $' PROMPT_2 DB 0DH,0AH,'The contents of the array after sorting : $' ARRAY DB 5,3,9,0,2,6,1,7,8,4
  • 4. .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX MOV BX, 10 ; set BX=10 LEA DX, PROMPT_1 ; load and display the string PROMPT_1 MOV AH, 9 INT 21H LEA SI, ARRAY ; set SI=offset address of ARRAY CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY LEA SI, ARRAY ; set SI=offset address of the ARRAY CALL BUBBLE_SORT ; call the procedure BUBBLE_SORT LEA DX, PROMPT_2 ; load and display the string PROMPT_2 MOV AH, 9 INT 21H LEA SI, ARRAY ; set SI=offset address of ARRAY CALL PRINT_ARRAY ; call the procedure PRINT_ARRAY MOV AH, 4CH ; return control to DOS INT 21H MAIN ENDP ;**************************************************************************; ;**************************************************************************; ;------------------------- Procedure Definitions ------------------------; ;**************************************************************************; ;**************************************************************************; ;**************************************************************************; ;----------------------------- PRINT_ARRAY ------------------------------; ;**************************************************************************; PRINT_ARRAY PROC ; this procedure will print the elements of a given array ; input : SI=offset address of the array ; : BX=size of the array ; output : none PUSH AX ; push AX onto the STACK PUSH CX ; push CX onto the STACK
  • 5. PUSH DX ; push DX onto the STACK MOV CX, BX ; set CX=BX @PRINT_ARRAY: ; loop label XOR AH, AH ; clear AH MOV AL, [SI] ; set AL=[SI] CALL OUTDEC ; call the procedure OUTDEC MOV AH, 2 ; set output function MOV DL, 20H ; set DL=20H INT 21H ; print a character INC SI ; set SI=SI+1 LOOP @PRINT_ARRAY ; jump to label @PRINT_ARRAY while CX!=0 POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP AX ; pop a value from STACK into AX RET ; return control to the calling procedure PRINT_ARRAY ENDP ;**************************************************************************; ;---------------------------- BUBBLE_SORT -------------------------------; ;**************************************************************************; BUBBLE_SORT PROC ; this procedure will sort the array in ascending order ; input : SI=offset address of the array ; : BX=array size ; output : none PUSH AX ; push AX onto the STACK PUSH BX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK PUSH DI ; push DI onto the STACK MOV AX, SI ; set AX=SI MOV CX, BX ; set CX=BX DEC CX ; set CX=CX-1 @OUTER_LOOP: ; loop label MOV BX, CX ; set BX=CX MOV SI, AX ; set SI=AX MOV DI, AX ; set DI=AX
  • 6. INC DI ; set DI=DI+1 @INNER_LOOP: ; loop label MOV DL, [SI] ; set DL=[SI] CMP DL, [DI] ; compare DL with [DI] JNG @SKIP_EXCHANGE ; jump to label @SKIP_EXCHANGE if DL<[DI] XCHG DL, [DI] ; set DL=[DI], [DI]=DL MOV [SI], DL ; set [SI]=DL @SKIP_EXCHANGE: ; jump label INC SI ; set SI=SI+1 INC DI ; set DI=DI+1 DEC BX ; set BX=BX-1 JNZ @INNER_LOOP ; jump to label @INNER_LOOP if BX!=0 LOOP @OUTER_LOOP ; jump to label @OUTER_LOOP while CX!=0 POP DI ; pop a value from STACK into DI POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP BX ; pop a value from STACK into BX POP AX ; pop a value from STACK into AX RET ; return control to the calling procedure BUBBLE_SORT ENDP ;**************************************************************************; ;-------------------------------- OUTDEC --------------------------------; ;**************************************************************************; OUTDEC PROC ; this procedure will display a decimal number ; input : AX ; output : none PUSH BX ; push BX onto the STACK PUSH CX ; push CX onto the STACK PUSH DX ; push DX onto the STACK XOR CX, CX ; clear CX MOV BX, 10 ; set BX=10 @OUTPUT: ; loop label XOR DX, DX ; clear DX DIV BX ; divide AX by BX PUSH DX ; push DX onto the STACK
  • 7. INC CX ; increment CX OR AX, AX ; take OR of Ax with AX JNE @OUTPUT ; jump to label @OUTPUT if ZF=0 MOV AH, 2 ; set output function @DISPLAY: ; loop label POP DX ; pop a value from STACK to DX OR DL, 30H ; convert decimal to ascii code INT 21H ; print a character LOOP @DISPLAY ; jump to label @DISPLAY if CX!=0 POP DX ; pop a value from STACK into DX POP CX ; pop a value from STACK into CX POP BX ; pop a value from STACK into BX RET ; return control to the calling procedure OUTDEC ENDP END MAIN