Professional Documents
Culture Documents
Muhammad Shoaib Talib CSA LAB 10
Muhammad Shoaib Talib CSA LAB 10
Assignment#03
Computer System Architecture
(PC) Muhammad Shoaib Talib (281018)
DE-40 CE” A”
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:
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:
branch on equal:
Now we have the instructions
Instructions Address
beq $t1,$t2,label 0040002c
j label2 00400030
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)
PC=PC+4+4=8
$t3=10=rt
OPCODE rs Rt Offset
4 9 10 2
0001 00 01 001 0 1010 0000 0000 0000 0010
Verification:
Jump:
We have the following MIPS CODE
j label2
label:
li $v0,4
la $a0,equal
syscall
j exit
label2:
li $v0,4
la $a0,notequal
syscall
exit:
jr $ra
0 0 4 0 0 0 4 4
We know that in the J type instruction we have 26-bit address field so omitting the least 2 and first 4
significants bits
OPCODE ADDRESS
J(2) 0x00400044
0000 10 00 0001 0000 0000 0000 0001 0001
Verification:
Task#02:
Data Path (Branch on equal):-
Now we have the following code
beq $t1,$t2,label
j label2
label: