KEMBAR78
Milen Dimitrov HW2 Q1 | PDF | Integer (Computer Science) | Software Engineering
0% found this document useful (0 votes)
22 views7 pages

Milen Dimitrov HW2 Q1

Advanced Computer Architecture homework For Syracuse University Masters of Computer Engineering

Uploaded by

milenid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views7 pages

Milen Dimitrov HW2 Q1

Advanced Computer Architecture homework For Syracuse University Masters of Computer Engineering

Uploaded by

milenid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Homework 2, Q1

Computer Architecture CIS 655/CSE661

Instructor: Dr. Mo Abdallah

Autor name: Milen Dimitrov


Created on: 07/14/2021

Syracuse University, College of Engineering & Computer Science

Question 1: [20 points] Write a MIPS instructions -


based program
Submit one single pdf file for this question. Download the MARS software from
http://courses.missouristate.edu/KenVollmar/mars/ . Find any tutorials for MARS. Read and
study the manual/tutorials. Write a MIPS instructions - based program and run it in MARS to find
the min and max numbers in an array. In your submission, show your code and a screenshot of
the output.

Solution of Q1:
1.1 Code:
While it can be written more effectively, printing the array and finding the Min and Max
elements in a single loop, I purposely implemented separate loops, to better visualise the
dataflow. First reading 10 integers, using system calls to prompt for input and reading 32 bit
integers in the ReadLoop label. Index the array with t0, incrementing it by 4 bytes. Branche to
the EndRedLoop, when t0 becomes 40. Similar loop for printing the array.
To find min value I use t3, initialising it with the max positive int value 0x7fffffff, and for the max i
use t2, initializing it with min negative 0x80000000. If number that is currently tested is smaller
than the max number, its skipping the “move” instruction, and same for the min number.

.data
array: .word 0:40
pr1: .asciiz "input integer: "
msg1: .asciiz "Array: "
msg2: .asciiz "min element: "
msg3: .asciiz "max element: "
nl: .asciiz "\n"
.text
read:
la $t0, 0 #counter
ReadLoop:
beq $t0, 40, EndReadLoop #branch if equal to 40, 10 numbers
li $v0, 4 #Print string syscall
la $a0, pr1 #load string to prompt for int
syscall
li $v0, 5 # syscall to read int
syscall
sw $v0, array($t0) #store input in array
addi $t0, $t0, 4 #add by 4 to counter
b ReadLoop
EndReadLoop:
li $v0, 4 #Print array title string
la $a0, msg1
syscall
la $t0, 0
PrintLoop:
beq $t0,40,EndPrintLoop
lw $t1,array($t0)
li $v0,1
move $a0,$t1
syscall
li $a0, 44
li $v0, 11
syscall
addi $t0, $t0 , 4
b PrintLoop
EndPrintLoop:
la $t0, 0
la $t2, 0x80000000 # for max number, initialized with min negative
la $t3, 0x7fffffff # for min number, initialized with the mx positive
CompareLoop:
beq $t0,40,EndCompareLoop
lw $t1,array($t0)
blt $t1,$t2,higher # skip if element is lower than max
move $t2,$t1
higher:
bgt $t1,$t3,lower # skip if element is higher than max
move $t3,$t1
lower:
addi $t0, $t0 , 4
b CompareLoop
EndCompareLoop:
li $v0, 4 #Print NL
la $a0, nl
syscall
li $v0, 4 #Print string for min num
la $a0, msg2
syscall
li $v0,1
move $a0,$t3 #print min num
syscall
li $v0, 4 #Print NL
la $a0, nl
syscall
li $v0, 4 #Print string for max num
la $a0, msg3
syscall
li $v0,1
move $a0,$t2 #print max num
syscall
li $v0, 4 #Print NL
la $a0, nl
syscall
li $v0, 10 #end
syscall

1.2 Output results:


Typing 10 numbers on the console, array is printed, comma separated. The min and max
numbers are printed below. Negative numbers are processed correctly.

Go: execution completed successfully.


Assemble: assembling C:\Users\d_mil\OneDrive\Escritorio\ACA\HW2\mips_ar_min_max.asm
Assemble: operation completed successfully.
input integer: 23
input integer: 45
input integer: 65
input integer: 765
input integer: 45
input integer: 6
input integer: 343
input integer: 23
input integer: 34
input integer: 5
Array: 23,45,65,765,45,6,343,23,34,5,
min element: 5
max element: 765

-- program is finished running --

input integer: 23
input integer: 432
input integer: -34
input integer: -2
input integer: 4543
input integer: 654
input integer: -234532
input integer: 43
input integer: 23
input integer: 43
Array: 23,432,-34,-2,4543,654,-234532,43,23,43,
min element: -234532
max element: 4543

-- program is finished running --

You might also like