In: Computer Science
Part (a): Computing odd parity
Digital-communication hardware and software often include circuitry and code for
detecting errors in data transmission. The possible kinds of errors are large in
number, and their detection and correction is sometimes the topic of upper-level
Computer Science courses. In a nutshell, however, the concern is that bits sent by a
data transmitter are sometimes not the same bits that arrive at the data receiver.
That is, if the data transmitter sends this word:
0x00200020
but this is received instead:
0x00204020
then the data receiver has the wrong data, and would need some way to determine
that this was the case. In response to the error, the same receiver might discard the
word, or ask the sender to retransmit it, or take some other combination of steps.
A technique for detecting one-bit errors is to associate with each word a parity bit . If
an odd parity bit is transmitted along with the word, then the number of all set bits in
the word plus the value of the parity bit must sum to an odd number . In our example
above involving the data transmitter, the chosen parity bit would be 1 (i.e., two set
bits in 0x00200020 , plus one set parity bit, equals three set bits). The data receiver
has the corrupted byte as shown ( 0x00204020 ) plus the parity bit value, and
determines that the number of set bits is four(i.e., three bits in the word, plus the set
parity bit, resulting in four set bits, which is an even number). Given that four is not
an odd number, the receiver can conclude there was an error in transmission. Note
that the receiver can only detect an error with the parity bit; more is needed to
correct the error. (Also notice that if two bits were in error, then our scheme would
not detect this event.)
Your main task for part (a) is to complete the code in the file named parity.asm
that has been provided for you. You must also draw by hand the flowchart of your
solution and submit a scan or smartphone photo of the diagram as part of your
assignment submission; please ensure this is a JPEG or PDF named
“ parity_flowchart.jpg ” or “ parity_flowchart.pdf ” depending on the file
format you have chosen.
Some test cases are provided to you.
# Compute odd parity of word that must be in register $8 # Value of odd parity (0 or 1) must be in register $15 .text start: lw $8, testcase1 # STUDENTS MAY MODIFY THE TESTCASE GIVEN IN THIS LINE # STUDENTS MAY MODIFY CODE BELOW # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv nop addi $15, $0, -10 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # STUDENTS MAY MODIFY CODE ABOVE exit: add $2, $0, 10 syscall .data testcase1: .word 0x00200020 # odd parity is 1 testcase2: .word 0x00300020 # odd parity is 0 testcase3: .word 0x1234fedc # odd parity is 0
Greetings!!
Code:
.data
prompt: .asciiz "Enter a number for calculating odd parity"
out: .asciiz "Odd parity is: "
.text
#display prompt message
la $a0,prompt #loading the address
of the prompt message
li $v0,4 #parameter for displaying
prompt
syscall
#displaying
#read the upper limit
li $v0,5 #parameter for reading
number
syscall
#read
move $t0,$v0 #save the number into
t0
addi $t1,$t1,0 #initialize 0
addi $t7,$t7,0 #initialize 0
#processing..
loop:
beq $t1,32,end #repeat for 32
times
addi $t1,$t1,1 #increment loop
count
andi $t2,$t0,0x80000000 #logical and the msb of the
number with 0x80000000
beq $t2,$0,skip #check whether the
result of the and is 0 or 1
addi $t3,$t3,1 #if the result is
1,then increment the count for 1
skip:
sll $t0,$t0,1 #shift the number left
by 1 bit
j loop
#repeat
end:
andi $t4,$t3,0x00000001 #checking whether the number of
1s are even or odd
beq $t4,$0,jump #if the number is
even,skip the next line,parity is already set to 0
addi $t7,$t7,1 #if the number is
odd,load parity as 1
jump:
#display the out message
la $a0,out #loading the address of
the out message
li $v0,4 #parameter for displaying
out
syscall
#displaying
#display the count
add $a0,$0,$t7 #load the number of
1s count in register a0 for display
li $v0,1 #parameter for display the
integer result
syscall
#display
#standard termination
li $v0,10 #parameter for standard
termination
syscall
Program logic: Number of 1s are counted in the given number by shifting it left and then finally check whether the count is even or odd. If the count is even, print odd parity as 0 and otherwise 1.
Output screenshots:
Please note that the inputs are read in decimal format only.
Hope this helps