0% found this document useful (0 votes)
15 views12 pages

Coa Lab 3 Shahzeb

The document is a lab report for a computer architecture course, detailing six tasks involving MIPS assembly programming. Each task includes code snippets for arithmetic operations, bitwise manipulation, character case conversion, bit extraction, and multiplication, along with critical analysis of the implementations. The analysis highlights strengths and weaknesses, particularly in terms of input validation and flexibility.

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)
15 views12 pages

Coa Lab 3 Shahzeb

The document is a lab report for a computer architecture course, detailing six tasks involving MIPS assembly programming. Each task includes code snippets for arithmetic operations, bitwise manipulation, character case conversion, bit extraction, and multiplication, along with critical analysis of the implementations. The analysis highlights strengths and weaknesses, particularly in terms of input validation and flexibility.

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/ 12

COMSATS UNIVERSITY

ISLAMABAD
CSC371
COMPUTER ARCHITECTURE AND
ORGANIZATION
LAB REPORT =03

NAME: SHAHZEB HUSSAIN


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

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

promptA: .asciiz "Enter integer A: "

promptB: .asciiz "Enter integer B: "

result_msg: .asciiz "Result of A + 2B - 5 is: "

.text

.globl main

main:

# Prompt and read A

li $v0, 4

la $a0, promptA

syscall

li $v0, 5

syscall

move $t0, $v0 # A = $t0

# Prompt and read B

li $v0, 4

la $a0, promptB

syscall

li $v0, 5

syscall

move $t1, $v0 # B = $t1


# Compute A + 2B - 5

add $t2, $t1, $t1 # t2 = 2B

add $t3, $t0, $t2 # t3 = A + 2B

addi $t3, $t3, -5 # t3 = A + 2B - 5

# Display result

li $v0, 4

la $a0, result_msg

syscall

move $a0, $t3

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

result_msg1: .asciiz "$s2 (sll): "

result_msg2: .asciiz "$s3 (srl): "

result_msg3: .asciiz "$s4 (sra): "

newline: .asciiz "\n"


.text

.globl main

main:

# Initialize $s1

li $s1, 0x87654321

# sll $s2, $s1, 16

sll $s2, $s1, 16

# srl $s3, $s1, 8

srl $s3, $s1, 8

# sra $s4, $s1, 12

sra $s4, $s1, 12

# Display $s2, $s3, $s4

li $v0, 4

la $a0, result_msg1

syscall

li $v0, 1

move $a0, $s2

syscall

li $v0, 4

la $a0, newline

syscall

li $v0, 4

la $a0, result_msg2

syscall

li $v0, 1

move $a0, $s3

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

result_msg1: .asciiz "$s2 (sll): "

result_msg2: .asciiz "$s3 (srl): "

result_msg3: .asciiz "$s4 (sra): "

newline: .asciiz "\n"

.text

.globl main

main:

# Initialize $s1

li $s1, 0x87654321

# sll $s2, $s1, 16

sll $s2, $s1, 16

# srl $s3, $s1, 8

srl $s3, $s1, 8


# sra $s4, $s1, 12

sra $s4, $s1, 12

# Display $s2, $s3, $s4

li $v0, 4

la $a0, result_msg1

syscall

li $v0, 1

move $a0, $s2

syscall

li $v0, 4

la $a0, newline

syscall

li $v0, 4

la $a0, result_msg2

syscall

li $v0, 1

move $a0, $s3

syscall

li $v0, 4

la $a0, newline

syscall

li $v0, 4

la $a0, result_msg3

syscall

li $v0, 1

move $a0, $s4

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

prompt: .asciiz "Enter an alphabetic character: "

result_msg: .asciiz "Changed case: "

newline: .asciiz "\n"

.text

.globl main

main:

# Prompt and read a character

li $v0, 4
la $a0, prompt

syscall

li $v0, 12 # syscall for reading character

syscall

move $t0, $v0 # char = $t0

# Check if uppercase

li $t1, 65 # ASCII 'A'

li $t2, 90 # ASCII 'Z'

blt $t0, $t1, lowercase

bgt $t0, $t2, lowercase

# Convert to lowercase (add 32)

addi $t0, $t0, 32

b display

lowercase:

# Check if lowercase

li $t1, 97 # ASCII 'a'

li $t2, 122 # ASCII 'z'

blt $t0, $t1, end_case_change

bgt $t0, $t2, end_case_change

# Convert to uppercase (subtract 32)

addi $t0, $t0, -32

display:

# Display changed case

li $v0, 4

la $a0, result_msg

syscall

li $v0, 11 # syscall for printing character

move $a0, $t0

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

prompt_num: .asciiz "Enter an integer number: "

prompt_bit: .asciiz "Enter a bit position (0-31): "

result_msg: .asciiz "The value of the bit is: "

newline: .asciiz "\n"

.text

.globl main

main:

# Prompt and read the integer

li $v0, 4

la $a0, prompt_num

syscall

li $v0, 5

syscall

move $t0, $v0 # number = $t0


# Prompt and read the bit position

li $v0, 4

la $a0, prompt_bit

syscall

li $v0, 5

syscall

move $t1, $v0 # bit position = $t1

# Shift the number right by the bit position and check the LSB

srl $t2, $t0, $t1

andi $t2, $t2, 1 # extract LSB

# Display the value of the bit

li $v0, 4

la $a0, result_msg

syscall

li $v0, 1

move $a0, $t2

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: "

result_msg: .asciiz "The result of multiplying by 24 is: "

newline: .asciiz "\n"

.text

.globl main

main:

# Prompt and read the signed number

li $v0, 4

la $a0, prompt

syscall

li $v0, 5

syscall

move $t0, $v0 # number = $t0

# Multiply by 24 (24 = 16 + 8)

sll $t1, $t0, 4 # t1 = t0 * 16

sll $t2, $t0, 3 # t2 = t0 * 8

add $t3, $t1, $t2 # t3 = t0 * 24

# Display result

li $v0, 4

la $a0, result_msg

syscall

move $a0, $t3

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.

You might also like