0% found this document useful (0 votes)
24 views9 pages

Lab Report3

The document is a lab report for a Computer Organization and Architecture course. It contains 4 tasks that involve taking user input, performing bitwise operations on numbers, and checking if a number is even or odd. The tasks include: 1) Building a basic calculator, 2) Checking the value of a specific bit position in a number, 3) Toggling the value of that bit, and 4) Checking if a user-input number is even or odd. MIPS assembly code is provided for each task.

Uploaded by

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

Lab Report3

The document is a lab report for a Computer Organization and Architecture course. It contains 4 tasks that involve taking user input, performing bitwise operations on numbers, and checking if a number is even or odd. The tasks include: 1) Building a basic calculator, 2) Checking the value of a specific bit position in a number, 3) Toggling the value of that bit, and 4) Checking if a user-input number is even or odd. MIPS assembly code is provided for each task.

Uploaded by

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

BRANCHING OPERATION:

LAB # 03

Fall 2023

CSE304L Computer Organization & Architecture

Submitted by: Muhammad Farhan Shah

Registration No: 21PWCSE2031

Class Section: C

Student Signature: _______FarhanShah_______

Submitted to:

Dr.Bilal Habib

10,19, 2023

Department of Computer Systems Engineering

University of Engineering and Technology, Peshawar


ASSESSMENT RUBRICS COA LABS

LAB REPORT ASSESSMENT

Marks
Criteria Excellent Average Nill Obtained
1. Objectives of Lab All objectives of Objectives of Objectives of lab
lab are properly lab are partially are not
covered [Marks covered shown
10] [Marks 0]
[Marks 5]

2. MIPS All the instructions Some The


instructions with are well written with instructions are instructions are
Comments and comments missing are not properly
proper indentations. explaining the code poorly written [Marks
and properly commented 0]
indented [Marks code [Marks
20] 10]

3. Simulation run The code is The code is The code is written


without error and running in the running but with but not running due
warnings simulator without some warnings or to errors
any error and errors. [Marks 0]
warnings [Marks
10] [Marks 5]

4. Procedure All the instructions are Some steps are steps are totally
written with proper missing [Marks missing [Marks
procedure 10] 0]
[Marks 20]

5. OUTPUT Proper output of the Some of the No or wrong


code written in outputs are output [Marks
assembly [Marks missing [Marks 0]
20] 10]

6. Conclusion Conclusion about Conclusion about Conclusion about


the lab is shown the lab is partially the lab is not
and written [Marks shown shown[Marks0]
20]
[Marks 10]
7. Cheating [Any kind of Marks
0]
cheating will lead
to 0 Marks

Total Marks Obtained:__________


Instructor Signature: ______________________

Document Tasks:

Task No : 1 : Take the 1st number from user.


Then take a number to do the operation. (1 corresponds to addition, 2 corresponds to
subtraction,

3 for multiplication and 4 for division).

Then finally take a 2nd number from a user.

CODE:
.text #first no taken from the user and saved to $t0

.globl main li $v0,4

main: la $a0,msg3

li $v0,4 syscall

la $a0,msg1 li $v0,4

syscall la $a0,newline

li $v0,4 syscall

la $a0,newline li $v0,5

syscall syscall

li $v0,5 move $t1,$v0

syscall #2nd no taken from the user to $t2

move $t0,$v0
li $v0,4 li $v0,1

la $a0,msg2 move $a0,$t3

syscall syscall

li $v0,4 j end

la $a0,newline

syscall multiplication:

li $v0,5 mul $t3,$t0,$t1

syscall li $v0,4

move $t2,$v0 la $a0,msg6

# check the condition for the calculator syscall

beq $t2 , 1 , addition li $v0,1

beq $t2 , 2 , subtraction move $a0,$t3

beq $t2 , 3 , multiplication syscall

beq $t2 , 4 , division j end

#operation is taken from the user

division:

