Google
Showing posts with label Experiment. Show all posts
Showing posts with label Experiment. Show all posts

Feb 19, 2008

Assembly Language Program to be executed when NMI is generated

Assembly Language Program to be executed when NMI is generated

AIM:To write Assembly Language Program to be executed when NMI is generated

APPARATUS:-
Microprocessor trainer kit & power supply.

NON MASKABLE INTERRUPT (NMI)

NMI is an edge triggered input pin which causes Type-2 interrupt. The NMI is not mask able internally by software. A transition from low to high initiates the interrupt response at the end of the current instruction. This input is internally synchronized.
When an external device interrupts the CPU at the interrupt pin NMI and the CPU is executing an instruction of a program. The CPU first completes the execution of current instruction. The IP is then incremented by one to point next instruction. The CPU then acknowledges the requesting device on its INTA pin immediately for NMI. After an interrupt is acknowledged, the CPU computes the vector address from the type of the interrupt that may be passed to interrupt structure of the CPU internally or externally (for NMI vector address is 00008 H). The contents of PSW, CS & IP are next pushed on stack. The contents of IP & CS now points to the address of the next instruction in main program from which the execution is to be continued after executing the ISR. The control is then transferred to Interrupt Service Routine for serving the interrupting device. The new address is found out from the interrupt vector table (for NMI [00009:00008] = ISR IP & [0000B:0000A] = ISR CS. The execution of ISR starts. At the end of ISR the last instruction should be IRET. When CPU executes IRET instruction the IP, CS & PSW is popped back from the stack and the execution continued from address received by IP & CS.

WRITE THIS PROGRAM AT 0000:4000 H MEMORY LOCATION AND EXECUTE IT
0000:4000 MOV AX,0FFFFH 
0000:4003 MOV BX,0FFFFH 
0000:4006 ADD AX,BX 
0000:4008 HLT 
0000:4009 
WRITE THIS PROGRAM AT 0000:4100 H MEMORY LOCATION AND EXECUTE IT

0000:4100 MOV AX,0000H 
0000:4103 MOV DS,AX 
0000:4105 MOV AL,00H 
0000:4107 MOV [0008],AL 
0000:410A MOV AL,40H 
0000:410C MOV [0009],AL 
0000:410F MOV AL,00H 
0000:4111 MOV [000A],AL 
0000:4114 MOV AL,00H 
0000:4116 MOV [000B],AL 
0000:4119 HLT 
0000:411A  

NOW PRESS NMI BUTTON ON 8086 MICROPROCESSOR KIT

You might be also interested in:

:: MASM 611 SOFTWARE
:: bit reversal and sorting programs
:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086

Feb 9, 2008

Traffic light control system using 8086

AIM:-
To develop Traffic light Control system using 8086

APPARATUS:-
Microprocessor trainer kit, Traffic light controller kit, power supply, data cable etc

THEORY:-
Traffic light controller interface module is designed to simulate the function of four way traffic light controller. Combinations of red, amber and green LED’s are provided to indicate Halt, Wait and Go signals for vehicles. Combination of red and green LED’s are provided for pedestrian crossing. 36 LED’s are arranged in the form of an intersection. A typical junction is represented on the PCB with comprehensive legend printing.
At the left corner of each road, a group of five LED’s (red, amber and 3 green) are arranged in the form of a T-section to control the traffic of that road. Each road is named North (N), South(S), East (E) and West (W). LED’s L1, L10, L19 & L28 (Red) are for the stop signal for the vehicles on the road N, S, W, & E respectively. L2, L11, L20 & L29 (Amber) indicates wait state for vehicles on the road N, S, W, & E respectively. L3, L4 & L5 (Green) are for left, strait and right turn for the vehicles on road S. similarly L12-L13-L14, L23-L22-L21 & L32-L31-L30 simulates same function for the roads E, N, W respectively. A total of 16 LED’s (2 Red & 2 Green at each road) are provided for pedestrian crossing. L7-L9.L16-L18, L25-L27 & L34-L36 (Green) when on allows pedestrians to cross and L6-L8, L15-L17, L24-L26 & L33-L35 (Red) when on alarms the pedestrians to wait.
To minimize the hardware pedestrian’s indicator LED’s (both red and green are connected to same port lines (PC4 to PC7) with red inverted. Red LED’s L10 & L28 are connected to port lines PC2 & PC3 while L1 & L19 are connected to lines PC0 & PC1 after inversion. All other LED’s (amber and green) are connected to port A & B.

WORKING:-
8255 is interfaced with 8086 in I/O mapped I/O and all ports are output ports. The basic operation of the interface is explained with the help of the enclosed program. The enclosed program assumes no entry of vehicles from North to West, from road East to South. At the beginning of the program all red LED’s are switch ON, and all other LED‘s are switched OFF. Amber LED is switched ON before switching over to proceed state from Halt state.
The sequence of traffic followed in the program is given below.
a) From road north to East
From road east to north
From road south to west
From road west to south
From road west to north
b) From road north to East
From road south to west
From road south to north
From road south to east
c) From road north to south
From road south to north
Pedestrian crossing at roads west & east
d) From road east to west
From road west to east
Pedestrian crossing at roads north & south

microprocessor traffic light control



ASSEMBLY LANGUAGE PROGRAMS:-
MODEL SMALL
.STACK 100
.DATA
CWR EQU 0FFC6 H
PORTA EQU 0FFC0 H
PORTB EQU 0FFC2 H
PORTC EQU 0FFC4 H
.CODE
START:
MOV AX,@DATA
MOV DS,AX
MOV AL,80H
MOV DX,CWR
OUT DX,AL
MOV AL,F3H
MOV DX,PORTC
OUT DX,AL
MOV AL,FFH
MOV DX,PORTA
OUT DX,AL
MOV AL,FFH
MOV DX,PORTB
OUT DX,AL
MOV CL,03H
CALL DELAY
TOP:
MOV AL,EEH
MOV DX,PORTA
OUT DX,AL
MOV AL,EEH
MOV DX,PORTB
OUT DX,AL
MOV CL,02H
CALL DELAY

MOV AL,FCH
MOV DX,PORTC
OUT DX,AL
MOV AL,7DH
MOV DX,PORTA
OUT DX,AL
MOV AL,57H
MOV DX,PORTB
OUT DX,AL
MOV CL,15H
CALL DELAY

MOV AL,E7H
MOV DX,PORTB
OUT DX,AL
MOV AL,FDH
MOV DX,PORTA
OUT DX,AL
MOV AL,EDH
MOV DX,PORTA
OUT DX,AL
MOV CL,02H
CALL DELAY

MOV AL,F7H
MOV DX,PORTB
OUT DX,AL
MOV AL,F0H
MOV DX,PORTC
OUT DX,AL
MOV AL,F1H
MOV DX,PORTA
OUT DX,AL
MOV CL,15H
CALL DELAY

MOV AL,FBH
MOV DX,PORTA
OUT DX,AL
MOV AL,FBH
MOV DX,PORTB
OUT DX,AL
MOV AL,50H
MOV DX,PORTC
OUT DX,AL
MOV CL,15H
CALL DELAY

MOV AL,FEH
MOV DX,PORTA
OUT DX,AL
MOV AL,FEH
MOV DX,PORTB
OUT DX,AL
MOV CL,03H
CALL DELAY

