0% found this document useful (0 votes)
4 views11 pages

Coa Lab-1

The document contains a lab report for a computer architecture course, detailing three programming tasks using MIPS assembly language. Task 1 involves calculating the average marks of 10 students, Task 2 combines three single-digit numbers into a three-digit number, and Task 3 computes total marks from quizzes and assignments scaled to a total of 25. Each task includes code snippets and a critical analysis of the implementation.

Uploaded by

Shahzeb Hussain
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)
4 views11 pages

Coa Lab-1

The document contains a lab report for a computer architecture course, detailing three programming tasks using MIPS assembly language. Task 1 involves calculating the average marks of 10 students, Task 2 combines three single-digit numbers into a three-digit number, and Task 3 computes total marks from quizzes and assignments scaled to a total of 25. Each task includes code snippets and a critical analysis of the implementation.

Uploaded by

Shahzeb Hussain
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/ 11

COMSATS UNIVERSITY

ISLAMABAD
CSC371
COMPUTER ARCHITECTURE AND
ORGANIZATION
LAB REPORT =01

NAME: SHAHZEB HUSSAIN


REG NO: FA22-BCE-096
TEACHER: MR, DILSHAD SABIR

DATE: 25/09/2024
INTRODUCTION TO MIPS ASSEMBLY

TASK NO-01:
Write a program that takes marks of 10 students and then displays the average.

CODE:
.data # Data segment
marks: .word 0:10 # Reserve space for 10 integers (marks of students)
prompt: .asciiz "Enter marks: " # Prompt message
result_msg: .asciiz "Average marks: "
.text # Code segment
.globl main # Declare main as global entry point
main:
# Initialize variables
li $t0, 0 # $t0 = i (loop counter)
li $t1, 0 # $t1 = sum (for storing sum of marks)
input_loop:
# Check if we have taken input for 10 students
li $t2, 10 # $t2 = 10
beq $t0, $t2, calc_average # If $t0 == 10, go to average calculation
# Prompt user for input
li $v0, 4 # syscall to print string
la $a0, prompt # load address of prompt
syscall # make system call
# Read input (student's marks)
li $v0, 5 # syscall to read integer
syscall # make system call
move $t3, $v0 # store input in $t3
# Add input to sum
add $t1, $t1, $t3 # sum += marks
# Increment loop counter
addi $t0, $t0, 1 # i++
# Repeat loop
j input_loop
calc_average:
# Calculate average
li $t2, 10 # $t2 = 10 (number of students)
div $t1, $t2 # Divide sum by 10
mflo $t4 # Move quotient (average) to $t4
# Display result message
li $v0, 4 # syscall to print string
la $a0, result_msg # load address of result message
syscall # make system call
# Print average
li $v0, 1 # syscall to print integer
move $a0, $t4 # move average to $a0
syscall # make system call
# Exit the program
li $v0, 10 # syscall to exit
syscall
OUTPUT:

TASK NO-02:
Write a program that inputs three 1-digit numbers and combines them to form a 3 digit
number. For example input 4, 8 ,7, output=487.
CODE:
.data
prompt1: .asciiz "Enter first digit: " # Prompt for the first digit
prompt2: .asciiz "Enter second digit: " # Prompt for the second digit
prompt3: .asciiz "Enter third digit: " # Prompt for the third digit
result_msg: .asciiz "The combined number is: " # Result message
.text
.globl main
main:
# Step 1: Input first digit
li $v0, 4 # syscall to print string
la $a0, prompt1 # load address of prompt1
syscall # make system call
li $v0, 5 # syscall to read integer
syscall # get input for first digit
move $t0, $v0 # store first digit in $t0
# Step 2: Input second digit
li $v0, 4 # syscall to print string
la $a0, prompt2 # load address of prompt2
syscall # make system call
li $v0, 5 # syscall to read integer
syscall # get input for second digit
move $t1, $v0 # store second digit in $t1
# Step 3: Input third digit
li $v0, 4 # syscall to print string
la $a0, prompt3 # load address of prompt3
syscall # make system call
li $v0, 5 # syscall to read integer
syscall # get input for third digit
move $t2, $v0 # store third digit in $t
# Step 4: Combine the digits to form the three-digit number
li $t3, 100 # load 100 into $t3
mul $t0, $t0, $t3 # first digit * 100
li $t3, 10 # load 10 into $t3
mul $t1, $t1, $t3 # second digit * 10
add $t0, $t0, $t1 # add first and second digits
add $t0, $t0, $t2 # add third digit to form final number
# Step 5: Print result message
li $v0, 4 # syscall to print string
la $a0, result_msg # load address of result message
syscall # make system call
# Step 6: Print the combined number
li $v0, 1 # syscall to print integer
move $a0, $t0 # move the combined number to $a0
syscall # make system call
# Exit the program
li $v0, 10 # syscall to exit
syscall

OUTPUT:

TASK NO-03:
Write a program that inputs marks of four quizzes and four assignments, each out of 10,
and the calculates total marks out of 25. Total quiz marks 15/25 and Assignment marks
= 10/25

CODE:
.data
prompt_quiz1: .asciiz "Enter marks for Quiz 1 (out of 10): "
prompt_quiz2: .asciiz "Enter marks for Quiz 2 (out of 10): "
prompt_quiz3: .asciiz "Enter marks for Quiz 3 (out of 10): "
prompt_quiz4: .asciiz "Enter marks for Quiz 4 (out of 10): "
prompt_ass1: .asciiz "Enter marks for Assignment 1 (out of 10): "
prompt_ass2: .asciiz "Enter marks for Assignment 2 (out of 10): "
prompt_ass3: .asciiz "Enter marks for Assignment 3 (out of 10): "
prompt_ass4: .asciiz "Enter marks for Assignment 4 (out of 10): "
result_msg: .asciiz "Total marks out of 25: "

.text
.globl main

main:
# Input Quiz Marks
li $v0, 4 # syscall to print string
la $a0, prompt_quiz1 # load prompt for Quiz 1
syscall # display prompt
li $v0, 5 # syscall to read integer
syscall # read Quiz 1 marks
move $t0, $v0 # store in $t0 (Quiz 1 marks)

li $v0, 4
la $a0, prompt_quiz2 # load prompt for Quiz 2
syscall
li $v0, 5
syscall
move $t1, $v0 # store in $t1 (Quiz 2 marks)

li $v0, 4
la $a0, prompt_quiz3 # load prompt for Quiz 3
syscall
li $v0, 5
syscall
move $t2, $v0 # store in $t2 (Quiz 3 marks)

li $v0, 4
la $a0, prompt_quiz4 # load prompt for Quiz 4
syscall
li $v0, 5
syscall
move $t3, $v0 # store in $t3 (Quiz 4 marks)

# Input Assignment Marks


li $v0, 4
la $a0, prompt_ass1 # load prompt for Assignment 1
syscall
li $v0, 5
syscall
move $t4, $v0 # store in $t4 (Assignment 1 marks)

li $v0, 4
la $a0, prompt_ass2 # load prompt for Assignment 2
syscall
li $v0, 5
syscall
move $t5, $v0 # store in $t5 (Assignment 2 marks)

li $v0, 4
la $a0, prompt_ass3 # load prompt for Assignment 3
syscall
li $v0, 5
syscall
move $t6, $v0 # store in $t6 (Assignment 3 marks)

li $v0, 4
la $a0, prompt_ass4 # load prompt for Assignment 4
syscall
li $v0, 5
syscall
move $t7, $v0 # store in $t7 (Assignment 4 marks)

# Step 1: Calculate total quiz marks


add $t8, $t0, $t1 # $t8 = Quiz 1 + Quiz 2
add $t8, $t8, $t2 # $t8 += Quiz 3
add $t8, $t8, $t3 # $t8 += Quiz 4

# Scale quiz marks to 15/25


li $t9, 15 # Load 15 into $t9
li $a1, 40 # Load 40 (total quiz marks possible)
mul $t8, $t8, $t9 # multiply total quiz marks by 15
div $t8, $t8, $a1 # divide result by 40 to get scaled quiz marks

mflo $t8 # move the quotient (scaled quiz marks) to $t8

# Step 2: Calculate total assignment marks


add $t9, $t4, $t5 # $t9 = Assignment 1 + Assignment 2
add $t9, $t9, $t6 # $t9 += Assignment 3
add $t9, $t9, $t7 # $t9 += Assignment 4

# Scale assignment marks to 10/25


li $a1, 10 # Load 10 into $a1
li $a2, 40 # Load 40 (total assignment marks possible)
mul $t9, $t9, $a1 # multiply total assignment marks by 10
div $t9, $t9, $a2 # divide result by 40 to get scaled assignment marks

mflo $t9 # move the quotient (scaled assignment marks) to $t9

# Step 3: Calculate total marks out of 25


add $t0, $t8, $t9 # total_marks = scaled_quiz_marks +
scaled_assignment_marks

# Step 4: Display the total marks


li $v0, 4 # syscall to print string
la $a0, result_msg # load result message
syscall
li $v0, 1 # syscall to print integer
move $a0, $t0 # move total marks to $a0
syscall

# Exit the program


li $v0, 10 # syscall to exit
syscall

OUTPUT:

CRITICAL ANALYSIS
In Task 1, the code efficiently uses loops to gather marks from 10 students, sum them
up, and calculate the average. Core MIPS assembly instructions like `addi`, `li`, `beq`,
and `div` manage the arithmetic and loop control, with a clear condition to exit after 10
inputs. Task 2 demonstrates how to combine three 1-digit numbers into a 3-digit number
using multiplication and addition. It multiplies the first and second digits by powers of 10
to correctly position them in the hundreds and tens places. Task 3 calculates total quiz
and assignment marks out of 25, scaling them to 15/25 and 10/25, respectively. The final
result is displayed by combining these scaled marks, making the logic easy to follow .

You might also like