Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

NATIONAL UNIVERSITY OF SCIENCES


AND
TECHNOLOGY

Assignment#03
Computer System Architecture
(PC) Muhammad Shoaib Talib (281018)
DE-40 CE” A”

SHOAIB TALIB&ABDUL WALI 1


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

Lab 10
Lab Objectives:
The purpose of this lab is to make students able to better understand the control unit and
hardware components embeddded in the the lowest layer of computer system architecture
with special focus on J-type and branch on equal instructions.

Lab Tasks
Task:
Convert the following HLL code to assembly language code that contains a
branch-on-equal as well as a jump MIPS instruction. Attach your assembly code as
well
if(num1==num2)
{
cout<<”Both numbers are equal”;
}
else
{
cout<<”Numbers have different values”;
}

Code:
.data
equal:.asciiz"\nBoth Numbers are equal"
notequal:.asciiz"Numbers have different values"
test:.asciiz"This is for testing!\n"
.text
.globl main
main:

SHOAIB TALIB&ABDUL WALI 2


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

li $t1,14
li $t2,1
#if the numbers are equal than goto label
beq $t1,$t2,label
#if the numbers are not equal than goto label #02
j label2
#Display that Numbers are equal
label:
li $v0,4
la $a0,equal
syscall
#exit the Program
j exit
#Display that numbers are not equal
label2:
li $v0,4
la $a0,notequal
syscall

exit:
jr $ra

Task#01:
Convert the branch on equal and jump instructions into corresponding machine language instructions.
Verify all your machine codes from simulator; and attach screenshots of simulator instructions as well as
your results (Attach both your binary and hexadecimal results). Explain in detail how you arrived at the
machine coded instructions from upper levels of architecture. If required, you are free to make certain
assumptions however, clearly mention that assumption

Solution:

SHOAIB TALIB&ABDUL WALI 3


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

branch on equal:
Now we have the instructions

Instructions Address
beq $t1,$t2,label 0040002c

j label2 00400030

label:li $v0,4 00400034

Here we know that there is only one instruction between the beq and the label so the current program
counter will have the offset

PC=PC+4+(offset)

Here there is only one instruction so we have

PC=PC+4+4=8

Dividing the 8/4 (we have instruction at the distance of 4)=2

Or in other ways we have

Here the offset is

00400034 – 0040002c = 8/4=2


Here $t1=9=rs

$t3=10=rt

OPCODE rs Rt Offset
4 9 10 2
0001 00 01 001 0 1010 0000 0000 0000 0010

Now we have the pattern

0001 0001 0010 1010 0000 0000 0000 0010


1 1 2 a 0 0 0 2

SHOAIB TALIB&ABDUL WALI 4


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

Verification:

Jump:
We have the following MIPS CODE
j label2

#Display that Numbers are equal

label:

li $v0,4

la $a0,equal

syscall

j exit

label2:

li $v0,4

la $a0,notequal

syscall

exit:

jr $ra

SHOAIB TALIB&ABDUL WALI 5


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

Considering the instruction “j label2” it will jump to the label label 2

So we have the instruction format for the J-type instruction


[00400030] 08100011 j 0x00400044 [label2] ; 13: j label2

Here the address is 0X00400044

Converting to the binary we have

0 0 4 0 0 0 4 4

0000 0000 0100 0000 0000 0000 0100 0100

We know that in the J type instruction we have 26-bit address field so omitting the least 2 and first 4
significants bits

We have the address

0000 0100 0000 0000 0000 0100 01

OPCODE ADDRESS
J(2) 0x00400044
0000 10 00 0001 0000 0000 0000 0001 0001

0000 1000 0001 0000 0000 0000 0001 0001


0 8 1 0 0 0 1 1
So we have the Hexadecimal code for the j type instruction is 08100011

Verification:

SHOAIB TALIB&ABDUL WALI 6


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

Task#02:
Data Path (Branch on equal):-
Now we have the following code
beq $t1,$t2,label

j label2

label:

Here we have the one instruction after the label so we have


Effective address=PC=(PC+4) +(2*2*1)=8

SHOAIB TALIB&ABDUL WALI 7


COMPUTER SYSTEM ARCHITECTURE ASSIGNMENT#03

Data Path (J Type):-

SHOAIB TALIB&ABDUL WALI 8

You might also like