MOV AL,FFH
MOV DX,PORTA
OUT DX,AL
MOV AL,AFH
MOV DX,PORTC
OUT DX,AL
MOV AL,EEH
MOV DX,PORTA
OUT DX,AL
MOV AL,EEH
MOV DX,PORTB
OUT DX,AL
MOV CL,02H
CALL DELAY

MOV AL,BFH
MOV DX,PORTA
OUT DX,AL
MOV AL,BFH
MOV DX,PORTB
OUT DX,AL
MOV CL,15H
CALL DELAY
JMP TOP

DELAY:
MOV BX,10H
D1:
MOV CX,0FFFFH
D2:
LOOP D2
DEC BX
JNZ D1
INT 03H
END START


PROCEDURE:-
1. Connect power supply 5V & GND to both microprocessor trainer kit & Traffic light controller interfacing kit.
2. Connect data bus between microprocessor trainer kit & Traffic light controller interfacing kit.
3. Enter the program to control Traffic light.
4. Execute the program by typing GO E000:0B80 ENTER.
5. Observe the LED’s on traffic light controller PCB.

You might be also interested in:

:: MASM 611 SOFTWARE
:: bit reversal and sorting programs
:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086



Jan 28, 2008

Temperature Control system using 8086

AIM:-

To develop Temperature Control system using 8086

APPARATUS:-

Microprocessor trainer kit, Temperature controller kit, power supply, data cable etc

THEORY:-

Temperature control system involved interfacing successive approximation ADC and typical method of measuring and controlling the temperature using microprocessor. ADC is among the most widely used devices for data acquisition. A digital computer uses binary values, but in physical world everything is analog, temperature, pressure, humidity, and velocity are few examples of physical quantities that we seal with every day.

Temperature measurement is of great importance in industry as most of the processes are temperature dependent. A number of devices and schemes have been used over the years, for the measurement of temperature. Typical sensors include devices like thermocouples, thermostats, RTD’s and semiconductor sensor.

This system uses semiconductor sensor AD590 to monitor the temperature of water bath. The AD590 is basically a PTAT (proportional to absolute temperature) current regulator. It generates a current O/P of 1µA/K above absolute zero temperature that is -2730C. Thus at 00C the current O/P will be 273µA and 250 if will be 298µA and 373mV at 1000. This O/p is buffered through an OPAMP having a gain of 10. To enable easy equivalence between the transducers O/P in volts and the measured temperature a calibration procedure needs to be done.

WORKING:-

8255 is interfaced with 8086 in I/O mapped I/O. port A (PA0-PA7) as input port is connect to data lines of ADC, PB0, PB1, PB2 lines of port B for channel selection, PC2 connected to Start of conversion (SOC) and PC3 to O/P enable. Channel 1 of ADC is used to input analog signal, Channel 0 of ADC for temperature controller.

ADC will give binary equivalent of the I/P voltage. Input will vary from 0 to 5V (0 to 100 degree C) and the ADC O/P varies from 00-FFH. So 5V/100 i.e. 5000mvs/100 gives 50mvs/0C. And the counts for indication of temperature are taken as 2.5 (256/100) per degree C.

AC supply to the external heating element is controlled through the onboard Relay, based on the set value. When the temperature of the heating element (which is sensed by AD590, AD590 output is analog which is converted to digital by ADC) is less than the set value (reference value) heating element will be switched ON and when temperature crosses the set temperature AC supply is turned OFF.




MODEL SMALL
.STACK 100
.DATA
START:
PORTA EQU FFC0H ; PORTA address
PORTB EQU FFC2H ; PORTB address
PORTC EQU FFC4H ; PORTC address
CTL EQU FFC6H ; Control port address
CTL_BYTE EQU 98H ; 8255 control reg.
CLEAR_DISPLAY EQU F800:4BB1H
DWAD EQU F800:4BB1H
DBDTA EQU F800:4F1F
DEC_TEMP DB 0
SET_TEMP DB 0
ADC_VAL DB 0
COUNT DB 0
PRE_TEMP DB 0
.CODE
ADC TABLE:

DB 00H,03H,05H,08H,0aH,0dH,0fH,11H,14H,16H


DB 19H,1cH,1eH,21H,24H,27H,2aH,2cH,2eH,32H

DB 34H,36H,39H,3cH,3fH,42H,45H,48H,4aH,4cH

DB 4eH,50H,52H,54H,56H,58H,5bH,61H,64H,67H

DB 6aH,6dH,70H,72H,74H,77H,7aH,7dH,7fH,82H

DB a0H,a2H,a5H,a8H,aaH,aDH,afH,b0H,b3H,b6H

DB b9H,bcH,bfH,c1H,c4H,c6H,c9H,ccH,cfH,d0H

DB d2H,d5H,d7H,daH,dcH,dfH,e0H,e2H,e5H,e7H

DB e9H,ebH,eeH,f1H,f4H,f6H,f9H,fcH,ffH

START:
MOV AL,CTL_BYTE ; 8255
MOV DX,CTL ; PORTC (lower) as output
OUT DX,AL ; PORTA as input
MOV AL,DEC_TEMP
CALL DEC_HEX
MOV SET_TEMP,AL
MOV AL,DEC_TEMP
MOV AH,00
MOV SI,AX
CALL FAR DWAD
MOV DX,CTL
MOV AL,02
OUT DX,AL
MOV AL,00
OUT DX,AL
MOV CX,70
L0:
LOOP L0
BACK:
MOV COUNT,0
CALL ADC
CALL DISP_TEMP
CALL TEMP_CONTL
JMP BACK
DISP_TEMP:
MOV AL,ADC_VAL
MOV SI,OFFSET ADC_TABLE
AGAIN:
CMP AL,[SI]
JC FOUND
JE FOUND
INC SI
INC COUNT
JMP AGAIN
FOUND:
MOV AL,COUNT
CALL HEX_DEC
MOV AH,0
MOV SI,AX
CALL FAR DBDTA
RET
TEMP_CONTL:
MOV AL,COUNT
CMP AL,SET_TEMP
JC TURN_ON_RELAY
RELAY_OFF:
MOV DX,PORTB
MOV AL,0FFH
OUT DX,AL
MOV DL,20H
HERE1:
MOV CX,FFFFH
HERE:
LOOP HERE
DEC DL
JNZ HERE1
RET
TURN_ON_RELAY:
MOV DX,PORTB
MOV AL,00H
OUT DX,AL
CONTINUE:
MOV CX,FFFFH
L22:
LOOP L22
RET
ADC:
MOV DX,CTL
MOV AL,01
OUT DX,AL
MOV CX,70
L10:
LOOP L10
MOV AL,00
OUT DX,AL
L1:
MOV DX,PORTC
IN AL,DX
AND AL,80H
CMP AL,80H
JNZ L1
MOV DX,PORTA
IN AL,DX
MOV ADC_VAL,AL
RET
HEX_DEC:
MOV AH,00H
MOV CL,0AH
DIV CL
MOV CL,04H
ROL AL,CL
AND AL,F0H
OR AL,AH
RET
DEC_HEX:
MOV BL,AL
AND BL,0FH
AND AL,F0H
MOV CL,04
ROR AL,CL
MOV CL,0AH
MUL CL
ADD AL,BL
RET
END START

PROCEDURE:-

1. Connect power supply 5V & GND to both microprocessor trainer kit & temperature controller interfacing kit.

2. Connect data bus between microprocessor trainer kit & temperature controller interfacing kit.

3. Enter the program to read temperature of the water bath from ADC at 0000:4000.

4. Execute the program by typing GO 0000:4000 enter.

5. Enter the reference temperature value, when temperature of water bath exceeds reference value then power supply to water bath is switched OFF.


You might be also interested in:

:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI
:: Interfacing Stepper Motor to 8086 using 8255

Jan 22, 2008

Interfacing Stepper Motor to 8086 using 8255

To Interface Stepper Motor to 8086 using 8255 and write Assembly Language Program to rotate Stepper Motor in Clockwise & Anticlockwise direction.

APPARATUS:-
Microprocessor trainer kit, ADC kit, power supply, data cable etc

THEORY:-
Stepper motor is a device used to obtain an accurate position control of rotating shafts. A stepper motor employs rotation of its shaft in terms of steps, rather than continuous rotation as in case of AC or DC motor. To rotate the shaft of the stepper motor, a sequence of pulses is needed to be applied to the windings of the stepper motor, in proper sequence. The numbers of pulses required for complete rotation of the shaft of the stepper motor are equal to the number of internal teeth on its rotor. The stator teeth and the rotor teeth lock with each other to fix a position of the shaft. With a pulse applied to the winding input, the rotor rotates by one teeth position or an angle x. the angle x may be calculated as.
x = 3600 / no. of rotor teeth
After the rotation of the shaft through angle x, the rotor locks it self with the next tooth in the sequence on the internal surface of the stator. The typical schematic of a typical stepper motor with four windings is as shown below.


The stepper motors have been designed to work with digital circuits. Binary level pulses of 0-5V are required at its winding inputs to obtain the rotation of the shafts. The sequence of the pulses can be decided, depending upon the required motion of the shaft. By suitable sequence of the pulses the motor can be used in three modes of operation.


  • One phase ON (medium torque)
  • Two phase ON (high torque)
  • Half stepping (low torque)


WORKING:-
8255 is interfaced with 8086 in I/O mapped I/O. port C (PC0, PC1, PC2, PC3) is used to give pulse sequence to stepper motor. The 8255 provides very less current which will not be able to drive stepper motor coils so each of the winding of a stepper motor needs to be interfaced using high speed switching Darlington transistors with max 1A, 80V rating with heat sink, with the output port of 8255. Output the sequence in correct order to have the desired direction to rotate the motor.





Assembly Language Program to rotate Stepper Motor in Clockwise direction

MODEL SMALL
.STACK 100
.DATA
PORTA EQU FFC0H ; PORTA ADDRESS
PORTB EQU FFC2H ; PORTB ADDRESS
PORTC EQU FFC4H ; PORTC ADDRESS
CWR EQU FFC6H ; CONTROL PORT ADDRESS
PHASEC EQU 03H
PHASEB EQU 06H ; SEQUENCE IN SERIES TO ROTATE MOTOR
PHASED EQU 0CH ; IN CLOCKWISE DIRECTION
PHASEA EQU 09H
.CODE
START:
MOV AL,@DATA
MOV DX,CTL
OUT DX,AL
AGAIN:
MOV AL,PHASEC
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP:
LOOP UP

MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1

MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2

MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH

UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START




Assembly Language Program to rotate Stepper Motor in Anticlockwise direction
MODEL SMALL
.STACK 100
.DATA
PORTA EQU FFC0H ; PORTA ADDRESS
PORTB EQU FFC2H ; PORTB ADDRESS
PORTC EQU FFC4H ; PORTC ADDRESS
CWR EQU FFC6H ; CONTROL PORT ADDRESS
PHASEC EQU 03H
PHASEA EQU 09H ; SEQUENCE IN SERIES TO ROTATE MOTOR
PHASED EQU 0CH ; IN ANTICLOCKWISE DIRECTION
PHASEB EQU 06H

.CODE
START:
MOV AL,@DATA
MOV DX,CTL
OUT DX,AL
AGAIN:
MOV AL,PHASEC
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP:
LOOP UP

MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1

MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2

MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START


PROCEDURE:-
1. Connect power supply 5V & GND to both microprocessor trainer kit & Stepper motor interfacing kit.
2. Connect data bus between microprocessor trainer kit & Stepper motor interfacing kit.
3. Enter the program to rotate Stepper motor in clockwise & anticlockwise.
4. Execute the program by typing GO E000:00C0 ENTER for clockwise, GO E000:0030 ENTER for anticlockwise.
5. Observe the rotation of stepper motor.


You might be also interested in:
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI

Jan 17, 2008

Interfacing Digital-To-Analog converter to 8086 using 8255


  1. Assembly Language Program to generate Square Wave
  2. Assembly Language Program to generate Ramp Wave
  3. Assembly Language Program to generate Triangular Wave
  4. Assembly Language Program to generate Staircase Wave


AIM:-
To Interface Digital -to-Analog converter to 8086 using 8255 and write Assembly Language Program to generate Square Wave, Ramp Wave, Triangular Wave & Staircase Wave form.

APPARATUS:-
Microprocessor trainer kit, ADC kit, power supply, data cable, CRO etc

THEORY:-
The DAC 0800 is a monolithic 8 bit high speed current output digital to analog converters featuring setting time of 100nSEC. It also features high compliance complementary current outputs to allow differential output voltage of 20 Vp-p with simple resistor load and it can be operated both in unipolar and bipolar mode.

FEATURES:-
  1. Fast setting output current 100nS
  2. Full scale error +/- 1 LSB
  3. Complementary current outputs
  4. easy interface to all microprocessor
  5. Wide power supply range +/- 4.5 to +/- 18V
  6. low power consumption

WORKING:-
When chip select of DAC is enabled then DAC will convert digital input value given through portliness PB0-PB7 to analog value. The analog output from DAC is a current quantity. This current is converted to voltage using OPAMP based current-to-voltage converter. The voltage outputs (+/- 5V for bipolar 0 to 5V for unipolar mode) of OPAMP are connected to CRO to see the wave form.



; RAMP WAVE GENERATOR with 8086 using 8255
MODEL SMALL
.STACK 100
.DATA
CONTROL EQU 0FFC6H ; Control port address for 8255
PORTA EQU 0FFC0H ; Port A address for 8255
PORTB EQU 0FFC2H ; Port B address for 8255
PORTC EQU 0FFC4H ; Port C address for 8255
.CODE
START:
MOV AX,@DATA ;Initialize Data segment
MOV DS,AX
MOV DX,CONTROL
MOV AL,80H ;Initialize all ports as output
OUT DX,AL ;Ports

MOV BL,FFH ;Take FFH in BL analog equivalent to 5V
RAMP : MOV DX,PORTB
MOV AL,BL ;Copy to AL
OUT DX,AL ;And output it on the port
DEC BL ; To generate ramp wave this 5V is continuously decreased till 0V
JNZ RAMP ; Jump to RAMP if not 0
MOV BL,FFH ; To generate same wave this procedure is repeated
JMP RAMP
INT 03H
END START



;SQUARE WAVE GENERATOR with 8086 using 8255
MODEL SMALL
.STACK 100
.DATA
CONTROL EQU 0FFC6H ; Control port address for 8255
PORTA EQU 0FFC0H ; Port A address for 8255
PORTB EQU 0FFC2H ; Port B address for 8255
PORTC EQU 0FFC4H ; Port C address for 8255

.CODE
START:
MOV DX,CONTROL
MOV AL,80H ; Initialize all ports as output
OUT DX,AL ; Ports
UP: MOV DX,PORTB
MOV AL,00H ;Output 00 for 0V level
CALL OUTPUT
MOV AL,0FFH ;Output FF for 5V level
CALL OUTPUT
JMP UP
OUTPUT:
OUT DX,AL
CALL DELAY
INT 21H

DELAY:
MOV CX,0FFH ; To vary through frequency alter the delay count
LUP1 LOOP LUP1
INT 21H

END START


;TRIANGULAR WAVE GENERATOR with 8086 using 8255

MODEL SMALL
.STACK 100
.DATA
CONTROL EQU 0FFC6H ; Control port address for 8255
PORTA EQU 0FFC0H ; Port A address for 8255
PORTB EQU 0FFC2H ; Port B address for 8255
PORTC EQU 0FFC4H ; Port C address for 8255

.CODE
START:
MOV DX,CONTROL
MOV AL,80H ; Initialize all ports as output
OUT DX,AL ; Ports

BEGIN:
MOV DX,PORTB
MOV AL,00H ; Output 00 for 0V level
UP: CALL OUTPUT
INC AL ; To raise wave from 0V to 5V increment AL
CMP AL,00H
JNZ UP ; Jump UP till rising edge is reached i.e. 5V

MOV AL,0FFH
UP1: CALL OUTPUT
DEC AL ; To fall wave from 5V to 0V decrement AL
CMP AL,0FFH
JNZ UP1 ; Jump UP till falling edge is reached i.e. 0V
JMP BEGIN

OUTPUT:
OUT DX,AL
CALL DELAY
INT 21H

DELAY:
MOV CX,07H ;To vary the frequency alter the delay count
LUP1:LOOP LUP1
INT 21H

END START



;STAIRCASE WAVEFORM GENERATOR with 8086 using 8255

MODEL SMALL
.STACK 100
.DATA

CONTROL EQU 0FFC6H ; Control port address for 8255
PORTA EQU 0FFC0H ; Port A address for 8255
PORTB EQU 0FFC2H ; Port B address for 8255
PORTC EQU 0FFC4H ; Port C address for 8255

.CODE
START:
MOV DX,CONTROL
MOV AL,80H ;Initialize all ports as output
OUT DX,AL ;Ports

UP: MOV DX,PORTB
MOV AL,00H ;Output 00 for 0V level
CALL OUTPUT ; And wait for some time
MOV AL,0FFH ;Output FF for 5V level
CALL OUTPUT ; And wait for some time
MOV AL,07FH ;Output 7F for 2.5V level
CALL OUTPUT ; And wait for some time
JMP UP

OUTPUT: OUT DX,AL
MOV CX,FFH
DELAY: LOOP DELAY ; To add DELAY
INT 03H
END START

PROCEDURE:-
  1. Connect power supply 5V & GND to both microprocessor trainer kit & DAC interfacing kit.
  2. Connect data bus between microprocessor trainer kit & DAC interfacing kit.
  3. Enter the program to generate Ramp, Square, Triangular & Staircase Wave.
  4. Execute the program by typing GO E000:4770 ENTER for Ramp, GO E000:03A0 ENTER for Square, GO E000:0410 ENTER for Triangular, GO E000:4890 ENTER for Staircase.
  5. Observe the wave forms on CRO.
You might be also interested in:
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI

Jan 10, 2008

Analog-to-Digital converter with 8086 using 8255

AIM:- To Interface Analog-to-Digital converter to 8086 using 8255 and write Assembly Language Program to read Digital value from ADC.

APPARATUS:-
Microprocessor trainer kit, ADC kit, power supply, data cable etc

THEORY:

ANALOG TO DIGITAL CONVERTER (0809):-
The ADC-0809 data acquisition component is a monolithic CMOS device with an 8-bit analog to digital converter, 8 channel multiplexed control logic. The 8 bit A/D converter uses successive approximation as the converter technique. The converter features a high impedance chopper stabilized comparator, a 256R voltage divider with analog switch free and a successive approximation register. The 8 channel multiplexed can directly access any of 8 single ended analog signal.

FEATURES:-
  1. Resolution 8 bits
  2. Conversion time 100 micro sec.
  3. Single supply 5V
  4. 8 channel multiplexed with latched control logic
  5. easy interface to all microprocessor
  6. 0 to 5V analog input voltage range with single 5V supply
  7. low power consumption 15mW
  8. latched tristate output

WORKING:-
ADC interface consists of a NAND gate oscillator witch feeds 50 KHz as the input clock to ADC, input to channel is given through terminal blocks provided on the card. Channel selection is done using port lines PC0, PC1 & PC2, START OF CONVERSION and ALE is controlled by port line PC7. Converted digital output is read by ADC through PORTA lines by enabling OE. OE line is connected to port line PC6.
In this method of interfacing microprocessor is continuously monitoring EOC line (which is connected to port line PA7). When this goes high, make OE (PC6) high & then low, this will put the digital equivalent of analog voltage of the given channel on data lines of ADC. Read the digital data through port lines PA0 to PA7 and display the same data.


ASSEMBLY LANGUAGE PROGRAM:-
MODEL SMALL
.STACK 100
.DATA
CONTROL EQU FFC6H ; Control port address for 8255
PORTA EQU FFC0H ; Port A address for 8255
PORTB EQU FFC2H ; Port B address for 8255
PORTC EQU FFC4H ; Port C address for 8255
CHANNEL EQU 07H

.CODE
START:
MOV AL,90H ;CONTROL WORD FOR 8255
MOV DX,CONTROL ;TO INITIALIZE PORTA AS INPUT, PORTB AS OUTPUT
OUT DX,AL ;PORTC AS OUTPUT PORT
MOV AL,CHANNEL ; OUTPUT CHANNEL NUMBER IS PLACED ON
MOV DX,PORTC ; PC0, PC1, PC2 LINES OF 8255 WHICH ARE CONNECTED
OUT DX,AL ; TO ADC TO SELECT RESPECTIVE CHANNEL OF ADC TO
; TAKE ANALOG INPUT
MOV AL,0FH ; AS PC7 OF 8255 IS CONNECTED TO START OF
MOV DX,CONTROL ; CONVERSION (SOC) OF ADC SO TO START CONVERSION
OUT DX,AL ; PC7 IS SET HIGH
MOV CX,3FFFH
DELAY: LOOP DELAY

MOV AL,0EH ; RESET PC7
MOV DX,CONTROL
OUT DX,AL

MOV AL,0CH ; AS PC6 IS CONNECTED TO OE i.e. OUTPUT ENABLE OF
OUT DX,AL ; ADC SO TO DISABLE OE AND AND TO CHECK EOC
; (CONNECTED TO PA7) RESET PC6
UP: MOV DX,PORTA
IN AL,DX ; CHECK FOR EOC BY READING PORTA
AND AL,80H ; MASK PC7 BIT
CMP AL,80H ; COMPARE PC7 BIT WITH 1
JNZ UP ; IF EOC THEN READ DIGITAL VALUE FROM ADC

MOV AL,0DH
OUT DX,CONTROL ; TO CONFIGURE ADC TO OUTPUT THE DIGITAL DATA
OUT DX,AL ; SO SET OE (PC6) TO READ VALUE

MOV DX,PORTA ; READ DIGITAL DATA FROM PORTA
IN AL,DX ; DIGITAL DATA IS IN AL
INT 03H

END START



PROCEDURE:-
1. Connect power supply 5V & GND to both microprocessor trainer kit & ADC interfacing kit.
2. Connect data bus between microprocessor trainer kit & ADC interfacing kit.
3. Enter the program to read digital data from ADC.
4. Execute the program by typing GO E000:4610 ENTER.
5. “ENTER THE CHANNEL NUMBER “, will be displayed on screen.
6. Now enter the channel number and apply the analog input to respective channel.
7. Equivalent digital output is displayed on screen.

Analog input Digital output
1V 33H
2V 66H

3V 99H
4V CCH
5V FFH

You might be also interested in:
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI


Jan 5, 2008

Find Square Root of a hexadecimal number in assembly language

To write 8086 Assembly Language Program to Find Square Root of a hexadecimal number.

Answer:

; SQUARE ROOT OF A NUMBER
MODEL SMALL
.STACK 100
.DATA ; Data segment starts
NUM1 DW 0019H ; Initialize num1 to 0019
SQRT DW 01 DUP (?) ; Reserve 1 word of uninitialised data space to offset sqrt
.CODE ; Code segment starts
START:
MOV AX,@DATA ;Initialize data segment
MOV DS,AX
MOV AX,NUM1 ;Move the number(num1) to AX
XOR BX,BX ;XOR is performed and result is stored in BX
MOV BX,0001H ;Initialize BX to 0001H
MOV CX,0001H ;Initialize CX to 0001H
LOOP1: SUB AX,BX ;AX=AX-BX
JZ LOOP2 ; If zero flag is zero jump to loop2
INC CX ; Increment CX by 1
ADD BX,0002H ;BX=BX+0002H
JMP LOOP1 ; Jump to loop1
INC CX ; Increment CX by 1
LOOP2: MOV SQRT,CX ; Store result
INT 03H ; halt
END START




INPUT:
NUM1 = 0019 H (25 IN DECIMAL)
NUM1 = 0090 H (144 IN DECIMAL)
OUTPUT:
RES = 0005H
RES = 000CH


_________________________________________________________________

AIM: To write 8086 Assembly Language Program to Find Number of one’s & zero’s in a hexadecimal number.


Answer:

MODEL SMALL
.STACK 100
.DATA ; Data segment starts
NUM DW 0F0F0H ; Initialize num to F0F0 H
ONES DB ? ; Reserve 1 byte for storing number of zeros
ZEROS DB ? ; Reserve 1 byte for storing number of ones
.CODE ; Code segment starts
START:
MOV AX,@DATA ;Initialize DS
MOV DS,AX
MOV CL,10H ;Initialize CL to 10H
MOV BX,0000H ;Initialize BX to 0000H
MOV AX,NUM ;Move contents of num to AX
UP:
SHL AX,1 ;Shift the contents of AX left once
JC AHEAD ; If CF=1 jump to label ahead
INC BL ; Increment BL by 1
JMP DOWN ; Jump to the label down
AHEAD:
INC BH ; Increment BH by 1
DOWN:
DEC CL ; Decrement CL by 1
JNZ UP ; If zero flag is not 0 jump to label up
MOV ONES,BH ;Move contents of BH to ones
MOV ZEROS,BL ;Move contents of BL to zeros
INT 03H ; Halt
END START




INPUT:
NUM = 0F0F0 H (0000 1111 0000 1111 0000 b)

OUTPUT:
ONES = 08 H
ZEROS = 08 H






____________________________________________________________________





AIM: To write 8086 Assembly Language Program to Find Factorial of a hexadecimal number.

Answer:

; This ALP will find factorial from 01 H to 08 H

MODEL SMALL
.STACK 100
.DATA ; Data segment starts
NUM DW ?
RES DB 1H
FACT DW ?
.CODE ; Code segment starts
START:
MOV AX,@DATA ; Initialize DS
MOV DS,AX
MOV AH,01 ; Move 01 to AH to take input at runtime
INT 21H ; Dos interrupt
AND AX,000FH ; Logical AND of AX,000f and stores in AX
MOV NUM,AL ; Move contents of AL to val1
MOV CX,AL ; Move contents of AL to CL
MOV AX,RES ; Move contents of res(1) to AX
M:
MUL CX ; AX = AX*CX
LOOP M ; Decrements CX by 1 continues multiplication until CX is 0
MOV FACT,AX ; Value of AX is moved to fact
INT 03H ; Halt
END START





INPUT
8 (DURING RUNTIME)
OUTPUT:
FACT = D980 H










_________________________________________________________________





AIM: To write 8086 Assembly Language Program to Convert BCD to 7-Segment display using lookup table.

Answer:

MODEL SMALL
.STACK 100
.DATA ; Data segment starts and defines array A having
; Equivalent 7 segment codes

A DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH

C EQU 06 ; BCD number which is to be converted
7SEG DB ? ; 7 segment code
.CODE ; Code segment starts
START:
MOV AX,@DATA ; Initialize data segment
MOV DS,AX
MOV BX,OFFSET A ; Moves the starting address of A to BX
MOV AL,C ; Move C value to AL register
XLAT ; It i'll add [BX+AL] i.e. 0000 + 06 = 0006 H
MOV 7SEG,AL ; Store the result
INT 03H ; Halt
END START




INPUT:
C = 06 H
OUTPUT:
AL = 7D H

You might be also interested in:
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI
:: MASM 611 SOFTWARE
:: bit reversal and sorting programs

Jan 2, 2008

bit reversal and sorting programs [ assembly language ]

bit reversal and sorting programs [ assembly language ]

1)bit reversal(FOR 16 BIT)


MOV CX,0010 ;count=16 (16 bit)
MOV AX,[1100];16 bit input
MOV BX,0000;result
L1:SHL AX,01;each bit of input inserted into BX in opp direc
RCR BX,01
LOOP L1
MOV [2000],BX
HLT


2)program to sort an array in acending order
clc
mov cx,[3000h]
dec cx
l1: push cx
mov si,2000
l2:mov ax,[si]
mov bx,[si+2]
cmp bx,ax
jbe l3
xchg ax,bx
mov [si],ax
mov [si+2],bx
l3:inc si
inc si
loop l2
pop cx
loop l1
hlt

just replace 'jbe' by 'jae' to get the descending order program code...

You might be also interested in:
:: Interfacing Analog-to-Digital converter to 8086 using 8255
:: Interfacing Digital-To-Analog converter to 8086 using 8255
:: Temperature Control system using 8086
:: Traffic light control system using 8086

Jan 1, 2008

Assembly Language Programs to compute an expression

AIM: To write 8086 Assembly Language Program to compute Z = (A + B) × C × (D ÷ E).

Program

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

A DB 56H ; Initialize A to 56H

B DB 78H ; Initialize B to 78H

C DB 05H ; Initialize C to 05H

D DB 0ACH ; Initialize D to ACH

E DB 04H ; Initialize E to 04H

Z DW ? ; Declare Z



.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize DS

MOV DS,AX

MOV AL,A ;Move contents of A to AL

MOV BL,B ;Move contents of B to BL

ADD AL,BL ;AL = AL + BL

MOV CL,C ;Move contents of C to CL

MUL CL ; AL = AL×CL

MOV BX,AX ;Move contents of AX to BX

MOV AX,0000 ;Move 0000 to AX

MOV AL,D ;Move contents of D to AL

MOV CL,E ;Move contents of E to CL

DIV CL ; AL = AL ÷ CL

MUL BX ; AX = AX×BX

MOV Z[SI+2],AX ;Move contents of Z to AX

MOV Z[SI],DX ;Move contents of Z1 to DX

INT 03H ; Halt

END START


INPUT:

A = 56H

B =78H

C = 05H

D = 0ACH

E = 04H

OUTPUT:
Z = 0000 0AD02 H

AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi × Yi.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

X DB 1H, 2H, 3H ; Declare array of 3bytes named X

Y DB 4H, 5H, 6H ; Declare array of 3bytes named Y

Z DW ? ; Reserve 1word by name Z

.CODE ; Code segment starts

START:

MOV AX,@DATA ; Initialize DS

MOV DS,AX

MOV DX,0000H ;Initialize DX to 0000h

MOV BX,0000H ;Initialize BX to 0000h

MOV SI,0000H ;Initialize SI to 0000h

MOV CL,03H ;Initialize CL to 03h

UP:

MOV AL,X[BX] ;Move the elements of X to AL

MUL BYTE PTR Y[SI] ;Multiply AL with the contents of Y

ADD DX,AX ;DX=DX+AX+CF

INC BX ; Increment BX by 1

INC SI ; Increment SI by 1

DEC CL ; Decrement CL by 1

JNZ UP ; If zero flag is not zero jump to label up

MOV Z,DX ;Move the contents of DX to Z

INT 03H ; Halt

END START

INPUT:

X =1H, 2H, 3H

Y = 4H, 5H, 6H



OUTPUT:

Z = 0020 H


AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi2.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

X DB 0FFH, 0FFH, 0FFH ; Initialize X with 3bytes

Z DW ? ; Initialize Z

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize AX

MOV DS,AX

MOV DX,0000H ;Initialize DX to 0000h

MOV BX,0000H ;Initialize BX to 0000h

MOV CH,03H ;Initialize CH to 03h

MOV CL,00H ;Initialize CL to 00h

MOV DX,0000H ;Initialize DX to 0000h

MOV SI,0000H ;Initialize SI to 0000h

UP: MOV AL,X[BX] ;Move contents of X[BX] to AL

MUL BYTE PTR X[BX] ;Multiply AL with contents of X[BX]

ADD DX,AX ;DX=DX+AX

ADC CL,00H ;CL=CL+00+CF

INC BX ; Increment BX by 1

DEC CH ; Decrement CH by 1

JNZ UP ; If zero flag is not zero jump to up

MOV Z[SI],CX ;Move contents of CX to Z[SI]

MOV Z[SI+2],DX ;Move contents of DX to Z[SI+2]

INT 03H ; Halt

END START


INPUT:

Z = FF2 + FF2 + FF2 = 2FA03 H

X =FFH, FFH, FFH

OUTPUT:

Z = 0002 FA03 H

AIM: To write 8086 Assembly Language Program to compute Z = ∑ Xi3.

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

A DB 0FFH, 0FFH, 0FFH ; Initialize an array A

Z DW ?

.CODE ; Code segment starts

START:

MOV AX,@DATA ; Initialize the data segment

MOV DS,AX

MOV BX,0000H ; Initialize the BX register

MOV CX,03H ; CX register is decremented whenever loop instruction executes

MOV SI,00H ; Initialize SI & DI

MOV DI,0000H

UP: XOR AX,AX ; Clear AX register

MOV AL,A[SI] ;Move the element in array A pointed by SI to AL

MOV BX,AX ;Move AX register to BX

MUL AX ; Multiplies AX with AX

MUL BX ; Multiplies BX with AX and stores the result in DX:AX

ADD Z[DI+2],AX ; Adds lower 16 bits of z with AX

ADC Z[DI],DX ; Adds higher 16 bits of z with DX

ADD SI,01 ; Increment SI by 1

LOOP UP ; Goes up until CX becomes zero

INT 03H ; Halt

END START

INPUT:

Z = FF3 + FF3 + FF3 = 02F7 08FD H

ARRAY OF 3 NO'S (FFH, FFH, FFH)

OUTPUT:

Z = 02F7 08FD H

You might be also interested in:

:: MASM 611 SOFTWARE

:: Traffic light control system using 8086

:: Interfacing Stepper Motor to 8086 using 8255

Dec 29, 2007

Assembly Language Programs on strings

AIM: To write 8086 Assembly Language Program to compare two strings.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

STR1 DB 'FINAL YEAR EEE' ; Define string1 STR1

LEN DW ($-STR1) ; Variable LEN will have length of STR1

D DB 'EQUALS' ; Variable D points to string 'EQUALS'

F DB 'UNEQUALS' ; Variable F points to string 'UNEQUALS'

.EXTRA ; Extra segment starts

STR2 DB 'FINAL YEAR EEE' ; Define string2 STR2



.CODE ; Code segment starts

START:

MOV AX,@DATA

MOV DS,AX ; Initialize Data segment

MOV AX,@EXTRA

MOV ES,AX ; Initialize Extra segment

LEA SI,STR1 ;Lode effective address of STR1 in SI

LEA DI,STR2 ;Lode effective address of STR2 in DI

MOV CX,LEN ; Take length of string STR1 in CX register

CLD ; Clear Direction Flag

REP CMPSB ; Compare two strings till CX = 0 OR ZF ≠ 1

JNE NEXT ; Jump to NEXT if no ZF i.e. ZF = 0

LEA DX,D ; Lode effective address of string D in DX

JMP DISPLAY ; Jump to DICPLAY

NEXT:

LEA DX,F ; Lode effective address of string F in DX

DISPLAY:

MOV AH,09H ; Move 09 H in AH to display the string whose

INT 21H ; Effective address is in DX. DOS interrupt INT 21H

MOV AH,4CH ; Move 43 H in AH to terminate the program using

INT 21H ; Dos interrupt

END START


AIM: To write 8086 Assembly Language Program to add two arrays of hexadecimal
numbers using String Instructions.




Answer:



MODEL SMALL

.STACK 100

.DATA ; Data segment starts

A DB 35H, 36H, 37H, 38H ; Initialize array A

B DB 45H, 46H, 47H, 48H ; Initialize array B



.EXTRA ; Extra segment starts

Z DB ? ; Variable to store result Z



.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize data segment

MOV DS,AX

MOV AX,@EXTRA ;Initialize extra segment

MOV ES,AX

MOV BX,0000H ;Initialize BX register to zero

MOV CL,04H ;Initialize count register to no of array elements

MOV DI,OFFSET Z ;Move the offset of Z to DI

UP: MOV AL,A[BX] ;Points to the first no in 'A'

ADD AL,B[BX] ;Adds the nth number in array A with the nth number in

; Array B and stores the result in AL.

INC BX ; Increments the BX register

STOSB ; Stores the result obtained in ES:DI

DEC CL ; Decrement count register

JNZ UP ; Jump to the label up when ZF!=0

INT 03H ; Halt

END START

INPUT: TWO ARRAYS IN DATA SEGMENT

A DB 35H, 36H, 37H, 38H

B DB 45H, 46H, 47H, 48H



OUTPUT: AN ARRAY IN EXTRA SEGMENT

Z DB 7AH, 7CH, 7EH, 80H





AIM: To write 8086 Assembly Language Program to display number of character
present in a string.

Answer:

MODEL SMALL

.STACK 100

.DATA

CR EQU 0DH

LF EQU 0AH

LEN DB 04 DUP(0)

MSG1 DB 'ENTER THE STRING.INPUT=','$'

MSG2 DB CR,LF,'THE LENGTH OF THE STRING=','$'



DISP MACRO MSG ; Micro to display a string

MOV AH,09H

