Multitasking and Context Switching; Pipelining 2. Pipeline Task Assume a 5-stage
ID: 3902932 • Letter: M
Question
Multitasking and Context Switching; Pipelining 2. Pipeline Task Assume a 5-stage pipelined processor using the standard 5-stages (IF, ID, EX, MEM, WB) that uses no forwarding or stalling circuitry. Rather, you will use the compiler to add no-ops to the code to ensure correct execution. Note: You can assume that if the processor reads and writes to the same register in a given cycle, the value read out will be the new value that is written in that cycle Write your own short program that re-writes the code below including the no-ops that are needed to protect against hazard conditions add $3, $2, $3 lw $4, 100($3) sub $7, $6, $2 xor $6, $4, $3 The first thing your program needs to do is to print out your family (last name) and your student ID. Create strings and use the print_string syscall to display this information to the MARS Run 1/0 window. Include as few no-ops as possible. Do not change the order of the code statements. To receive full credit, be sure to document the hazard condition in your code comments Deliverables:Explanation / Answer
Screenshot
-------------------------------------------------------------
Code:-
#This is a simple program to check the address calculation
#to avoid data hazards between registers using "nop" instruction
#nop instruction generate delay to the execution of instructions
#but not harmful
#Variable declaration section
.data
#Write your lastname variable
lastName: .asciiz "LastName"
#Write your student ID
sId: .asciiz " YourId"
#an array of 100 size , word boundary means 4 byte
arr: .word 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#Main Program
.text
#Display your last name
la $a0,lastName
li $v0,4
syscall
#Display your Id
la $a0,sId
li $v0,4
syscall
#add value of register 2 and 6 with 0
li $2,0
li $6,0
#load address of the array in $3 register
la $3,arr
# $3 using next instruction , so avoiding data hazard put NOP
nop
nop
nop
#add starting address of array with 0 and store again in $3
add $3,$2,$3
#$4 getting value of $3 address(Base address)+offset contains element, so here also data hazard happening
nop
nop
nop
#load value of 100th offset space , $4=26
lw $4,100($3)
#$7=0-0=0
sub $7,$6,$2
#again $6 using next instruction for storing , so avoid data hazard nop instruction using
nop
nop
nop
#xoring 26 with base address of array and store the result in $6(Means another address)
xor $6,$4,$3
#End of the program
li $v0,10
syscall
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.