Coa Lab 3 Shahzeb
Coa Lab 3 Shahzeb
ISLAMABAD
CSC371
COMPUTER ARCHITECTURE AND
ORGANIZATION
LAB REPORT =03
DATE: 25/09/2024
INTEGER ARITHMETIC
TASK 1:
• Write a program to ask the user to enter two integers A and B and then display the result of computing the
expression: A + 2B - 5.
CODE:
.data
.text
.globl main
main:
li $v0, 4
la $a0, promptA
syscall
li $v0, 5
syscall
li $v0, 4
la $a0, promptB
syscall
li $v0, 5
syscall
# Display result
li $v0, 4
la $a0, result_msg
syscall
li $v0, 1
syscall
# Exit
li $v0, 10
syscall
OUTPUT:
TASKE 2:
Assume that $s1 = 0x12345678 and $s2 = 0xffff9a00. Determine the content of registers $s3 to $s6 after
executing the following instructions: and $s3, $s1, $s2 # $s3 = or $s4, $s1, $s2 # $s4 = xor $s5, $s1, $s2 # $s5 =
nor $s6, $s1, $s2 # $s6 = Write a program to execute these instructions and verify the content of registers $s3 to
$s6.
CODE:
.data
.globl main
main:
# Initialize $s1
li $s1, 0x87654321
li $v0, 4
la $a0, result_msg1
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, result_msg2
syscall
li $v0, 1
syscall
li $v0
OUTPUT:
TASKE 3:
Assume that $s1 = 0x87654321. Determine the content of registers $s2 to $s4 after executing the following
instructions: sll $s2, $s1, 16 # $s2 = srl $s3, $s1, 8 # $s3 = sra $s4, $s1, 12 # $s4 =
CODE:
.data
.text
.globl main
main:
# Initialize $s1
li $s1, 0x87654321
li $v0, 4
la $a0, result_msg1
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, result_msg2
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
li $v0, 4
la $a0, result_msg3
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
# Exit
li $v0, 10
syscall
OUTPUT:
TASK 4:
Write a program that asks the user to enter an alphabetic character (either lower or upper case) and change the
case of the character from lower to upper and from upper to lower and display it.
CODE:
.data
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
syscall
# Check if uppercase
b display
lowercase:
# Check if lowercase
display:
li $v0, 4
la $a0, result_msg
syscall
syscall
li $v0, 4
la $a0, newline
syscall
end_case_change:
# Exit
li $v0, 10
syscall
OUTPUT:
TASK 5:
Write a program that asks the user to enter and integer number and read it. Then ask him to enter a bit position
(between 0 and 31) and display the value of that bit.
CODE:
.data
.text
.globl main
main:
li $v0, 4
la $a0, prompt_num
syscall
li $v0, 5
syscall
li $v0, 4
la $a0, prompt_bit
syscall
li $v0, 5
syscall
# Shift the number right by the bit position and check the LSB
li $v0, 4
la $a0, result_msg
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
OUTPUT:
TASK 6:
Write a program that asks the user to enter a signed number and read it. Then display the content of multiplying
this number by 24.
CODE:
.data
prompt: .asciiz "Enter a signed number: "
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $v0, 5
syscall
# Multiply by 24 (24 = 16 + 8)
# Display result
li $v0, 4
la $a0, result_msg
syscall
li $v0, 1
syscall
li $v0, 4
la $a0, newline
syscall
# Exit
li $v0, 10
syscall
OUTPUT:
CRITICAL ANALYSIS:
The six tasks demonstrate a range of MIPS assembly concepts, including arithmetic operations, bitwise
manipulation, shifting, character case conversion, bit extraction, and optimized multiplication. The programs
generally handle these tasks efficiently using basic instructions like `add`, `srlv`, and `andi`, and they showcase
how to work with system calls for input/output. However, some tasks use hardcoded values instead of user
input, limiting their flexibility (especially in Tasks 2 and 3). The lack of input validation and error handling is a
common weakness across the tasks, as the programs assume valid input without checking for mistakes or
special cases. Tasks like the bit extraction and multiplication are optimized well, but more comments and
clearer explanations would help make the code more beginner-friendly. Overall, the tasks are effective in
teaching key assembly operations, though they could be improved with better input validation, edge-case
handling, and more dynamic user interaction.