ADDITION OF TWO ARRAYS OF BINARY NUMBERS, EACH OF 8 BYTE LENGTH

EXPERIMENT NO.:-1DATE:-

AIM:- Program to add two arrays binary numbers, each of 8 byte length.

PROGRAM:

Address / Opcodes / Label / Mnemonics / Operand / Comments
0200 / F8 / CLC / Clear Carry Flag
0201 / B9 04 00 / MOV / CX,0004 / Load counter register with number of times addition to be performed
0204 / BE 00 03 / MOV / SI,0300 / Load source index register with starting address of 1st Binary no.
0207 / BF 08 03 / MOV / DI,0308 / Load destination index reg with destination address
020A / 8B 04 / MOV / AX,[SI] / Load data bytes which are in location 0300 & 0301 in 16 bit acc
020C / 11 05 / ADC / [DI],AX / Add the contents of 0308,0309 with the contents of 0300 &0301 and store the result into the location 0308
020E / 46 / INC / SI / Point at 0302 location
020F / 46 / INC / SI
0210 / 47 / INC / DI / Point at next location 030A
0211 / 47 / INC / DI
0212 / 49 / DEC / CX / Decrement the counter
0213 / 75 F5 / JNZ / 020A / If not zero then continue addition
0215 / F4 / HLT / Else halt

DATA:RESULT:

0300:0308:0308:

0301:0309:0309:

0302:030A:030A:

0303:030B:030B:

0304:030C:030C:

0305:030D:030D:

0306:030E:030E:

0307:030F:030F:

FIND THE LARGEST NUMBER IN A GIVEN STRING

EXPERIMENT NO.:-2DATE:-

AIM:- Program to find largest number in a given string.

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BE 00 03 / MOV / SI,0300 / Load SI register with starting address of string
0203 / B9 10 00 / MOV / CX,0010 / Initialize counter register
0206 / B4 00 / MOV / AH,00 / Initialize the 8 bit accumulator
0208 / 3A 24 / CMP / AH,[SI] / 1st data byte of the string is compared with 00
020A / 73 02 / JAE / 020E / If both bytes are equal or above jump to location 020E
020C / 8A 24 / MOV / AH,[SI] / Else move the content into acc
020E / 46 / INC / SI / Point to the next address of the string
020F / E0 F7 / LOOP / NZ , [0208] / Decrement the counter value if not zero continue the processing
0211 / 88 24 / MOV / [SI],AH / Larger no. is stored in 0310 address location
0213 / F4 / HLT / Halt

DATA:RESULT:

0300:0308:0310:

0301:0309:

0302:030A:

0303:030B:

0304:030C:

0305:030D:

0306:030E:

0307:030F:

PACKED BCD FROM TWO ASCII NUMBERS

EXPERIMENT NO.:-3DATE:-

AIM:- Program to produce packed BCD from two ASCII numbers.

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BE 00 03 / MOV / SI,0300 / Load SI register to store the result
0203 / B3 35 / MOV / BL,’5’ / Load 1st ASCII digit
0205 / B0 39 / MOV / AL,’9’ / Load 2nd ASCII digit
0207 / 80 E3 0F / AND / BL,OFH / Mask upper 4 bit of 1st digit
020A / 24 0F / AND / AL,0FH / Mask upper 4 bits of 2nd digit
020C / B1 04 / MOV / CL,04H / Load the counter to rotate 4 times
020E / D2 C3 / ROL / BL,CL / Rotate the content of BL left by 4 bits
0210 / 0A C3 / OR / AL,BL / OR both masked digits
0212 / 88 04 / MOV / [SI],AL / Store the result in 0300 location
F4 / HLT / Halt

RESULT:

0300:

SORT A STRING OF BYTE IN DESCENDING ORDER

EXPERIMENT NO.:-4DATE:-

AIM:- Program to sort a string of byte in the descending order.

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BE 00 03 / MOV / SI,0300 / Initialize SI reg with mem locn 0300
0203 / 8B 1C / MOV / BX,[SI] / BX has the no. of bytes from locn 0300 & 0301
0205 / 4B / DEC / BX / Decrement the no. of bytes by one
0206 / 8B 0C / MOV / CX,[SI] / Also CX has no. of bytes from locn 0300 & 0301
0208 / 49 / DEC / CX / Decrement the number of bytes by one
0209 / BE 02 03 / MOV / SI,0302 / Initialize SI reg with the starting address of the string
020C / 8A 04 / MOV / AL,[SI] / Move the first data byte of string into AL
020E / 46 / INS / SI / Point at the next bytes of the string
020F / 3A 04 / COMP / AL,[SI] / Compare the two bytes of the string into AL
0211 / 73 06 / JAE / 0219 / If two bytes are equal or 1st byte is greater than the 2nd jump to locn 0219
0213 / 86 04 / XCHG / AL,[SI] / Else swap the two bytes
0215 / 4E / DEC / SI
0216 / 88 04 / MOV / [SI],AL
0218 / 46 / INC / SI / Point at the next locn of the string
0219 / E2 F1 / LOOP / 020C / Continue the process if count is not 0
021B / 4B / DEC / BX / Decrement the conter for next pass
021C / BE 00 03 / MOV / SI,0300 / Load the counter value
021F / 75 E5 / JNZ / 0206 / If count is 0 jump to locn 0206
0221 / F4 / HLT / halt

DATA: RESULT:

0300: 0302:

0301:0303:

0302:0304:

0303:0305:

0304:

0305:

COUNT NUMBER OF BYTES IN A STRING OF DATA

EXPERIMENT NO.:-5DATE:-

AIM:- Program to count no. of bytes in a string of data

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BE 00 03 / MOV / SI,0300 / Load SI reg with the starting address where the result is to be stored
0203 / B9 FF FF / MOV / CX,FFFF / Initialize the counter register
0206 / BF 02 03 / MOV / DI,0302 / Load DI reg with the starting address of the string
0209 / BO 03 / MOV / AL,03 / Store the identifiers in ASL
020B / F2 / REPNZ / Data byte accessed by DI reg compared with identifier with altering either of the contents,this comparing continuous with the incrementing of DI counter till the two bytes match.With each scanning the contents of CX go on decrementing by 1
020C / AE / SCASB
020D / F7 D1 / NOT / CX / Z’s complemented CX & move CX
into 0300
020F / 89 0C / MOV / [SI],CX
0211 / CC / INT3 / Halt

DATA:

Let (309)=03

Then after executing the program CX=0008 & (0300)=08(0301)=00

CONVERT THE STRING OF DATA INTO ITS COMPLIMENT FORM

EXPERIMENT NO.:-6DATE:-

AIM:- Program to convert the data string to equivalent 2’s compliment

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BE 00 03 / MOV / SI,0300 / Load SI register with the starting address of data string
0203 / BF 00 04 / MOV / DI,0400 / Load DI with the starting address of result locns
0206 / B9 10 00 / MOV / CX,0010 / Load CX with the no. of bytes in the string
0209 / AC / LODSB / Load AL with data byte accessed by SI register and increment the address locn in SI reg
020A / F6 D8 / NEG / AL / The content of AL are 2’s complimented
020C / AA / STOSB / Store AL contents in locn pointed to by DI ref. and increment the current location in DI reg
020D / EO FA / LOOP / NZ 02090 / If CX=0000 continue 2’s complementing the data in string else
020F / F4 / HLT / Halt

DATA: RESULT:

0300: 0400:

0301:0401:

0302:0402:

0303:0403:

0304: 0404:

0305: 0405:

0306:0406:

0307:0407:

0308;0408:

0309:0409:

030A:040A:

030B:040B:

030C:040C:

030D:040D:

030E:040E:

030F:040F:

MOVE A BLOCK OF DATA UPWARD

EXPERIMENT NO.:-7DATE:-

AIM:- Program to move block of data string upward

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / FD / STD / Direction flag is set to order the auto decrement the SI and DI index regs
0201 / BE 1F 03 / MOV / SI,031F / Load SI with the end address of block of data
0204 / BF 2F 03 / MOV / DI,032F / Load DI with the end address of block where the block of data is to be moved
0207 / B9 20 00 / MOV / CX,0020 / Initialize count reg with the no. of bytes in the string
020A / F2 A5 / REPNE:MOVSW / It transfers the words from the SI locns to DI string till CS doesnot become zero
020C / F4 / HLT / Halt

DATA: RESULT:

0300: 0400:

0301:0310:

0302:0312:

0303:0313:

0304: 0314:

0305: 0315:

0306:0316:

0307:0317:

0308;0318:

0309:0319:

030A:031A:

030B:031B:

030C:031C:

030D:031D:

030E:031E:

030F:031F:

BINARY TO GRAY CONVERSION

EXPERIMENT NO.:- 8DATE:-

AIM:- Program to convert Binary number to gray code

PROGRAM:

Address / Opcodes / Mnemonics / Operand / Comments
0200 / BB 00 03 / MOV / BX,0300 / Load BX with the starting address of look up table.
0203 / BE 50 05 / MOV / SI,0500 / Load SI with the address of binary no. whose gray code is to be found
0205 / AC / LOOSB / Load AL with the data byte accessed by SI reg and increment its current address by one i.e SI=0151
0207 / D7 / XLAT / AL=(BX+AL) i.e the contents of address accessed by BX+AL is stored in AL
0208 / 88 / MOV / [SI],AL / The contents of AL are moved into locn pointed by SI i.e 0151 contains the result
020A / F4 / HLT / Halt

DATA:

0300:

0301:

0302:

0303:

0304:

0305:

0306:

0307:

0308;

0309:

030A:

030B:

030C:

030D:

030E:

030F:

EXCHANGE A BLOCK OF DATA

EXPERIMENT NO.:-10DATE:-

AIM:- Microcontroller Program to exchange a block of data from one memory location to other

PROGRAM:

Label / Mnemonics / Operand / Comments
Org / 0000h / Orginate the memory location
Sjmp / 30h / Short jump to 30h location
0rg / 30h / Orginate the program from 30h location
Mov / R0,#27h / Move the source address to r0 reg
Mov / R1,#41h / Move the destination address to r1 reg
Mov / R3,#05h / Store the number of data’s to be exchanged in r3 reg
back: / movx / A,@r0 / First data is taken into acc
Mov / R4,a / From acc is transferred into reg r4
movx / A,@r1 / Destination addressed data is moved into acc
movx / @r0,a / From acc it is tranfered to source location
Mov / A,r4 / And the data located at source is moved to destination
movx / @r1,a
Inc / R0 / Increment the source address location
Inc / R1 / Increment the destination address location
djnz / R3,back / Decrement the counter if not zero jump to back
Here: / sjmp / Here / Short jump
End / End of the program

Result:

X:0027h

X:0041h

INTERFACING OF 8255 WITH 8086

EXPERIMENT NO.:-11DATE:-

AIM:- Interfacing and programming of 8255 (programmable peripheral interface).

Introduction: The parallel input output port chip 8255 is designed to interface with 8 bit, 16 bit and higher capability processor. It has 24 input output lines which may be individually program in two groups of 12 lines each or 3 groups of 8 lines. The 2 group of input output pins are named as group A and group B. each of this group contain a subgroup of 8 input output lines called as 8 bit port and another subgroup of 4 input output line or 4 bit port. Thus group A contain an 8 bit port A along with a 4 bit port C upper.

The port A lines are identified by symbols PA0 to PA7 while the port C lines are identified by PC4 to PC7. similarly group B contains an 8 bit port B containing lines PB0 to PB7 and 4 bit port C with PC0 to PC3. The 8 bit data bus buffer is control by read/write logic. The read/write control logic manages all of the internal and external transfers of both data and control words. RD, WR, A1, A0 and RESET are the inputs provided by the microprocessor to read/write control logic.

The 8 bit 3 state bidirectional buffer is used to interface the 8255 internal data bus wit external system data bus. This buffer receives or transmits data upon execution of input or output instruction by microprocessor. The control word or status information is also transferred through the buffer.

Modes Of Operation: There are 2 basic modes of operation of 8255 I/O mode and BSR mode( bit set reset mode).In i/o mode 8255 work as programmable i/o ports while in BSR mode only port C can be used to set or reset its individual port bits.Under I/O mode there are further 3 modes of operation Viz mode 0, mode 1, and mode 2.

1)BSR Mode:- In this mode any of 8 bits of portC can be set or reset depending on B0 of control word the bit to be set or reset is selected by bit select flags B3,B2,B1 of CWR is as shown below:-

B3 / B2 / B1 / Selected bits of port C
0 / 0 / 0 / B0
0 / 0 / 1 / B1
0 / 1 / 0 / B2
0 / 1 / 1 / B3
1 / 0 / 0 / B4
1 / 0 / 1 / B5
1 / 1 / 0 / B6
1 / 1 / 1 / B7

B7B6 B5 B4 B3 B2 B1 B0

1 / X / X / X

0-for BSR mode| Bit select flags | 0-Rsest, 1-Set

