1b. Parity checking and displaying 'FF' or '00' for Odd/Even parity

vtu mp 1b
Q) Read the status of eight input bits from the Logic Controller Interface and display ‘FF’ if the parity of the input read is even; otherwise display 00

This program will read an 8 bit number from the logic controller and display ‘FF’ if that number is of even parity. Otherwise displays ‘00’ on logic controller. Also displays the number of ‘1’s present in the input number.

Algorithm:

Step 1: Initialize the control word i.e., 82H of logic controller.
Step 2: Store the control word in the Control register and initialize the Port B address.
Step 3: Read the 8-bit status into AL from the input Port-B of logic controller.
Step 4: Next step is to determine the number of 1’s in AL register value.
Step 5: To check whether AL register contains even or odd number.
Step 6: If AL contains even number, it is even parity and display FF.
Step 7: If AL contains odd number, it is odd parity and display 00.
Step 8: Finally display the number of 1’s that is the value of AL.
Step 9: Stop.

CODE:


Explanation:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
        CR EQU 0E803H
        PA EQU 0E800H
        PB EQU 0E801H

DATA ENDS

Programming model selected contains one data segment(DS) and one code segment (CS).
Our data segment contains three memory locations assigned with port addresses of the logical interface. Port A(PA), Port B(PB) and Control registers(CR) are equated with appropriate port addresses.

CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
       
Code segment starts with initializing of data segment at the line 3 and 4 in the snippet.

MOV DX,CR
MOV AL,82H
OUT DX,AL
We are activating ports of the logic controller. That is done in this way.
Control register port address (CR) is moved into DX register. Also port address (82H which is port C, which is also called as Control ward) is moved into AL register. Ports are then activated using OUT command (OUT DX,AL)

MOV DX,PB
IN AL,DX
Input is then taken from Port B using IN instruction(to do this, port b address must be in DX). The value inputted is stored in register AL.

Next we have to display whether parity is even or odd and display ‘FF’ if even parity. Otherwise display ‘00’.

MOV DX,PA
MOV BL,AL
Output port address is moved into DX. And AL is backed up into BL.(for checking number of 1s in AL later).

AND AL,AL
JP FF
MOV AL,0
OUT DX,AL
JMP COUNT
FF:
MOV AL,0FFH
OUT DX,AL
AL is ANDed with itself to check for parity(AL will remain same after ANDing since we are ANDing with itslef). If the resulting number is of even parity, it means AL is even parity number so jump to label ‘FF’ to display the same and after displaying, jump to label COUNT. Otherwise move ‘0’ to AL and display. For displaying, we need output port address in DX which is done in previous snippet. OUT command is used to display the contents of AL through Port A.


Next is counting the number of 1s in the inputted 8 bit number

COUNT:  
CALL DELAY
MOV AL, 0
MOV CL,08
Call some delay, otherwise you wont be able to see the parity indicator ‘FF’ or ‘00’ in the controller.
Then move 0 to AL, stating that initially number of 1s is 0. You should increment 1s each time you get a 1 in the input number. CL is assigned to 8, We should run the comparison for 1, 8 times since input is 8 bit. CL acts as a counter.

UP:    
ROR BL,01
JNC DOWN1
INC AL
DOWN1: 
DEC CL
JNZ UP
OUT DX, AL
MOV AH,4CH
INT 21H
UP is a label.
Now we have the original 8 bit number in BL (remember we had backed up in BL at the beginning). Right rotate it and check the carry flag. (since carry flag contains the rightmost bit after ROR). If carry was set, it means the number is 1, hence count it by increment AL. If carry isn’t set, jump to DOWN1 label for next number.
Each time the number is checked, decrement the loop counter CL, and if it is not equal to 0, it means you still have numbers to be checked. Go to label UP to check for more.
Finally after 8 comparisons, that is when CL becomes 0, the number of 1s will be in AL. Display it using OUT command and terminate.

DELAY PROC NEAR
PUSH CX
PUSH BX
MOV CX, 0FFFFH
B1:  MOV BX, 0FFFFH
B2:  DEC BX
       JNZ B2
       LOOP B1
       POP BX
       POP CX
       RET
DELAY ENDP
CODE ENDS
END START
Delay procedure is same for all programs.
Code segment ends and so does START label.

Output:
Output for this program will be seen in logic controller.
(see the DELAY and Executing explanations in MP hardware basics page).

He is a simple passionate tech freak who himself is an engineering student at Canara Engineering college. He likes App Development, Web designing, Blogging, Youtubing, Debugging and also is a CodeGeek!

Sharing is sexy!

Related Articles

Share your views about this article!