MOV DX,OFFSET MSG

INT 21H

ENDM



.CODE

START:

MOV AX,@DATA

MOV DS,AX

DISP MSG1

MOV CX,00H

READ: MOV AH,01H ; Take the input string at run time

INT 21H

CMP AL,CR ; Detect the end of the string

JE AHEAD

INC CX

JMP READ



AHEAD:DISP MSG2

MOV SI,OFFSET LEN

MOV AX,CX

CALL HEX2ASC

DISP LEN

INT 03H



HEX2ASC PROC NEAR ; Procedure to convert number of character in HEX to ASCII

MOV BX,0001H

MUL BX

AAM

OR AX,3030H

MOV [SI],AH

MOV [SI+1],AL

MOV AL,'$'

MOV [SI+2],AL

INT 03H

HEX2ASC ENDP

END START

INPUT: ENTER THE STRING

.INPUT = Microprocessor lab

OUTPUT: 'THE LENGTH OF THE STRING= 18


You might be also interested in:

:: Interfacing Digital-To-Analog converter to 8086 using 8255

:: MASM 611 SOFTWARE






Dec 21, 2007

Assembly Language Programs on array of Hexadecimal numbers

AIM: To write 8086 Assembly Language Program to sorting n-hexadecimal number in ascending order.

Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 53H, 25H, 02H, 19H ; Array (list) containing 4 elements is initialized.

COUNT EQU 04 ; Count is initialized to 4

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize the data segment

MOV DS,AX

MOV DX,COUNT-1 ;Move 03(count-1) to DX register

LOOP0: MOV CX,DX ;Move the contents of DX to CX register

MOV SI,OFFSET LIST ;Move the pointer variable of array(list) to SI

LOOP1: MOV AX,[SI] ;Move the contents of array pointed by SI to AX register

CMP AX,[SI+2] ;Compare the contents of array pointed by SI and SI+2

JL PR1 ; Transfers the control to PR1 if OF & SF are SET i.e. if 1st no<2nd style="font-size:130%;">

AIM: To write 8086 Assembly Language Program to sorting n-hexadecimal number in descending order.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 53H, 25H, 02H, 19H ; Array (list) containing 4 elements is initialized.

COUNT EQU 04 ; Count is initialized to 4

.CODE ; Code segment starts

START:

MOV AX,@DATA ;Initialize the data segment

MOV DS,AX

MOV DX,COUNT-1 ;Move 03(count-1) to DX register

LOOP0: MOV CX,DX ;Move the contents of DX to CX register

MOV SI,OFFSET LIST ;Move the pointer variable of array(list) to SI

LOOP1: MOV AX,[SI] ;Move the contents of array pointed by SI to AX register

CMP AX,[SI+2] ;Compare the contents of array pointed by SI and SI+2

JG PR1 ; Transfers the control to pr1 if OF & SF

; are RESET i.e. if 1st no>2nd no.

XCHG [SI+2],AX ;Exchanges the contents of AX with [SI+2]

XCHG [SI],AX ;Exchanges the contents of AX with [SI]

PR1: ADD SI,02 ;Increments SI by 2

LOOP LOOP1 ; Control passes to LOOP1

DEC DX ; Decrement DX register

JNZ LOOP0 ; Jump to LOOP0 if CX! = 0

INT 03H

END START

INPUT:

LIST 53H, 25H, 02H, 19H

OUTPUT:

SORTED ARRAY OF THE INPUT

53H, 25H, 19H, 02H


AIM: To write 8086 Assembly Language Program to find Number of Positive & Negative hexadecimal numbers in an array.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 2345H, 4567H, 8125H, 0A120H ; Initialize an array (LIST) of 16bit

COUNT EQU 04 ; Initialize count variable

.CODE ; Code segment starts

START:

XOR BX,BX ; Clear the contents of BX register

XOR DX,DX ; Clear the contents of DX register

MOV AX,@DATA ; Initialize data segment

MOV DS,AX

MOV CL,COUNT ;Move count to CL register

MOV SI,OFFSET LIST ;Offset of array is moved to SI

LOOP1: MOV AX,[SI] ;The contents of array pointed by SI are moved to AX

SHL AX,01 ;After SHL, the MSB will contain the SIGN FLAG

JC NEG1 ; Jump on no carry to NEG1

INC BX ; Increment BX register

JMP NEXT ; Jump to NEXT

NEG1: INC DX ; Increment DX register

NEXT: ADD SI,02 ;Increment SI by 2

DEC CL ; Decrement CL by 1

JNZ LOOP1 ; Jump to loop1 if ZF! = 0

INT 03H

END START

INPUT:

ARRAY OF 16BITS

LIST DW 2345H, 4567H, 8125H, 0A120H

OUTPUT:

BX register gives the no of positive numbers in the given array (LIST)

DX register gives the no of negative numbers in the given array (LIST)

AIM: To write 8086 Assembly Language Program to find Number of Even & Odd hexadecimal numbers in an array.


Answer:

MODEL SMALL

.STACK 100

.DATA ; Data segment starts

LIST DW 2345 H, 4567 H, 8125 H, 0A120 H, 6742 H ; Initialize an array (LIST) of 16bit

COUNT EQU 05 ; Initialize count variable

.CODE ; Code segment starts

START:

XOR BX,BX ;Clear the contents of BX register

XOR DX,DX ;Clear the contents of DX register

MOV AX,@DATA ;Initialize data segment

MOV DS,AX

MOV CL,COUNT ;Move count to CL register

MOV SI,OFFSET LIST ;Offset of array is moved to SI

LOOP1: MOV AX,[SI] ;The contents of array pointed by SI are moved to AX

ROR AX,01 ;After ROR, the LSB specifies if the no is even/odd

JC ODD ;Jump on no carry to ODD

INC BX ; Increment BX register

JMP NEXT ; Jump to next

ODD: INC DX ; Increment DX register

NEXT: ADD SI,02 ;Increment SI by 2

DEC CL ; Decrement CL by 1

JNZ LOOP1 ; Jump to loop1 if ZF! = 0

INT 03H

END START

INPUT: ARRAY OF 16-BITS

LIST DW 2345H, 4567H, 8125H, 0A120H

OUTPUT:

BX register gives the no of odd numbers in the given array (LIST)

DX register gives the no of odd numbers in the given array (LIST)

You might be also interested in:
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI

Dec 14, 2007

Assembly Language Programs for Multiplication and Division

this part has following programs 5 programmes



1) To write 8086 Assembly Language Program to Multiply two unsigned number.


MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
A DW 0FF87H ; First signed number A = (-79H) = FF87H (2'Compliment form)
B DW 0FF84H ; Second signed number B = (-7CH) = FF84H (2'Compliment form)
C DW ? ; Variable C to store result

.CODE
START:
MOV AX,@DATA
MOV DS,AX ; Initialize data segment
MOV SI,0000H ; Initialize SI to 0000H
MOV AX,A ;Take first number A in AX register
MOV CX,B ;Take second number B in CX register
MUL CX ; Performs unsigned Multiplication DX:AX = AX × CX
MOV C[SI],DX ; Store higher 16-bit result
MOV C[SI+2],AX ; Store lower 16-bit result
INT 03H

END START

Input:
FF87 × FF84 = FF0B 3A9C H
A = 0FF87 H (2'compliment of -79H)
B = 0FF84 H (2'compliment of -7CH)

Output:
C = FF0B 3A9C H


2) To write 8086 Assembly Language Program to multiply two signed number.


MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
A DW 0FF87H ; First signed number A = (-79H) = FF87H (2'Compliment form)
B DW 0FF84H ; Second signed number B = (-7CH) = FF84H (2'Compliment form)
C DW ? ; Variable C to store result

.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV AX,A ;Take first number A in AX register
MOV CX,B ;Take second number B in CX register
IMUL CX ; Performs signed Multiplication DX:AX = AX × CX
MOV C[SI],DX ;Store higher 16-bit result
MOV C[SI+2],AX ;Store lower 16-bit result
INT 03H

END START




Input:
-79 × -7C = 3A9C H
A = 0FF87 H (2'compliment of -79H)
B = 0FF84 H (2'compliment of -7CH)

Output:
C = 0000 3A9C H


3) To write 8086 Assembly Language Program to multiply two 32-bit unsigned numbers.


MODEL SMALL
.STACK 100
.DATA ; Data segment starts
A DW 5678H, 1234H, 5 DUP(0) ;A is 32bit number A=1234 5678
b DW 1111H, 1111H, 5 DUP(0) ;B is 32bit number B=1111 1111
C DW 4 DUP(?) ; Reserve 4 words of uninitialized data space to an offset C
.CODE
START:
MOV AX,@DATA ;Initialize DS
MOV DS,AX
MOV SI,OFFSET A ;Point to first number in A

MOV AX,WORD PTR A[SI] ;Take lower 16bits(5678) of A into AX
MUL WORD PTR B[BX+0] ;Multiply AX with lower 16bits of B(1111) and store in AX
MOV C[DI],AX ;Move the contents of AX to C[DI]
MOV CX,DX ;Move the value of DX to CX

MOV AX,WORD PTR A[SI+2] ;Take higher 16bits(1234) of A into AX
MUL WORD PTR B[BX+0] ;Multiply AX with lower 16bits of B(1111)and store in AX
ADD CX,AX ;CX=CX+AX
MOV C[DI+2],CX ;Move the contents of CX to C[DI+2]
MOV CX,DX ;Move contents of DX to CX

MOV AX,WORD PTR A[SI] ;Take lower 16bits(5678) of A in AX
MUL WORD PTR B[BX+2] ;Multiply contents of AX with higher 16bits of B(1111)
ADD WORD PTR C[DI+2],AX ;C[DI+2]=C[DI+2]+AX
ADC CX,DX ;CX=CX+DX+CF
MOV C[DI+4],AX ;Move contents of AX to C[DI+4]

MOV AX,WORD PTR A[SI+2] ;Take higher 16bits of A(1234) into AX
MUL WORD PTR B[BX+2] ;Multiply AX with higher 16bits of B(1111) and store in AX
ADD CX,AX ;CX=CX+AX
MOV WORD PTR C[DI+4],CX ;Move contents of CX to C[DI+4]
ADC DX,0000 ;DX=DX+0000+CF
MOV C[DI+6],DX ;Move the contents of DX to C[DI+6]

INT 03H ; Halt

END START


INPUT
A = 1234 5678 H
B = 1111 1111 H

OUTPUT
C=0136 BO6E 652F B5F8 H


4) To write 8086 Assembly Language Program to Division two unsigned number.


MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
Dividend DW 1234H, 5678H ; Dividend = 1234 5678 H
Divisor DW 270FH ; Divisor = 207FH
Quotient DW ? ; Variable Quotient to store Quotient
Reminder DW ? ; Variable Reminder to store Reminder

.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV DX,Dividend[SI] ;Take higher 16-bit number which is to be divided in DX register
MOV AX,Dividend[SI+2] ;Take lower 16-bit number which is to be divided in AX register
MOV CX,Divisor ;Take divisor in CX register
DIV CX ; Performs unsigned Division DX:AX ÷CX
; AX = Quotient DX = Reminder
MOV Reminder,DX ;Store Reminder
MOV Quotient,AX ;Store Quotient
INT 03H
END START




Input:
12345678H ÷ 207FH = 7751H
Dividend = 1234 5678 H
Divisor = 207F H

Output:
Quotient = 7751 H
Reminder = 01B9 H


5) To write 8086 Assembly Language Program to Division two signed number.


MODEL SMALL
.STACK 100
.DATA ; Data Segment to initialize the variables
Dividend DW 0FFFFH, 0FF88H ; Dividend = (-78H) = FFFF FF88H (2'Compliment form)
Divisor DW 0006H ; Divisor = 0006H
Quotient DW ? ; Variable Quotient to store Quotient
Reminder DW ? ; Variable Reminder to store Reminder

.CODE
START:
MOV AX,@DATA
MOV DS,AX ;Initialize data segment
MOV SI,0000H ;Initialize SI to 0000H
MOV DX,Dividend[SI] ;Take higher 16-bit number which is to be divided in DX register
MOV AX,Dividend[SI+2] ;Take lower 16-bit number which is to be divided in AX register
MOV CX,Divisor ;Take divisor in CX register
IDIV CX ; Performs signed Division DX:AX ÷ CX
; AX = Quotient DX = Reminder
MOV Reminder,DX ;Store Reminder
MOV Quotient,AX ;Store Quotient
INT 03H

END START




Input:
-78H ÷ 06H = -14H
Dividend = FFFF FF87 H (32-bit 2'compliment of -78H)
Divisor = 0006 H

Output:
Quotient = FFEC H (2'compliment of -14H)
Reminder = 0000 H

You might be also interested in:
:: Assembly Language Programs on array of Hexadecimal numbers
:: Assembly Language Programs on strings







Dec 7, 2007

List of all the experiments to be written

T are all the list of Assembly Language Programs that are to be discussed in the future blog posts.

:: Assembly Language Programs for Addition and Subtraction
:: Assembly Language Programs for Multiplication and Division
:: Assembly Language Programs on array of Hexadecimal numbers
:: Assembly Language Programs on strings
:: Assembly Language Programs to compute an expression
:: Interfacing Analog-to-Digital converter to 8086 using 8255
:: Interfacing Digital-To-Analog converter to 8086 using 8255
:: Temperature Control system using 8086
:: Traffic light control system using 8086
:: Assembly Language Program to serve NMI
:: Interfacing Stepper Motor to 8086 using 8255
:: MASM 611 SOFTWARE
:: bit reversal and sorting programs
:: Find Square Root of a hexadecimal number in assembly language
:: common intreview questions on 8086
:: Assembly Language Source Codes
:: why there are two ground pins in 8086
:: Program to display ASCII characters on the display unit
:: 8051 based project for electrical students
:: free and open source 8086 Microprocessor Emulator
:: Invoke function
:: Troubleshooting a simple 8086 microprocessor based microcomputer
:: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language
:: Data transfer instructions of 8086 microprocessor
:: 8085 Microprocessor simulator for linux
::Interfacing pic microcontroller with LCD
:: Serial Port interfacing with atmega
:: TCP/IP on PIC 18 series
:: assembly program to find out the largest number from an unordered array
:: Program to find out the number of even and odd numbers from a given series
:: assembly Program to create , write and close file
:: Operator Precedence
:: 8051 or PIC microcontroller which is better
:: Effective addresses
:: Floating Point Initializations
:: options available for int 21h instruction
:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing
:: How to add two binary numbers without carry
::How to choose a MicroController
:: How to add two Hexa decimal numbers without carry
:: Adding two hexa-decimal numbers with carry


These programs are tested on masm611.