3b. Reading two 8 bit numbers and displaying the product

vtu mp 3b
Q)  Read the status of two 8-bits inputs (X & Y) from the Logic Controller Interface and display X*Y.

This program will display the product of two 8 bit input numbers x and y (inputted from logic controller) on the logic controller.

Algorithm: 
Step 1: Connect Logic Controller to PC.
Step 2: Set the 8255 using control word.
Step 3: Read the first data (Port B) from logic controller and store in X.
Step 4: Read the second data (Port B) from logic controller and store in Y.
Step 5: res=X*Y
    Display(higher 8 bit data of res)
Step 6: Call delay procedure or wait some time.
Step 7: Stop

CODE:


Explanation:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
CR EQU 0e803H
PA EQU 0e800H
PB EQU 0e801H
PC EQU 0e802H
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), Port C(PC) 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
MOV DX,PB   
IN AL,DX
MOV BL,AL
CALL DELAY
Activating Controller using normal procedure.(first 3 lines)
Inputting a number using IN instruction (Port B is input and its address is moved into DX).
Inputted number (x) is moved to BL. (this is first number for multiplication)
Call some delay after entering first number.

MOV DX,PB
IN AL,DX
MUL BL
Take second number (Y) using IN command,(DX containing the input port address).
First number is in BL and second one in AL.
Multiply content of AL and BL using MUL BL. Result of multiplication is stored in AL.

MOV DX,PA
OUT DX,AL
MOV AH,4CH
INT 21H
Move Output port address into DX and Display the result which is AL using OUT command. Finally terminate.

DELAY PROC
PUSH BX
PUSH DX
MOV DX,0FFFH
UP2:    MOV BX,0FFFFH
UP1:NOP
    DEC BX
    JNZ UP1
    DEC DX
    JNZ UP2
    POP DX
    POP BX
    RET
DELAY ENDP
CODE ENDS
END START
Delay procedure is same.See explanation See explanation here.

Output:
Seen in logic controller



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!