8086 Programs
8086 Programs
8086 Programs
Writing an ALP
Assembly level programs generally abbreviated as ALP are written in text editor
EDIT.
Type EDIT in front of the command prompt to open an untitled text file.
EDIT<file name>
After typing the program save the file with appropriate file name with an
extension .ASM
Ex:
Add.ASM
Assembling an ALP
MASM<filename.ASM>
If the program is free from all syntactical errors, this command will give the OBJECT
file.In
case of errors it list out the number of errors, warnings and kind of error.
Linking
The command is
LINK<File name.OBJ>
prompt.
command.
CV <Filename.exe>
This will open the program in debugger screen where in you can view the
assemble code
with the CS and IP values at the left most side and the machine code. Register
content
Execute option in the menu in the menu can be used to execute the program
either in
DATA SEGMENT
DATA1 DB 23H
DATA2 DW 1234H
DATA3 DB 0H
DATA4 DW 0H
DATA5 DW 2345H,6789H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
;(16 bit)
INT 21H
END START
- 5 - ii)Block move (with and with out overlapping)
Without overlapping
DATA SEGMENT
Y DB 05 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
Before execution
00
00
00
00
00
05
04
03
02
01
After execution
05
04
03
02
01
05
04
03
02
01
Y,DI
X, SI
- 6 - With Overlapping
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
DEC DI
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
DS Before execution
xx
xx
xx
xx
xx
05
04
03
02
01
DI
SI
DS After execution
xx
xx
05
04
03
- 7 - 02
01
03
02
01
DATA SEGMENT
X DB 01H,02H,03H,04H,05H
Y DB 11H,12H,13H,14H,15H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
INC DI
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
DS Before execution
15
14
13
12
11
05
04
03
02
01
Y,DI
X, SI
- 9 - DS After execution
05
04
03
02
01
15
14
13
12
11
i ) 16 Bit Addition
DATA SEGMENT
NUM DW 1234H, 0F234H
SUM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT : 10468H
- 11
DATA SEGMENT
NUM1 DW 0FFFFH,0FFFFH
NUM2 DW 1111H,1111H
SUM DW 4 DUP(0)
dATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,NUM1
ADD AX,NUM2
MOV SUM,AX
MOV AX,NUM1+2
ADC AX,NUM2+2
MOV SUM+4,01H
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: 0111111110H
DATA SEGMENT
NUM1 DW 12345678H
NUM2 DW 12345678H
SUM DW 3 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
MOV DS,AX
ADD AX,[DI]
MOV CX,[SI+2]
; Add DI content to AX
;content to CX
;with carry to CX
MOV AH,4CH
INT 21H
CODE ENDS
END START
INOUT: 12345678H,12345678H
OUTPUT:2468ACF0H
- 13 - iv) 16 Bit Subtraction
DATA SEGMENT
NUM DW 4567H,2345H
DIF DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME
CS:CODE,DS:DATA
CLC
; Clearing Carry
;Number subtraction)
MOV AH,4CH
INT 21H
CODE ENDS
END START
INPUT: 4567H,2345H
OUTPUT:2222
- 14 - v) 32 Bit Subtraction
DATA SEGMENT
NUM1 DW 2345H,6762H
NUM2 DW 1111H,1111H
DIF DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
LEA SI,NUM1
LEA DI,NUM2
MOV AX,[SI]
MOV BX,[DI]
SUB AX,BX
MOV DIF,AX
INC SI
; Subtract from BX to AX
INC SI
INC DI
INC DI
MOV AX,[SI]
MOV BX,[DI]
MOV DIF+2,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
INPUT: 23456762,-11111111
OUTPUT:12345651
INPUT:11111111,-23451234
OUTPUT:EDCBFEDD
DATA SEGMENT
NUM DW 1234H,1234H
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV PROD+2,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Multiplier - 1234H
OUTPUT: DX-01 4B
AX-54 90
DATA SEGMENT
NUM DW -2,1
PROD DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV PROD+2,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Multiplier - 1
OUTPUT: DX FF FF
DATA SEGMENT
NUM1 DB 72H,
NUM2 DB 02H
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AH,0H
DIV NUM2
; Zero extended for 16 bit/8 bit division
MOV AH,4CH
INT 21H
CODE ENDS
END START
Divisor - 02 H,
AX - 00H (reminder);
Divisor - 04 H,
AX - 01H (reminder);
- 18 - ix)8 Bit Division for Signed numbers
DATA SEGMENT
NUM1 DB -10
NUM2 DB 02
QUO DB 1 DUP(0)
REM DB 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
CBW
IDIV NUM2 ; Perform the Sign Division operation using IDIV operator
INT 21H
CODE ENDS
END START
Divisor - 02
Divisor - 03
DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV DX,NUM1+2
DIV NUM2
MOV QUO,AX
MOV REM,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Divisor - 4111,
DX 0952H (reminder);
DATA SEGMENT
NUM1 DW 4567H,2345H
NUM2 DW 4111H
QUO DW 2 DUP(0)
REM DW 1 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV DX,NUM1+2
CWD
IDIV NUM2
MOV QUO,AX
MOV REM,DX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Divisor - 2222,
0UTPUT: AX FE (quotient);
DX FF (reminder)
- 21 - 3.Code Conversion
CODE SEGMENT
ASSUME CS:CODE
MUL CL ;AX=0019H
AAS ;AX=0007
AX,3030H ;AX=3037H
MOV AH,4CH
INT 21H
CODE ENDS
END START
- 22 - ii)Binary to BCD code conversion
DATA SEGMENT
BIN DW 01A9H
BCD DB 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,BIN
MOV CL,64H
DIV CL
MOV BCD+1,AL
MOV AL,AH
MOV AH,00H
MOV CL,0AH
DIV CL
MOV CL,04
ROR AL,CL
ADD AL,AH
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: binary--------01A9
Output: bcd------------425
;100 in decimal
;10 in decimal.
DATA SEGMENT
BCD DW 27H
BIN DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,BCD
AND AX,07H
MOV BX,AX
MOV AX,BCD
AND AX,0F0H
MOV CX,0AH
MUL CX
ADD AX,BX
MOV BIN,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: BCD-------------27
Output:------------------1B
;Move data AX to BX
;10 in decimal.
DATA SEGMENT
X DW 04H
SQUARE DW ?
CUBE DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,X
MOV BX,X
MUL BX
MOV SQUARE,AX
MUL BX
MOV CUBE,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: x ----------- 4h
Cube -----------40h
DATA SEGMENT
NUM DW 05,04
LCM DW 2 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV DX,0H
MOV AX,NUM
MOV BX,NUM+2
UP: PUSH AX
PUSH DX
DIV BX
CMP DX,0
JE EXIT
POP DX
POP AX
ADD AX,NUM
JNC DOWN
INC DX
DOWN: JMP UP
POP LCM
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 0A, 04
Output: 02
;Increment DX.
;Jump to Up label.
DATA SEGMENT
NUM1 DW 000AH
NUM2 DW 0004H
GCD DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,NUM1
MOV BX,NUM2
JE EXIT
JB EXCG
UP1:MOV DX,0H
DIV BX
CMP DX,0
JE EXIT
MOV AX,DX
JMP UP
EXCG:XCHG AX,BX
JMP UP1
EXIT:MOV GCD,BX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 0A,04
Output: 02
;Jump to UP label.
;Jump to UP1.
DATA SEGMENT
X DW 06H
FACT DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AX,01H
MOV CX,X
UP: MUL CX
LOOP UP
MOV FACT,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
Input: 06
Output: 2D0H
DATA SEGMENT
NUM DB 12H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AL,NUM
ROL AL,1
JC NEGA
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
DATA SEGMENT
X DW 27H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,X
TEST AX,01H
JNZ EXIT
LEA DX,MSG1
MOV AH,09H
INT 21H
JMP LAST
;(alternate logic)
;MOV BL,2
;DIV BL
;CMP AH,0H
;JNZ EXIT
MOV AH,09H
INT 21H
INT 21H
CODE ENDS
END START
DATA SEGMENT
X DB 0AAH
ONE DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AH,X
MOV BL,8
MOV CL,1
JNC DOWN
INC ONE
JMP DOWN1
DOWN1: DEC BL
JNZ UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
Output: Ones--------04
Zeros--------04
;Initialize BL to 8.
;Initialize CL to 1.
;Increment one.
;Jump to DOWN1.
;Increment ZERO.
DATA SEGMENT
X DW 82H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,X
MOV BX,0H
AND AX,0E0H
JNZ DISP
MOV CL,05
MOV AX,X
JNC DOWN
INC BX
DOWN:DEC C
JNC UP
CMP BX,02H
JNZ DISP
LEA DX,MES
MOV AH,09H
INT 21H
JMP EXIT
MOV AH,09H
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
;If zero, Initialize the counter for check the last 5 bit.
DATA SEGMENT
X DW 0FFFFH
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,X
MOV CL,10H
RCL DX,1
LOOP UP
CMP AX,DX
JNZ DOWN
LEA DX,MSG1
MOV AH,09H
INT 21H
JMP EXIT
MOV AH,09H
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
;Move DW to AX.
;Declare as a PALINDROME.
DATA SEGMENT
X DW 2662H
TEMP DW 0H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV AX,X
MOV BX,X
MOV CL,04
AND AX,0000FH
AND BX,0F000H
ROL BX,CL
CMP AX,BX
JNZ TER
MOV AX,X
ROR AX,CL
MOV BX,AX
AND AX,000FH
ROR BX,CL
AND BX,000FH
CMP AX,BX
JNZ TER
MOV AH,09H
LEA DX,MES
INT 21H
JMP LAST
TER:MOV AH,09H
LEA DX,MES1
INT 21H
LAST:MOV AH,4CH
INT 21H
CODE ENDS
END START
;Initialize counter.
;Move AX to BX.
;Declared as a PALINDROME.
palindrome
- 34 - 6. PROGRAMS INVOLVING BRANCH/LOOP INSTRUCTIONS /
PROGRAMS ON
ARRAYS
i)ADDITION OF n NUMBERS
ARR DW 0010H,0020H,0030H,0040H,0050H
SUM DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
LEA SI,ARR
CLC
XOR AX,AX
MOV CX,LEN
INC SI
INC SI
DEC CX
JNZ UP
MOV SUM,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: 00F0
;clear carry
;clear AX register
ARR
;add
the
numbe
pointe
d by SI
to A
registe
;decrement Cx
if no then add
;store the addition result in user
DATA SEGMENT
ARR DW 50H,10H,20H,10H,05H
DIF DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
LEA SI,ARR
CLC
MOV CX,LEN-1
MOV AX,[SI]
INC SI
INC SI
DEC CX
JNZ UP
MOV DIF,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: 0005
- 36 -
pointed by SI in AX
;decrement CX
DATA SEGMENT
X DW 0010H,52H,30H,40H,50H
LAR DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
MOV AX,[SI]
DEC CX
JA CONTINUE
MOV AX,[SI+2]
CONTINUE:ADD SI,2
DEC CX
JNZ UP
MOV LAR,AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
in X
AX
AX
compared
INTERRUPTS
DATA SEGMENT
X DW 0010H,0052H,0030H,0040H,0050H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
MOV AX,[SI]
DEC CX
JA CONTINUE
MOV AX,[SI+2]
CONTINUE:ADD SI,2
DEC CX
JNZ UP
AAM
ADD AX,3030H
MOV BX,AX
MOV AX,09H
LEA DX,MES
INT 21H
MOV DL,BH
MOV AH,02H
INT 21H
MOV DL,BL
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
array X
number in AX
contents of AX
;make a copy of it in AX
DATA SEGMENT
X DW 0060H,0020H,0030H,0040H,0050H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV DS,AX
MOV CX,05H
LEA SI,X
MOV AX,[SI]
DEC CX
JB CONTINUE
MOV AX,[SI+2]
CONTINUE:ADD SI,2
DEC CX
JNZ UP
AAM
ADD AX,3030H
MOV BX,AX
MOV AH,09H
LEA DX,MES
INT 21H
MOV DL,BH
MOV AH,02H
INT 21H
- 39 -
datawords in array X
in array X
number in AX
by SI+2
AX
number in AX
compared if no continue
comparison
ASCII in BX
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
DATA SEGMENT
x DW 42H,34H,26H,17H,09H
LEN EQU 05
ASCD DB 10 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV BX,LEN-1
MOV CX,BX
LEA SI,X
MOV DX,[SI+2]
CMP AX,DX
JB DOWN/JA DOWN
MOV [SI],DX
MOV [SI+2],AX
DOWN: INC SI
INC SI
DEC BX
JNZ UP
DEC CX
JNZ UP1
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: 09 17 26 34 42
AX
;decrement counter2
ascending order
DATA SEGMENT
STR2 DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2
MOV CX,LEN
CLD
REP MOVSB
MOV AH,4CH
INT 21H
CODE ENDS
END START
;STR1
;and DI
;decremented)
DATA SEGMENT
STR1 DB 'HELLO'
STR2 DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD
LODSB
STD
STOSB
LOOP UP
MOV AH,4CH
INT 21H
CODE ENDS
END START
OUTPUT: OLLEH
at STR1
register
register
pointed by DI
CX is zero
DATA SEGMENT
MSG DB 'HELLO'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
MOV DS,AX
MOV ES,AX
LEA SI,MSG
MOV AL,SRC
MOV CL,CNT
MOV CH,00H
CLD
UP: SCASB
JZ DOWN
LOOP UP
LEA DX,MSG2
MOV AH,09H
INT 21H
JMP EXIT
the string
string is stored in AL
MOV AH,09H
INT 21H
INT 21H
CODE ENDS
END START
DATA SEGMENT
STR1 DB 'LIRIL'
STR2 DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
MOV DS,AX
MOV ES,AX
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD
LODSB
STD
STOSB
LOOP UP
LEA SI,STR1
LEA DI,STR2
CLD
MOV CX,LEN
REPE CMPSB
CMP CX,0H
JNZ NOTPALIN
LEA DX,MES1
MOV AH,09H
- 45
operations
string
auto increment SI
auto decrement DI
pointed by DI
original string
palindrome
and DI
palindrome)
JMP EXIT
MOV AH,09H
INT 21H
CODE ENDS
END START
- 46 -
interrupts
;end of code
segment 7.1.Program to use DOS interrupt INT 21H function called for
reading a character from
DATA SEGMENT
INKEY DB ?
BUF DB 20 DUP(0)
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AH,01H
INT 21H
MOV BUF,10
MOV AH,0AH
LEA DX,BUF
INT 21H
MOV AH,06H
MOV DL,'A'
INT 21H
MOV AH,09H
LEA DX,MES
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
;keyboard.
;keyboard.
DATA SEGMENT
FILENAME DB'HELLO.NEW'
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV AH,3CH
MOV CX,0
;new file
CODE
ENDS
END START
;filename
INT 21H
- 48 - 3.Writing to a file
DATA SEGMENT
FILENAME DB 'HELLO.NEW'
BUFFER DB 22 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
ERROR:
EXIT:
CODE ENDS
END START
MOV AX,DATA
MOV DS,AX
MOV AH,09H
LEA DX,MES
INT 21H
MOV BUFFER,20
MOV AH,0AH
INT 21H
MOV AH,3CH
MOV CX,0
MOV DX,OFFSET FILENAME
INT 21H
MOV BX,AX
MOV CX,20
INT 21H
JC ERROR
JMP EXIT
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
YY DB
MM DB
D DB
TDAY DW UN,MON,TUE,WED,THU,FRI,SAT
SUN DB'SUNDAY,$'
MON DB'MONDAY,$'
TUE DB'TUESDAY,$'
WED DB'WEDNESDAY,$'
THU DB'THURSDAY,$'
FRI DB FRIDAY,$'
SAT DB'SATURDAY,$'
TMON DW JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC
JAN DB'JANUARY,$'
FEB DB'FEBRUARY,$'
MAR DB'MARCH,$'
APR DB'APRIL,$'
MAY DB'MAY,$'
JUN DB'JUNE,$'
JUL DB'JULY,$'
AUG DB'AUGUST,$'
SEP DB'SEPTEMBER,$'
OCT DB'OCTOBER,$'
NOV DB'NOVEMBER,$'
DEC DB'DECEMBER,$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
PUSH AX
PUSH DX
MOV DL,CHAR
MOV AH,02
INT 21H
POP DX
POP AX
ENDM
MOV DX,AX
CALL PDATE
- 50 - MOV AH,4CHH
INT 21H
MOV AH,2AH
INT21H
MOV YY,CX
MOV MM,DH
MOV D,DL
MOV AH,0
ROL AX,1
ADD SI,AX
MOV DX,[SI]
MOV AH,09H
INT21H
MOV AL,D
MOV AH,00H
AAM
OR AH,AH
JZ DIGIT0
ADD AH,30H
DISCHAR AH
DIGIT0:
DIS19:
ADD AL,30H
DISCHAR AL
DISCHAR ''
MOV AL,MM
SUB AL,1
MOV AH,0
ROL AX,1
ADD SI,AX
MOV DX,[SI]
MOV AH,09H
INT21H
MOV AX,YY
CMP AX,2000
JB DIS19
SUB AX,2000
DISCHAR'2'
DISCHAR'0'
JMP SKIP
SUB AX,1900
DICHAR'1'
DISCHAR'9'
- 51 - SKIP: AAM
ADD AX,3030H
DISCHAR AH
DISCHAR AL
RET
PDATE ENDP
CODE ENDS
END START
DATA SEGMENT
MES1 DB 10,13,"DATE:$"
BUFF DB 10 DUP(0)
DB 0
DB 10 DUP(0)
YY DB ?
MM DB ?
D DB ?
DATA ENDS
CODE SEGMENT
MOV DS,AX
CALL DATEP
MOV AH,4CH
INT 21H
MOV AH,09H
LEA DX,MES
INT 21H
MOV AH,09H
LEA DX,MES1
INT 21H
MOV AH,0AH
LEA DX,BUFF
INT 21H
MOV CL,04
MOV DL,0H
LEA SI,BUFF
ADD SI,02
CMP AL,':'
JZ TER
ROL DL,CL
SUB AL,30H
- 53 - TER:
BACK1:
TER1:
BACK2:
TER2:
ADD DL,AL
INC SI
JMP BACK
MOV DH,DL
ADD DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV DH,AL
MOV DL,0
INC SI
MOV AL,[SI]
CMP AL,':'
JZ TER1
ROL DL,CL
SUB AL,30H
ADD DL,AL
INC SI
JMP BACK1
MOV DH,DL
AND DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV MM,AL
MOV DL,0
INC SI
MOV AL,[SI]
CMP AL,13
JZ TER2
ROL DL,CL
SUB AL,30H
ADD DL,AL
INC SI
JMP BACK2
MOV DH,DL
AND DL,0F0H
- 54 - ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,0DH
MOV YY,AL
MOV AH,2BH
MOV CL,YY
MOV CH,00
ADD CX,2000
MOV DH,MM
MOV DL,0DH
INT 21H
RET
DATEP ENDP
CODE ENDS
END START
DATA SEGMENT
HOUR DB ?
MIN DB ?
DATA ENDS
CODE SEGMENT
PUSH AX
PUSH DX
MOV DL,CHAR
MOV AH,02
INT 21H
POP DX
POP AX
ENDM
MOV DS,AX
CALL TIME
MOV AH,4CH
INT21H
INT21H
MOV HOUR,CH
MOV MIN,CL
CMP CH,12
JB DOWN
SUB CH,12
MOV AH,00H
AAM
MOV AX,3030H
DISCHAR AH
DISCHAR AL
DISCHAR:
MOV AL,CL
MOV AH,00H
AAM
- 56 - ADD AX,3030H
DISCHAR AH
DISCHAR AL
DISCHAR
CMP HOUR,12
JB AM
DISCHAR P
JMP DOWN1
AM: DISCHARA
DOWN1: DISCHARM
RET
TIME ENDP
CODE ENDS
END START
- 57 - 7.Set system time
DATA SEGMENT
FOLLOWED BY AM OR PM$
BUF DB 10
DB 0
DB 10 DUP(0)
HOUR DB?
MIN DB?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MOV DS,AX
CALL TIME
MOV AX,4CH
INT 21H
MOV AH,09H
LEA DX,MES
INT 21H
MOV AH,09H
LEA DX,MES1
INT 21H
MOV AH,0AH
LEA DX,BUF
INT 21H
MOV CL,4
MOV DL,00H
LEA SI,BUF
ADD SI,2
UP:
DOWN:
MOV AL,[SI]
CMP AL,:
JZ DOWN
ROL DL,CL
SUB AL,30H
ADD DL,AL
INC SI
JMP UP
MOV DH,DL
- 58 - UP1:
AND DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV HOUR,AL
MOV DL,0
INC SI
MOV AL,[SI]
CMP AL,
JZ DOWN1
ROL DL,CL
SUB AL,30H
ADD DL,AL
INC SI
JMP UP1
AND DL,0F0H
ROR DL,CL
MOV AL,10
MUL DL
AND DH,0FH
ADD AL,DH
MOV MIN,AL
INC SI
MOV CH,[SI]
CMP CH,P
JNZ SKIP
ADD HOUR,0CH
SKIP:
CODE ENDS
END START
MOV AH,2DH
MOV CH,HOUR
MOV CL,MINUTE
MOV CX,0000H
INT 21H
RET
TIME ENDP
- 59 - 8.INTERFACING EXPERIMENTS
DATA SEGMENT
ARRAY DB '0123456789.+-*/%ACK=MMMM'
DATA ENDS
CODE SEGMENT
MOV DX,CWRD
OUT DX,AL
REPEAT: MOV DX,PORTC ;make first row of the keyboard high through pc0
MOV AL,01
OUT DX,AL
MOV DX,PORTA
JZ NEXT
JMP FIRSTROW
NEXT: MOV DX,PORTC ;if key not found in first row, check if key is in
;second row
MOV AL,02
OUT DX,AL
MOV DX,PORTA
IN AL,DX
CMP AL,00
JNZ SECONDROW
MOV AL,04 ; if key not found then check for key closure in
;third row
MOV DX,PORTC
OUT DX,AL
MOV DX,PORTA
IN AL,DX
CMP AL,00H
JNZ THIRDROW
JMP REPEAT
FIRSTROW: CALL DELAY ;check all the keys one by onein first row
LEA SI,ARRAY
- 60 - UP: SHR AL,1
INC SI
JMP UP
JMP DISPLAY
SECONDROW:CALL DELAY
UP1:SHR AL,1
INC SI
JMP UP1
INC SI
JMP UP2
JMP DISPLAY
JZ EXIT
INT 21H
JMP REPEAT
DELAY:
L1:
L2:
CODE ENDS
END START
MOV BX,0FFFFH
MOV CX,0FFFH
DEC CX
JNZ L2
DEC BX
JNZ L1
RET
EXIT:MOV AH,4CH
INT 21H
2)SEVEN SEGMENT DISPLAY INTERFACE
- 61 - DATA SEGMENT
TABLE DB 8CH,0C7H,86H,89H
DATA ENDS
CODE SEGMENT
MOV DS,AX
MOV DX,CWRD
OUT DX,AL
MOV AL,[SI]
OUT DX,AL
MOV AL,01
OUT DX,AL
DEC AL
MOV DX,PORTC
OUT DX,AL
JNZ NEXTBIT
DEC BH
INC SI
JNZ NEXTDIGIT
INT 21H
CODE ENDS
END START
- 62 - 3) LOGICAL CONTROLLER INTERFACE
DATA SEGMENT
REGISTER
DATA ENDS
CODE SEGMENT
MOV DS, AX
MOV DX, CR
OUT DX,AX
IN AL,DX
CMP AL,00H
JZ DISPLAY
OUT DX,AL
JMP REPEAT
CODE ENDS
END START
OUT DX, AL
JMP REPEAT
- 63 -4)STEPPER MOTOR INTERFACE
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
UP:
DELAY:
UP2:
UP1:
CODE ENDS
MOV AX,DATA
MOV DS,AX
MOV DX,CWRD
OUT DX,AL
MOV DX,PORTA
CALL DELAY
ROL AL,01H ;rotate left to get exitation sequence of 11,22,44,88
OUT DX,AL
JMP UP
MOV BX,0FFH
DEC BX
JNZ UP1
DEC CX
JNZ UP2
RET
MOV AH,4CH
INT 21H
END START
VISVESWARAIAH TECHNOLOGICAL UNIVERSITY,BELGAUM
QUESTION BANK
PART A
1A) Write an ALP to show the byte and word transfers in different addressing modes.
1B) Write an ALP to transfer a given block of data word from source memory to
1C) Write an ALP to transfer a given block of data word from source memory to
2C) Write an ALP to add / subtract two32 bit numbers using DD Directive.
2D) Write an ALP to multiply two 16 bit unsigned / signed numbers and display.
2E) Write an ALP to divide two 8 bit numbers (signed and unsigned)
3F) Write an ALP to find the GCD of two 16 bit unsigned integers.
4C) Write an ALP to check number of ones and zeroes n the given data.
4D) Write an ALP to check if the given byte is 2 out of 5 code or not (i.e., the code is
first 3 MSB must be 0 and the last 5 LSB should have two 1s).
4E) Write and Alp to check if the given 16 bit data is a palindrome (bitwise).
4F. Write and Alp to check if the given 16 bit data is a palindrome (nibble-wise).
5A) Write an Alp to add / substract N 16 bit numbers and display the result.
5B)Write an ALP to find the largest of N 16 bit numbers and display the result.
5C) Write an ALP to find the smallest of N 16 bit numbers and display the result.
5D) Write an ALP to sort the given set of 16 bit unsigned integers in ascending order
- 65 - 6A) Write an ALP to transfer a given source string to destination using string
instructions.
7A) Write an ALP to read a character from a keyboard with and without echo.
7B) Write an ALP to read a string of characters from the keyboard and display.
PART - B
1A) Write an ALP to scan the keyboard for key closure and store the code of the key
1B) Write an ALP to implement a rolling display of set characters using a display
interface.
1C) Interface a logic controller via 8255 using I/O cards and perform the following
Operations: Read all the 8 inputs from the logic controller, Complement
1D) Write an ALP to control the speed of a stepper motor & to drive the stepper
motor
4. Name some 64 bit processor (Pentium, Pentium pro, Pentium II, Xeon, Pentium III,
and
Pentium IV)
5. List the address bus width and the memory size of all the processor.
Processor
8086
8088
80186
80286
80386
80386DX
80386EX
80486
address bus
20
20
20
24
24
32
26
32
memory size
1M
1M
1M
16M
16M
4G
64M
4G
PENTIUM 64
PENTIUM O 32
4G
4G
PENTIUM P 32 4G
6. The memory map of any IBM COMPATIBLE PC consists of three main parts, name
them
8. What does the TPA hold (interrupt vectors, bios, DOS, IO.SYS, MSDOS, DEVICE
DRIVERS, command.com)
10. What are the main two parts of 8086 internal architecture.(BIU,EU)
11. Name the registers in BIU (CS, DS, ES, SS, IP)
12. Name the registers in EU.( AX, BX, CX, DX, SP, BP, SI, DI)
20. Explain MOV AL, A, MOV AX, NUMBER, MOV [BP], DL, MOV CH,[1000],
21. Name the programme memory addressing modes. (Direct, relative, indirect)
23. Differentiate near and short jumps (+_32k and +127to_128 bytes)
(op(1-2b),(mode,reg,rem),(displacement-0-2b))
35. What are the two types of I/O addressing modes. ( fixed port ,variable port)
40. What are the two basic formats used by assemblers. Where are they used.
41. Explain ADD BYTE PTR (.model tiny (64kb), .model small(128 kb), .model huge.
42. Explain ADD BYTE PTR [DI], 3, SBB BYTE PTR [DI],5, CMP[DI], CH
44. Name the logical instructions. How can we invert number .(XOR WITH 1s)
45. Differentiate TEST and CMP, and NOT& NEG, SAR & SHR, RCL & ROL, SCAS &
46. Which are the flags affected. JA(Z=0 C=0), JB(C=0), JG (Z=0 S=0), JLE( Z=1
S<>0)
48. Differentiate NEAR & FAR CALL, NEAR RET & FAR RET
49. Explain, maskable, non maskable, vectored, non vectored, software & Hardware
Interrupts.
50. What are interrupt vectors. (4 byte no. stored in the first 1024 bytes of memory.
There are
256 interrupt vectors. Each vector contains value of CS & IP, 32 vectors are
reserved for
53. Give the significance of IRET instruction how is it different from RET.
(Like far RET retrieves 6 bytes from stack, two for IP, two for CS and two for flags.)
56. Explain how the interrupt flag bit IF and TF are used during an interrupt
57. Name the hardware and soft ware interrupt of 8086, explain about them. (NMI,
INTR are
hardware interrupts. INT, INT0, INT3, BOYND, are the software interrupts)
58. How can you expand the interrupt structure. ( using 74LS 244 7 more interrupts
can
accommodated. Daisy chained interrupt is better as it requires only one interrupt
vector.)
61. Explain the above pins of 8086 TEST, READY, RESET, BHE/S7, MN/MX, ALE, DT/R,
67. How are the address and data buses are separated.
70. What are the two methods of interfacing memory. ( linear and absolute
decoding)
77. What are the various signals in a RAM and ROM memories.
78. Name the following. 8255, 8155, 8259, 8253, 8257, 8251
84. What is an arithmetic coprocessor, What are its functions. (multiply, devide, ad,
subtract,
85. What are the data types used. ( 16,32, 64 bit signed integers, 18 bit BCD data,
32, 64 and
86. What are the advantages of the 8087 coprocessor. (many times faster than the
microprocessor)
93. What are the conditional statements used in a MACRO. (REPEAT, WHILE)
94. What are the different methods of reading the keyboard using DOS function
calls.
96. What are the two methods of interfacing I/O ( memory mapped I/O and I/O
mapped I/O)
- 69 -