I/O Mode control word register format and BSR mode control word register format

2). I/O mode:

a): Mode 0 (basic I/O mode): This mode provides simple input and output capability using each of the 3 ports. Data can be simply read from and return to the input and output ports resp. after appropriate initialization.

The silent features of this mode are listed below:

1)Two 8 bit port (A & B) and Two 4 bit ports (port C upper and lower) are available. The two 4 bit port can be combined by used as a 3rd 8 bit port.

2)Any port can be used as an input or output port.

3)Output ports are latched. Input ports are not latched.

4)A maximum of 4 ports are available so that overall 16 I/O configurations are possible.

All this modes can be selected by programming a register internal to 8255 known as control word register. The control word register has 2 formats. The first format is valid for I/O modes of operation i.e. mode 0, mode 1 and mode 2 while the 2nd format is valid for bit set/reset format.

b): Mode 1 (Strobed I/O mode): This mode is known as strobe I/O mode. Handshaking signals are given by port C bits. The PC 0- PC2 signals of port C provides handshaking signals of port A. the port C and port A are grouped as group B. The PC3- PC5 provides strobe lines for port A. This group includes port A and PC3 and PC5 forms group A. The silent features of mode 1 are listed as follows:

1)Two groups group A and group B are available for strobed data transfer.

2)Each group contains one 8 bit data I/O port and one 4 bit control/data port.

3)The 8 bit data port can be used as I/O port.

4)Out of 8 bit port C, PC0 to PC2 are used to generate control signals for port B and PC3 to PC5 are used to generate control signals for port A. the lines PC6 and PC7 can be used as independent data lines.

c): Mode 2 (Strobed bidirectional I/O): This mode of operation of 8255 provides 8255 an additional feature for communicating with peripheral device on an 8 bit data but. Hand shaking signals are provided to maintain proper data flow and synchronization between data transmitter and receiver. The intruded generation and other function are similar to mode 1. The silent features of mode 2 are as follows:

1)The single 8 bit port in group A is available.

2)The 8 bit port is bidirectional and additionally 5 bit control port is available.

3)Three I/O lines are available at port C.

Interfacing 8255 with 8086:

Interface an 8255 with 8086 to work as an I/O port. Initialize port A as output port, port B as input port, and port C as output port. Port A address should be 0740H. Write a program to sense switch positions SW0-SW7 connected at port B. The sensed pattern is to be displayed on port A to which 8 LEDs are connected, while port C lower displays no. of ON switches out of total 8 switches.

Solution:

The control word is decided as follows

B7 B6 B5 B4 B3 B2 B1B0

1 / 0 / 0 / 0 / 0 / 0 / 1 / 0
I/O mode / Port A in mode 0 / Port A output / Port C O/P / Port B mode 0 / Port B I/P / Port C O/P

Control word =82H.

Thus 82H is the control word for the requirement in the problem. The 8255 is to be interfaced with the lower order data bus i.e. D0 to D7.

Group A modes:

B6 / B5 / Mode
0 / 0 / Mode 0
0 / 1 / Mode 1
1 / 0 / Mode 2
1 / 1 / X

1)Port B mode is either 0 or 1 depending upon B2 bit.

2)A port is an o/p port if the port bit is 0 else it is i/p port.

ALP:

MOV DX, 0746H ; Initialize CWR with control word 82H

MOV AL, 82H

OUT DX, AL

SUB DX, 04; Get address of port B in DX

IN AL, DX; Read port B for switch positions into AL and get port A

SUB DX, 02; address in DX

OUT DX, AL; Display switch positions on port A

MOV BL, 00H; Initialize BL for switch count

MOV CH, 08H;Initialize CH for switch number

YY: ROL AL; Rotate AL through carry to check whether the switch is

JNC XX; On or OFF i.e. either 1 or 0

INC BL

XX: DEC CH; Check for next switch . if

JNZ YY; all switch are checked , the

MOV AL, BL ; number of on switches are

ADD DX, 04; in BL. Display it on port C

OUT DX, AL; lower.

HLT ;Stop.

Flow Chart:

Connection Diagram:

Practice Question:

Interface a 4*4 keyboard with 8086 using 8255 and write an ALP for detecting a key closure and return the key code in AL. The debouncing period for a key is 10 ms. Use software key debouncing technique

MICROPROCESSOR & INTERFACING LAB, DEPT OF E&C, CITM, INDORE