addition: div $t3,$t0,$t1

add $t3,$t0,$t1 li $v0,4

li $v0,4 la $a0,msg7

la $a0,msg4 syscall

syscall li $v0,1

li $v0,1 move $a0,$t3

move $a0,$t3 syscall

syscall j end

j end

end:

subtraction: li $v0 , 10

sub $t3,$t0,$t1 syscall

li $v0,4

la $a0,msg5 .data

syscall
msg1: .asciiz "Enter the first no : " msg4: .asciiz "The Sum is : "

msg2: .asciiz "Enter the operation: " msg5: .asciiz "The Difference is : "

msg3: .asciiz "Enter the Second no : " msg6: .asciiz "The product is : "

newline: .asciiz "\n " msg7: .asciiz "The division is : "

OUTPUT:

Task NO : 2 : Write a program that’s show the bit position of a number is 0 or 1. (Hint if
number is 5

it is represented by 0101 show the 4th bit position is 0, similarly if the user enters 9 then the

binary equivalent is 1001. In this case the 4th bit position is 1).

CODE
.text la $a0,msg1

.globl main syscall

main: li $v0,4

li $v0,4 la $a0,newline
syscall li $v0 , 4

li $v0,5 la $a0 , msg2

syscall syscall

move $t0,$v0 j end

#first no taken from the user and saved to $t0

and $t1, $t0 , 8 end:

beq $t1, 8, one li $v0 , 10

syscall

li $v0, 4

la $a0 , msg3 .data

syscall msg1: .asciiz "Enter the no : "

j end msg2: .asciiz "the fourth bit is one "

msg3: .asciiz "the Fourth bit is zero "

one: newline: .asciiz "\n "

OUTPUT:

Task No 3: Now toggle the bit find in the previous task if the bit is 1 set it to 0 if it is 0 then
set it to

1.

CODE:
.text .globl main
main: la $a0,msg2

li $v0,4 syscall

la $a0,msg1

syscall li $v0 , 1

li $v0,4 move $a0 , $t1

la $a0,newline syscall

syscall

li $v0,5 li $v0 , 10

syscall syscall

move $t0,$v0

#no taken from the user and saved to $t0 .data

msg1: .asciiz "Enter the no : "

xor $t1, $t0 , 8 msg2: .asciiz "After toggling the no is "

newline: .asciiz "\n "

li $v0,4

OUTPUT:

Task No 4: Write a program to check a number entered by user is even or odd.

CODE:
.text main:

.globl main li $v0, 4

la $a0, msg1
syscall j end

#check if no is odd

li $v0, 5 odd:

syscall li $v0, 4

move $t0, $v0 la $a0, msg3

#take no as input from user syscall

li $t1, 2 #check if no is even

div $t0, $t1 end:

mfhi $t1 li $v0, 10

syscall

bnez $t1, odd

.data

li $v0, 4 msg1: .asciiz "Enter the no : "

la $a0, msg2 msg2: .asciiz "the no is even "

syscall msg3: .asciiz "the no is odd "

OUTPUT:

Task No 5:
Show that shifting left of an even number by 1 position is a multiplication by 2 and

shifting right of an even number by 1 position is a division by 2. (Hint: Use sll and srl).

CODE:
.text syscall

.globl main #shift right

srl $t2, $t0, 1

main: li $v0, 4

li $v0, 4 la $a0, msg3

la $a0, msg1 syscall

syscall move $a0, $t2

li $v0, 5 li $v0, 1

syscall syscall

move $t0, $v0 j end

#shift left

sll $t1, $t0, 1 end:

li $v0, 10

li $v0, 4 syscall

la $a0, msg2

syscall .data

msg1: .asciiz "Enter an even number: "

move $a0, $t1 msg2: .asciiz "Multiplying by 2 using sll: \n"

li $v0, 1 msg3: .asciiz "Dividing by 2 using srl: \n"

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy