Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a code written in Assembly Language for the following question: Even pari

ID: 1813384 • Letter: I

Question

          

        

I need a code written in Assembly Language for the following question:

     Even parity is where there is an even number of 1s in a string of data bits. Write a program to check the value loaded into Accumulator B and determine the state of the extra bit that would need to be added to the string in B in order to make all nine-bits have EVEN parity. Store that ninth (parity) bit as the MSB of Accumulator A and exit.

Example: If the value of B is 00111010, the number of ones in this pattern is four. This number is already even. Therefore, the extra bit is zero.

Example: If the value of B is 00101100, the number of ones in this pattern is three. This number is odd. Therefore, the extra bit is 1. The total number of ones, including the extra bit, becomes even.

  

Explanation / Answer

Here is a simple example for even parity.

1) Our input stream is 9 bits. Of these 9 bits, 8 bits(6 to 0) are for data and 9th bit(bit 8) is for the parity.

2) The parity bit (bit 8) is 0 if there are even number of 1's in the bit stream (bits 7 down to 0). In the example below bit 8, the parity bit is 0 since there are 4 1's in bits 7:0.

|--->Bit stream
8 7 6 5 4 3 2 1 0
0 0 1 1 1 1 0 0 0

---> parity bit

At the receiver here is an alogrithm you can use:

1) Count the number of 1's in the bits 6:0.
2) If even & bit 8 = 0 then everything is okay.
3) If odd & bit 8 = 1 then everything is okay.
4) If even & bit 8 = 1 then fail parity_check.
5) If odd & bit 8 = 0 then fail parity_check.


Here is one possible implementation in assembly:

mov eax, 0x78 ; this is our input bit stream that includes the
;parity bit.
mov ecx, 8 ; set up the count
xor ebx, ebx ; clear ebx register

count_ones_loop:
bt eax, ebx ; test bit 0 of eax
jnc not_a_one ; if bit 0 of eax = 1 then carry flag = 1
inc [my_counter] ; If bit 0 of eax = 1 then increment counter
not_a_one:
loop count_ones_loop ; ecx = ecx-1 if ecx!=0 then loop again

; when i get here the number of 1's is available in the
; my_counter variable in memory.
mov ebx, [my_counter] ; ebx = total number of 1's
bt ebx, 0 ; test bit0 of ebx to find if it is odd or even.
jc odd ; If odd jump to label 'odd'
jmp even ; If i get here it should be an even number

odd:
bt eax, 8 ; check if bit 8 = 0. If odd and bit 8 = 0 then fail
jnc fail_parity_check
jmp pass ; I passed the parity check.


even:
bt eax, 8 ; check if bit 8 = 1. If even and bit 8 = 1 then fail
jc fail_parity_check
jmp pass ; I passed the parity check.

pass:
<your passing code here>
<hlt>

fail_parity_check:
<message that parity check has failed>
<hlt>




Note: This code can be optimized for better performance.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote