Вы находитесь на странице: 1из 48

Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 1a
;--------------------------------------------------------------------------------------------------------------------
; Title : Copying Data from location X to Y with overlapping
; Description : Copy Data from X[DS:2000] to Y[DS:2005]
; Author : Anamika [4NM13EC---]
; Date : 21/08/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
X DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,10H ; 10 numbers
ORG 2005H
Y DB 0AH DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CX,0AH ; count for the 10 data bytes
LEA DI,Y ; load effective address of X
LEA SI,X ; load effective address of Y
ADD SI,09H
ADD DI,09H
UP:MOV AL,[SI] ; Transfer the data
MOV [DI],AL
DEC SI
DEC DI
LOOP UP ; Repeat 10 times
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>debug prg1.exe
BEFORE EXECUTION
-D DS:2000
1403:2000 01 02 03 04 05 06 07 08-09 10
-D DS:2005
1403:2000 06 07 08-09 10
-g
AFTER EXECUTION
-D DS:2000
1403:2000 01 02 03 04 05 01 02 03-04 05 06 07 08 09 10

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 1b
;--------------------------------------------------------------------------------------------------------------------
; Title : Copying Data from location X to Y without overlapping
; Description : Copy Data from X[DS:2000] to Y[DS:3000]
; Author : Anamika [4NM13EC---]
; Date : 21/08/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
X DB 01H,02H,03H,04H,05H,06H,07H,08H,09H,10H ; 10 numbers
ORG 3000H
Y DB 0AH DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV CX,0AH ; count for the 10 data bytes
LEA DI,Y ; load effective address of X
LEA SI,X ; load effective address of Y
UP:MOV AL,[SI] ; Transfer the data
MOV DS:[DI],AL
INC SI
INC DI
LOOP UP ; Repeat 10 times
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>DEBUG PRG2.EXE
BEFORE EXECUTION
-D DS:2000
1403:2000 01 02 03 04 05 06 07 08-09 10
-D DS:3000
1403:3000 00 00 00 00 00 00 00 00-00 00
-g
AFTER EXECUTION
-d ds:2000
1403:2000 01 02 03 04 05 06 07 08-09 10
-d ds:3000
1403:3000 01 02 03 04 05 06 07 08-09 10

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 2
;--------------------------------------------------------------------------------------------------------------------
; Title : Exchange of 4 bytes Data between ES:3546 and DS:2109
; Description : After assembling the program the user should access the location
; 1A45:3546 and "e 2B65:2109". The 4 values are edited in these locations.
; After the execution of the memory locations are verified using"d ds:3546"
; and "d es:2109" command.
; Author : Anamika [4NM13EC---]
; Date : 21/08/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX,2B65H
MOV DS,AX
MOV AX,1A45H
MOV ES,AX
MOV CX,0004H ;to exchange 4 bytes of data
MOV SI,3546H
MOV DI,2109H
MOVE: MOV DL,ES:[SI] ;copying 1 byte of data from memory to register
MOV DH,[DI]
MOV [DI],DL ;exchange of 1 byte of data from register to another memory location
MOV ES:[SI],DH
INC SI
INC DI
LOOP MOVE
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT
D:\NM023>DEBUG PRG3.EXE
BEFORE EXECUTION
-e 1a45:3546
1A45:3546 13.10 8B.20
1A45:3548 C2.30 03.40
-e 2b65:2109
2B65:2109 10.60 20.70 30.80 40.90
-g
AFTER EXECUTION
-D DS:2109
2B65:2100 10 20 30 40
-D ES:3546
1A45:3540 60 70-80 90

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 3

;--------------------------------------------------------------------------------------------------------------------
; Title : To add 10 numbers from even memory locations
; Description : To add 10 data bytes stored in even address of default data segment
; starting from 0000h offset. And store the result in ES:2020(ES=1B1B)
; Author : Anamika [4NM13EC---]
; Date : 28/08/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
NUM DB 01H,22H,02H,22H,03H,22H,04H,22H,05H,22H,06H,22H,07H,22H,08H,22H,
09H,22H,10H
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AX,1B1BH
MOV ES,AX
LEA SI,NUM
MOV AH,00H ; clearing register to store the carry
MOV DI,2020H
MOV CX,0009H ; initializing number of counts for addition
MOV AL,[SI] ; copying first byte from the memory to register
MOVE:ADD SI,02
ADD AL,[SI]
JNC SKIP
INC AH
SKIP:LOOP MOVE
MOV ES:[DI],AL
MOV ES:[DI+1],AH
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG4.EXE

BEFORE EXECUTION
-D DS:0000
1403:0000 01 22 02 22 03 22 04 22-05 22 06 22 07 22 08 22

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

1403:0010 09 22 10
-D ES:2020
13F3:2020 3C 07
-G

AFTER EXECUTION
-D ES:2020
1B1B:2020 3D 00

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To add two 64 bit numbers
; Description : To add two 64 bit numbers and also save the carry flag value
; The numbers are entered to the memory while executing the program
; Author : Anamika [4NM13EC---]
; Date : 28/08/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
N1 DB 08 DUP(?)
ORG 3000H
N2 DB 08 DUP(?)
ORG 4000H
R DB 09 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,N1
LEA DI,N2
MOV BX,OFFSET(R)
MOV CX,0008H
CLC ; clearing contents of carry flag to avoid mistake while adding carry
UP:MOV AL,[SI] ; copying contents from memory to register to perform addition
ADC AL,[DI]
MOV [BX],AL ; moving result of addition to new memory location
INC SI
INC DI
INC BX
LOOP UP
MOV AL,00H

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

ADC AL,00H
MOV [BX],AL ; final carry is saved in the memory
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG5.EXE

BEFORE EXECUTION
-D DS:2000
1403:2000 00 00 00 00 00 00 00 00
-D DS:3000
1403:3000 00 00 00 00 00 00 00 00
-D DS:4000
1403:4000 00 00 00 00 00 00 00 00-00
-E DS:2000
1403:2000 00.12 00.34 00.56 00.78 00.9A 00.BC 00.DE 00.F0
-E DS:3000
1403:3000 00.11 00.22 00.33 00.44 00.55 00.66 00.77 00.88
-G

AFTER EXECUTION
-D DS:4000
1403:4000 23 56 89 BC EF 22 56 79-01

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To add six two digit BCD numbers
; Description : To add six two digit BCD numbers stored in memory location
; DS:2000H and result stored in DS:3000H
; Author : Anamika [4NM13EC---]
; Date : 28/08/2015
; College/Dept : NMAMIT/ECE
; -------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
NUM DB 99H,99H,99H,99H,99H,99H
ORG 3000H
RES DB 02 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

START:MOV AX,DATA
MOV DS,AX
LEA SI,NUM
LEA DI,RES
MOV CX,0006H ; initializing count for loop
MOV AX,0H
UP:ADD AL,[SI]
DAA ; converting the sum to decimal equivalent sum
JNC SKIP
INC AH ; using AH register to store higher byte of result
SKIP:INC SI
LOOP UP
MOV [DI],AL
MOV [DI+1],AH ; moving results from register to memory
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT
D:\NM023>DEBUG PRG6.EXE
BEFORE EXECUTION
-D DS:2000
1403:2000 99 99 99 99 99 99
-D DS:3000
1403:3000 00 00
-G
AFTER EXECUTION
-D DS:3000
1403:3000 94 05

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To subtract two 64 bit numbers
; Description : To subtract two 64 bit numbers and save the result in location DS:4000
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
ORG 2000H
N1 DB 08 DUP(?)
ORG 3000H
N2 DB 08 DUP(?)
ORG 4000H

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

R DB 09 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,N1
LEA DI,N2
MOV BX,OFFSET(R)
MOV CX,0008H ; initializing count for loop
CLC ; clearing carry flag to avoid previous carry to affect this subtraction
UP:MOV AL,[SI]
SBB AL,[DI]
MOV [BX],AL
INC SI
INC DI
INC BX
LOOP UP
INT 3H
CODE ENDS
END START

;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG7.EXE

BEFORE EXECUTION
-E DS:2000
1403:2000 00.84 00.00 00.FF 00.3C 00.6D 00.A5 00.64 00.83
-E DS:3000
1403:3000 00.AB 00.3F 00.01 00.BC 00.FF 00.63 00.11 00.11
-D DS:4000
1403:4000 00 00 00 00 00 00 00 00
-G

AFTER EXECUTION
-D DS:4000
1403:4000 D9 C0 FD 80 6D 41 53 72

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 4
;--------------------------------------------------------------------------------------------------------------------
; Title : To arrange 10 bytes of data in ascending order
; Description : To arrange 10 bytes of unsigned numbers stored in
; location DS:4000 in ascending order
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
X DB 05H,01H,09H,03H,06H,08H,00H,07H,02H,04H
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV CX,09H
UP1:LEA SI,X ; every time comparision must start from the starting address of memory
MOV AL,[SI]
INC SI
PUSH CX ; moving value of CX register to stack segment to save loop counter value
UP:CMP AL,[SI]
JBE SKIP ; checking numbers for less than or equal to
MOV BL,[SI]
MOV [SI-1],BL
MOV [SI],AL ; swaping the values
SKIP:MOV AL,[SI]
INC SI
LOOP UP ;the loop repeats until value in CX becomes zero
POP CX ; saved value of CX is copied back from the stack segment
LOOP UP1
INT 3H
CODE ENDS
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>DEBUG PRG8.EXE
BEFORE EXECUTION
-D DS:2000
1403:2000 05 01 09 03 06 08 00 07-02 04
-G
AFTER EXECUTION
-D DS:2000
1403:2000 00 01 02 03 04 05 06 07-08 09

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 4

;--------------------------------------------------------------------------------------------------------------------
; Title : To arrange 10 bytes of data in descending order
; Description : To arrange 10 bytes of numbers stored in DS:4000 in descending order
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 2000H
X DB 05H,01H,09H,03H,06H,08H,00H,07H,02H,04H
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV CX,09H
UP1:LEA SI,X ; every time comparision must start from the starting address of memory
MOV AL,[SI]
INC SI
PUSH CX ; moving value of CX register to stack segment to save loop counter
UP:CMP AL,[SI]
JAE SKIP ; checking numbers for greater than or equal to
MOV BL,[SI]
MOV [SI-1],BL
MOV [SI],AL ; swaping the values
SKIP:MOV AL,[SI]
INC SI
LOOP UP ;the loop repeats until value in CX becomes zero
POP CX ; saved value of CX is copied back from the stack segment
LOOP UP1
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT
D:\NM023>DEBUG PRG9.EXE
BEFORE EXECUTION
-D DS:2000
1403:2000 05 01 09 03 06 08 00 07-02 04
-G
AFTER EXECUTION
-D DS:2000

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

1403:2000 09 08 07 06 05 04 03 02-01 00

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------

; Title : To subtract an array of 10 numbers


; Description : To subtract an array of 10 numbers stored in the location
; DS:2000 and store the result in DS:3000
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
ORG 2000H
NUM DB 15h,32h,88h,12h,0BFh,03h,77h,46h,22h,50h
ORG 3000H
RES DB 02 DUP(?)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,NUM
LEA DI,RES
MOV BL,00H ; clearing contents of BX register to save the borrows
MOV AL,[SI] ; copying first number to the register AL
INC SI
MOV CX,09H
CLC ; clearing carry flag to avoid previous result from affecting current subtraction
MOVE:SUB AL,[SI]
JNC SKIP
DEC BL
SKIP:INC SI
LOOP MOVE
MOV DS:[DI],AL ; copying results from register to memory
MOV DS:[DI+1],BL
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

D:\NM023>DEBUG PRG10.EXE

BEFORE EXECUTION
-D DS:2000
1403:2000 15 32 88 12 BF 03 77 46-22 50
-D DS:3000
1403:3000 00 00
-G

AFTER EXECUTION
-D DS:3000
1403:3000 58 FD

PROGRAM 5

;--------------------------------------------------------------------------------------------------------------------
; Title : To find sum of six two digit BCD numbers
; Description : To enter six two digit BCD numbers through keyboard and display their
; sum on the console
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
MSG1 DB 10,13,”ENTER SIX 2 DIGIT BCD NUMBERS:”,10,13,”$”
MSG2 DB 10,13,”THE SUM OF ENTERED NUMBERS IS:$”
NEWL DB 0AH,0DH,’$’
ORG 2000H
X DB 6 DUP(0)
ORG 3000H
SUM DB 2 DUP(0)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,X
MOV CX,06H ;initializing count to read 6 numbers
MOV AH,09H

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

LEA DX,MSG1
INT 21H ; displaying the first message
UP:MOV AH,01H
INT 21H
SUB AL,30H
PUSH CX
MOV CX,4H
SHL AL,CL ;converting ASCII value of the entered number to actual digit
MOV [SI],AL ; moving the digit to the memory location X
INT 21H
SUB AL,30H
ADD [SI],AL ;saving the whole two digit number in the memory X
MOV AH,09H
MOV DX,OFFSET(NEWL)
INT 21H ; to transfer cursor to newline after entering a number
POP CX
INC SI
LOOP UP
;calculating sum
LEA SI,X ; assigning starting address of X to SI
MOV BX,00H ;initializing BX to 0h to save sum of the numbers temporarily
MOV CX,06H ; initializing count for the loop
UP1: MOV AL,BL
ADD AL,[SI] ;adding the numbers
DAA ;converting to decimal equivalent form
JNC DOWN1
INC BH
DOWN1:MOV BL,AL
INC SI
LOOP UP1
;displaying sum
MOV AH,09H
LEA DX,MSG2
INT 21H ;displaying the second message
LEA SI,SUM ;assigning starting address of SUM to SI
MOV [SI],BH
MOV [SI+1],BL ;storing the sum in the memory location SUM
MOV AH,02H
MOV CX,02H
DOWN: MOV DL,[SI] ;copying a byte of sum from memory to register DL

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

AND DL,0F0H
PUSH CX
MOV CX,04H
SHR DL,CL
ADD DL,30H ;storing ASCII value of first digit of the sum byte
INT 21H ;displaying the first digit
MOV DL,[SI] ;copying a byte of sum from memory to register DL
AND DL,0FH
ADD DL,30H ; storing ASCII value of second digit of the sum byte
INT 21H ;displaying the second digit
POP CX
INC SI
LOOP DOWN ;loop is used to display two bytes of data from the sum
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT

D:\NM023>DEBUG PRG11.EXE
-G

1)
AFTER EXECUTION

ENTER SIX 2 DIGIT BCD NUMBERS:


23
45
11
61
21
34

THE SUM OF ENTERED NUMBERS IS: 0195

2)
AFTER EXECUTION

ENTER SIX 2 DIGIT BCD NUMBERS:


99
99
99

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

99
99
99

THE SUM OF ENTERED NUMBERS IS: 0594


>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To find sum of six four digit BCD numbers
; Description : To enter six four digit BCD numbers through keyboard and display their
; sum on the console
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
ORG 1000H
MSG1 DB "ENTER SIX FOUR DIGIT NUMBERS",10,13,"$"
ORG 2000H
NEWL DB 10,13,"$"
ORG 3000H
MSG2 DB "SUM IS:",10,13,"$"
ORG 4000H
NUMS DB 0CH DUP(0)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET(MSG1)
MOV AH,09H
INT 21H ;displaying first message
MOV DX,00H ;DX reg is used to store higher word of the sum of the numbers entered
MOV BX,00H ;BX reg is used to store lower word of the sum
LEA SI,NUMS ;moving starting address of NUM to SI
MOV CX,06H ;initializing count to 6 to read 6 numbers
UP: MOV AH,01H
INT 21H
SUB AL,30H
PUSH CX
MOV CL,04H

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

SHL AL,CL ;converting ASCII value to real number


MOV [SI+1],AL ;storing the first digit in the memory
MOV AH,01H
INT 21H
SUB AL,30H
ADD [SI+1],AL ;storing second digit of the number
MOV AH,01H
INT 21H ;reading third digit
SUB AL,30H ;converting ASCII value to real number
SHL AL,CL
MOV [SI],AL ;storing the third digit in memory
MOV AH,01H
INT 21H ;reading fourth digit
SUB AL,30H
ADD [SI],AL ;storing fourth digit in the memory
CLC
MOV AL,BL
ADD AL,[SI] ;adding the lower byte of the numbers
entered
DAA ;converting into equivalent decimal sum
MOV BL,AL
MOV AL,BH
ADC AL,[SI+1] ;adding the higher byte of the entered
numbers
DAA ;converting into equivalent decimal sum
JNC SKIP
INC DL
SKIP:
MOV BH,AL
PUSH DX ;moving value of DX to stack segment
MOV DX,OFFSET(NEWL)
MOV AH,09H
INT 21H ;moving cursor to newline after each number is
entered
POP DX
POP CX
ADD SI,02H
LOOP UP
PUSH DX
MOV DX,OFFSET(MSG2)
MOV AH,09H
INT 21H ;displaying second message
POP DX
ADD DL,30H ;storing ASCII value
MOV AH,02H
INT 21H ;displaying higher word of the sum

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

MOV CX,02H
AG:MOV DL,BH
AND DL,0F0H
PUSH CX
MOV CL,04H
SHR DL,CL
ADD DL,30H ;storing ASCII value
MOV AH,02H
INT 21H ;displaying a digit from lower word of sum
MOV DL,BH
AND DL,0FH
ADD DL,30H
INT 21H ;displaying another digit from lower word of sum
MOV BH,BL
POP CX
LOOP AG
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG12.EXE
-G

AFTER EXECUTION
ENTER SIX FOUR DIGIT NUMBERS
1111
2222
1111
2222
1212
2121
SUM IS:
09999

AFTER EXECUTION
ENTER SIX FOUR DIGIT NUMBERS
9999
9999
9999
9999
9999
9999
SUM IS:

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

59994

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To show the use of AAA instruction
; Description : To show the use of AAA (ASCII Adjust AL after Addition)
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX,00H
MOV AL,37h
MOV BL,39H
ADD AL,BL ;al<=al+bl=37h+39h=70h
AAA ; if((al AND 0FH)>9)or(af=1) then
; al<=al+6,ah<=ah+1,af=0,cf=1
; else al<=(al AND 0fh),af=0,cf=0
; store unpacked BCD in AX
MOV SI,1000H
MOV [SI],AL
INC SI
MOV [SI],AH
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT:

D:\NM023>DEBUG PRG13.EXE
-G
AFTER EXECUTION:

AX=0106 BX=0032 CX=0013 DX=0000 SP=0000 BP=0000 SI=1001 DI=0000


DS=075A ES=075A SS=0769 CS=076A IP=0012 NV UP EI PL NZ NA PO NC
076A:0012 CC INT 3
-d ds:1000
Microprocessor & Microcontroller Application Lab - EC506
Department of Electronics & Communication Engineering, NMAMIT, Nitte

075A:1000 06 01
>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To show the use of AAM instruction
; Description : To show the use of AAM (ASCII Adjust AX after Multiplication)
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX,00H
MOV AL,09H
MOV BL,09H
MUL BL ; al<=al*bl=09h*09h=0051h
AAM ; ax<=0801h,which is unpacked BCD for 51h
MOV SI,1000H
MOV [SI],AL
INC SI
MOV [SI],AH
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT:

D:\NM023>DEBUG PRG14.EXE
-G
AFTER EXECUTION:

AX=0801 BX=0009 CX=0014 DX=0000 SP=0000 BP=0000 SI=1001 DI=0000


DS=075A ES=075A SS=0769 CS=076A IP=0013 NV UP EI PL NZ NA PO NC
076A:0013 CC INT 3
-d ds:1000 01 08

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To arrange 10 bytes of signed data in ascending order
; Description : To arrange 10 bytes of signed data in ascending order and store the result
; in DS:3000
; Author : Anamika [4NM13EC---]
; Date : 04/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
ORG 2000H
X DB 07H,04H,03H,02H,82H,08H,01H,0AAH,09H,0CDH
ORG 3000H
Y DB 0AH DUP(0)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV CX,09H
UP1: LEA SI,X
MOV AL,[SI] ; copying first byte of location x to al
INC SI
PUSH CX ; copying value of CX to stack segment
UP:CMP AL,[SI] ;comparing al with the next byte
JBE SKIP
MOV DL,[SI]
MOV DH,[SI-1]
MOV [SI],DH
MOV [SI-1],DL ;swaping the bytes
SKIP: MOV AL,[SI] ;storing ascendingly ordered numbers considering them as unsigned
INC SI
LOOP UP
POP CX
LOOP UP1
LEA DI,Y
LEA SI,X
MOV DX,00H
MOV CX,0AH
UP2 :MOV AL,[SI]
CMP AL,7FH ;checking for negative numbers
JBE SK

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

JMP DOWN2
SK:INC SI
INC DX ;counting number of positive numbers
LOOP UP2
JMP L2
DOWN2:MOV [DI],AL ;copying negative numbers to new location
INC SI
INC DI
MOV AL,[SI]
LOOP DOWN2
L2:LEA SI,X
MOV CX,DX
NXT:MOV AL,[SI]
MOV [DI],AL ;copying positive numbers to new location
INC SI
INC DI
LOOP NXT
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG15.EXE

BEFORE EXECUTION:
-D DS:2000
076A:2000 07 04 03 02 82 08 01 AA-09 CD
AFTER EXECUTION:
-D DS:2000
076A:2000 01 02 03 04 07 08 09 82-AA CD
-D DS:3000
076A:3000 82 AA CD 01 02 03 04-07 08 09

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To multiply two 16 bit numbers
; Description : To multiply two 16 bit numbers and save result in DS:4000
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

ORG 1000H
N1 DW 1000H
ORG 2000H
N2 DW 2000H
ORG 4000H
R DW 02 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE;
START:
MOV AX,DATA
MOV DS,AX
LEA SI,N1 ;copying address of N1 to SI
LEA DI,N2 ;copying address of N2 to DI
MOV BX,OFFSET(R) ;copying address of R to BX
MOV AX,[SI]
MOV CX,[DI]
MUL CX ;16 bit multiplication of AX and CX
MOV [BX],AX ;lower byte of the product copied to memory
MOV [BX+2],DX ;higher byte of the product copied to memory
INT 3H
CODE ENDS
END START

RESULT
D:\NM023>DEBUG PRG16.EXE
BEFORE EXECUTION
-D DS:1000
1403:1000 00 10
-D DS:2000
1403:2000 00 20
-D DS:4000
1403:4000 00 00 00 00
-G
AFTER EXECUTION
-D DS:4000
1403:4000 00 00 00 02

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To divide a 16 bit number from 8 bit number
; Description : To divide a 16 bit number from 8 bit number and store result in DS:3000
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015
; College/Dept : NMAMIT/ECE

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 1000H
N1 DW 1123H
ORG 2000H
N2 DB 42H
ORG 3000H
R DW 01 DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE;
START:
MOV AX,DATA
MOV DS,AX
LEA SI,N1 ;copying address of N1 to SI
LEA DI,N2 ;copying address of N2 to DI
MOV BX,OFFSET(R) ;copying address of R to BX
MOV AX,[SI]
MOV CL,[DI]
DIV CL ;division of 16bit reg AX by 8 bit reg CL
MOV [BX],AL ;copying quotient to the memory
MOV [BX+1],AH ;copying remainder to the memory
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT
D:\NM023>DEBUG PRG17.EXE
BEFOR EXECUTION
-D DS:1000
1403:1000 23 11
-D DS:2000
1403:2000 42
-D DS:3000
1403:3000 00 00
-G
AFTER EXECUTION
-D DS:3000
1403:3000 42 1F

PROGRAM 6 a)
;--------------------------------------------------------------------------------------------------------------------
; Title : To convert BCD number to hexadecimal number
; Description : To convert a four digit BCD number to hexadecimal number
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
CODE SEGMENT
ASSUME CS:CODE;
START:
MOV SI,1000H
MOV AX,1234H
MOV WORD PTR[SI],AX ;copying BCD number to location DS:1000
MOV SI,2000H
MOV WORD PTR[SI],0000H ;initializing location DS:2000 to 0
MOV BX,AX
AND AX,0FH ;getting the first digit
ADD [SI],AL ;adding it to the memory
MOV AX,BX
AND AX,0F0H
MOV CL,04H
SHR AX,CL ;getting second digit
MOV CL,0AH
MUL CL ;multiplying second digit by 0Ah
ADD [SI],AX ;adding it to the memory
MOV AX,BX
AND AX,0F00H
MOV CL,08H
SHR AX,CL ;getting third digit
MOV CL,64H
MUL CL ;multiplying third digit with 64h
CLC
ADD [SI],AL
ADC [SI+1],AH ;adding the product to the memory
MOV AX,BX
AND AX,0F000H
MOV CL,0CH ;getting fourth digit
SHR AX,CL
MOV CX,3E8H
MUL CX ;multiplying it by 3E8h
ADD [SI],AL
ADC [SI+1],AH ;adding product to memory
INT 3H
CODE ENDS
END START
RESULT
D:\NM023>DEBUG PRG18.EXE

BEFORE EXECUTION
-D DS:1000
13F3:1000 34 12

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

-D DS:2000
13F3:2000 00 00
-G
AFTER EXECUTION
-D DS:2000
13F3:2000 D2 04

PROGRAM 6 b)
;--------------------------------------------------------------------------------------------------------------------
; Title : To convert hexadecimal number to BCD number
; Description : To convert a four digit hexadecimal number to BCD number
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
CODE SEGMENT
ASSUME CS:CODE;
START:
MOV SI,1000H
MOV AX,0FFEFH
MOV WORD PTR[SI],AX
MOV SI,2000H
MOV WORD PTR[SI],0000H
MOV CX,0AH
UP:MOV DX,00H
DIV CX
MOV [SI],DL
INC SI
CMP AX,CX
JAE UP
MOV [SI],AL
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT

D:\NM023>DEBUG PRG19.EXE

BEFORE EXECUTION
-D DS:1000
075A:1000 46 04 03 C6
-D DS:2000
075A:2000 7F 04 00 75 C6
-G

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

AFTER EXECUTION
-D DS:1000
075A:1000 EF FF
-D DS:2000
075A:2000 09 01 05 05 06

PROGRAM 7 a)
;--------------------------------------------------------------------------------------------------------------------
; Title : To find LCM and GCD of two numbers
; Description : To find LCM and GCD of two numbers entered from the keyboard
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
ORG 3000H
NUM1 DB ?
NUM2 DB ?
LCM DB ?
GCD DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV SI,3000H
MOV AH,01H
INT 21H ;read a number
SUB AL,30H
MOV NUM1,AL ;save it in the memory
MOV BL,AL
INT 21H ;read another number
SUB AL,30H
MOV NUM2,AL ;save it in the memory
L1: CMP AL,BL
JE L3 ;check if the numbers are equal
JA L2
ADD AL,NUM2 ;adds the number by itself
JMP L1
L2: ADD BL,NUM1 ;adds the number by itself
JMP L1
L3: MOV LCM,AL

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

MOV AL,NUM1
MOV BL,NUM2
MUL BL
MOV BL,LCM
DIV BL ;gcd= num1 x num2 / lcm
INC SI
MOV GCD,AL
INT 3H
CODE ENDS
END START

RESULT:

D:\NM023>DEBUG PRG20.EXE

AFTER EXECUTION:
-G
46
-d ds:3000
075A:3000 04 06 0C 02

PROGRAM 7 b)
;--------------------------------------------------------------------------------------------------------------------
; Title : To find factorial of a BCD number
; Description : To find factorial of a single digit BCD number
; Author : Anamika [4NM13EC---]
; Date : 18/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
NUM DB 09H
FACTORIAL DW (?)
FACTORIAL1 DW (?)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV AL,NUM
CMP AL,01H
Microprocessor & Microcontroller Application Lab - EC506
Department of Electronics & Communication Engineering, NMAMIT, Nitte

JBE LAST ;check if the number is less than or equal to one


MOV CL,AL
DEC CL
MOV AH,00H
MOV AL,01H
MOV BL,01H
FACT: INC BL
MUL BX
DEC CL
JNZ FACT ;continuous multiplication until CL becomes zero
MOV FACTORIAL,AX ;storing lower byte in the memory
MOV FACTORIAL1,DX ;storing higher byte in the memory
JZ DOWN
LAST: MOV AH,00H
MOV AL,01H
MOV FACTORIAL,AX ;storing factorial as 1 for numbers<=1
DOWN: INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT:

D:\NM023>DEBUG PRG21.EXE

BEFORE EXECUTION:
-d ds:0000
076A:0000 09 00 00 00 00

AFTER EXECUTION:
-d ds:0000
076A:0000 09 80 89 05 00

PROGRAM 8
;--------------------------------------------------------------------------------------------------------------------
; Title : To reverse a string and display it
; Description : To enter a string through the keyboard,reverse it and display the reversed
string
; Author : Anamika [4NM13EC---]
; Date : 25/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

DATA SEGMENT
NUM1 DB 10,13,"Enter a string $"
NUM2 DB 10,13,"Reversed string is $" ;storing the messages to be displayed
N DB 0
TEMP DB 10 DUP(0)
ORG 2000H
TEMP1 DB 10 DUP(0)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,NUM1
MOV AH,09H
INT 21H
LEA SI,TEMP
LEA DI,TEMP1
MOV CX,00H
UP:MOV AH,01H
INT 21H
CMP AL,0DH ;reading a character until enter key is pressed
JE DOWN
MOV [SI],AL ;saving the characters entered in the memory
INC SI
INC CL
JMP UP
DOWN:MOV BH,'$' ;terminating the string with $ to indicate end of the string
MOV[SI],BH
DEC SI
MOV BL,CL
UP1:MOV AL,[SI]
MOV [DI],AL ;storing the reversed string in another memory location
DEC SI
INC DI
LOOP UP1
DOWN1:MOV BH,'$' ;terminating the reversed string with $
MOV [DI],BH
LEA DX,NUM2
MOV AH,09H
INT 21H
LEA DX,TEMP1
INT 21H ; displaying the reversed string
INT 3H
CODE ENDS

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

END START
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>DEBUG PRG22.EXE
-G
1)AFTER EXECUTION

Enter a string ANAMIKA


Reversed string is AKIMANA

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To concatenate two strings
; Description : To concatenate two strings from different segment
; Author : Anamika [4NM13EC---]
; Date : 25/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
STR1 DB 30 DUP(' ')
LEN1 DB ?
MSG DB 10,13,"ENTER FIRST STRING:$"
MSG1 DB 10,13,"ENTER SECOND STRING:$"
MSG2 DB 10,13,"CONCATENATED STRING IS:$"
DATA ENDS
EXTRA SEGMENT
STR2 DB 20 DUP(0)
LEN2 DB ?
EXTRA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRA
START:
MOV AX,DATA
MOV DS,AX
MOV AX,EXTRA
MOV ES,AX
LEA SI,STR1
LEA DI,STR2
LEA DX,MSG
MOV AH,09H
INT 21H
MOV CH,0H
STNG1:MOV AH,01H

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

INT 21H
CMP AL,0DH ;reading characters from keyboard until enter key is pressed
JZ DOWN1
MOV DS:[SI],AL ;storing the entered characters in memory
INC SI
INC CH
JMP STNG1
DOWN1:INC SI ;leaving one byte of memory for space between the two strings
MOV LEN1,CH
MOV DL,10
MOV AH,02H
INT 21H
LEA DX,MSG1
MOV AH,09H
INT 21H
MOV CH,00H
STNG2:MOV AH,01H
INT 21H
CMP AL,0DH ;reading second set of characters until enter key is pressed
JZ DOWN2
MOV ES:[DI],AL ;storing it in the memory
INC DI
INC CH
JMP STNG2
DOWN2:MOV LEN2,CH
LEA DI,STR2
CONCAT:MOV AL,ES:[DI]
MOV DS:[SI],AL ;concatenating the strings and saving it in the first string’s memory
INC SI ;location
INC DI
DEC CH
JNZ CONCAT
MOV CH,LEN1
ADD CH,LEN2
ADD CH,1H
LEA SI,STR1
MOV DL,10
MOV AH,02H
INT 21H ;moving cursor to the next line in the console
LEA DX,MSG2
MOV AH,09H
INT 21H ; displaying the second message
DISP:MOV DL,DS:[SI]
MOV AH,02H
INT 21H ;displaing the concatenated string
INC SI

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

DEC CH
JNZ DISP
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>DEBUG PRG23.EXE

1.AFTER EXECUTION

ENTER FIRST STRING:PAULO

ENTER SECOND STRING:COEHLO

CONCATENATED STRING IS:PAULO COEHLO

PROGRAM 9
;--------------------------------------------------------------------------------------------------------------------
; Title : To arrange set of 10 letters in alphabetical order
; Description : To read 10 letters from keyboard and display them in alphabetical order
; Author : Anamika [4NM13EC---]
; Date : 25/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------

DATA SEGMENT
ORG 2000H
LETTERS DB 0AH DUP(?)
MSG1 DB "ENTER THE ALPHABETS",10,"$"
MSG2 DB 10,"THE ORDERED ALPHABETS ARE",10,"$"
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA SI,LETTERS
MOV AH,09H
LEA DX,MSG1
INT 21H ;display first message
MOV CX,0AH

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

UP:MOV AH,01H
INT 21H ;read 10 letters character by character
MOV [SI],AL ;store their ASCII values in the memory
INC SI
LOOP UP
MOV CX,09H
CMP2:LEA SI,LETTERS
MOV AL,[SI]
INC SI
PUSH CX
CMP1:CMP AL,[SI] ; compare the ASCII values
JBE SKIP
MOV BL,[SI]
MOV BH,[SI-1]
MOV [SI],BH
MOV [SI-1],BL ;swap the ASCII values
SKIP:MOV AL,[SI]
INC SI
LOOP CMP1
POP CX
LOOP CMP2 ;the letters will be arranged in the alphabetical order by the end of this loop
LEA DX,MSG2
MOV AH,09H
INT 21H ;displaying second message
LEA SI,LETTERS
MOV AH,02H
MOV CX,0AH
UP1:MOV DL,[SI]
INT 21H ;displaying the letters in alphabetical order
INC SI
LOOP UP1
INT 3H
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT
D:\NM023>DEBUG PRG24.EXE

1)AFTER EXECUTION
ENTER THE ALPHABETS
JIHGFEDCBA
THE ORDERED ALPHABETS ARE
ABCDEFGHIJ

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

2)AFTER EXECUTION
ENTER THE ALPHABETS
LKHJGDFSRT
THE ORDERED ALPHABETS ARE
DFGHJKLRST

PROGRAM 10
;--------------------------------------------------------------------------------------------------------------------
; Title : To check whether the string is palindrome or not
; Description : To check and display whether the entered string is palindrome or not
; Author : Anamika [4NM13EC---]
; Date : 25/09/2015
; College/Dept : NMAMIT/ECE
;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
MSG1 DB 'ENTER THE STRING:$'
MSG2 DB 0DH,0AH,'STRING IS NOT A PALINDROME.$'
MSG3 DB 0DH,0AH,'STRING IS A PALINDROME.$'
MSG4 DB ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H ; display first message
MOV SI,00H
MOV DI,00H
BACK: MOV AH,01H
INT 21H ;reading characters from the keyboard
MOV MSG4[SI],AL ;storing the ASCII values of the entered characters in the memory
INC SI
CMP AL,0DH ;comparing with enter key
JNZ BACK
DEC SI
DEC SI
MOV CX,SI
UP: MOV BL,MSG4[DI]

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

MOV DL,MSG4[SI]
CMP BL,DL ;comparing the ASCII values at specific locations to check for palindrome
JNZ DOWN
INC DI
DEC SI
LOOP UP
MOV DX,OFFSET MSG3
MOV AH,09H
INT 21H ;displaying third message
INT 3H ;suspend execution
DOWN: MOV DX,OFFSET MSG2
MOV AH,09H
INT 21H ; displaying second message
INT 3H ; suspend execution
CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------

RESULT:
D:\NM023>DEBUG PRG25.EXE

1.AFTER EXECUTION

ENTER THE STRING:ANAMIKA

STRING IS NOT A PALINDROME.

2.AFTER EXECUTION

ENTER THE STRING:MADAM

STRING IS A PALINDROME.

>Additional Exercise Program

;--------------------------------------------------------------------------------------------------------------------
; Title : To illustrate the use of LODSB and CMPSB instructions
; Description : To illustrate the use of LODSB and CMPSB instructions
; Author : Anamika [4NM13EC---]
; Date : 25/09/2015
; College/Dept : NMAMIT/ECE

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

;--------------------------------------------------------------------------------------------------------------------
DATA SEGMENT
STR1 DB “MALAYALAM $”
LEN DB 09H
STR2 DB 10 DUP(‘ ‘)
MSG1 DB 10,13,"IS A PALINDROME",10,13,'$'
MSG2 DB 10,13,"IS NOT A PALINDROME",10,13,'$'
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATA
START:
MOV AX,DATA ;initialization of data segment
MOV DS,AX
MOV ES,AX ;initializing extra segment with the same contents as that of data segment
LEA SI,STR1
LEA DI,STR2+LEN-1
MOV CX,LEN
UP: CLD ;clear the direction flag
LODSB ;load AL with contents of DS:[SI] and increment SI
STD ;set direction flag
STOSB ;store contents of SI to ES:[DI] and decrement DI
LOOP UP ;reversed STR1 is saved in STR2 at the end of the loop
LEA SI,STR1
LEA DI,STR2
MOV CX,LEN
REPE CMPSB ; REPE instruction decrements CX by 1 until it becomes 0 and also
; checks for the zero flag. If zero flag is 1 then the cycle repeats else
; comes out of the loop
; CMPSB compares data at DS:[SI] and ES:[DI] and changes the flag
;accordingly
CMP CX,0H
JNZ NPAL ;jump if not zero to NPAL
LEA DX,MSG2 ;display message in msg2
MOV AH,09H
INT 21H
JMP EXIT
NPAL: LEA DX,MSG1 ;display message in msg1
MOV AH,09H
INT 21H
EXIT: INT 3H
Microprocessor & Microcontroller Application Lab - EC506
Department of Electronics & Communication Engineering, NMAMIT, Nitte

CODE ENDS
END START
;--------------------------------------------------------------------------------------------------------------------
RESULT:
D:\NM023>DEBUG PRG26.EXE

AFTER EXECUTION

IS A PALINDROME

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

8051 MICROCONTROLLER INTERFACE PROGRAMS


PROGRAM 11
;---------------------------------------------------------------------------------------------------------------
; Title : To blink LEDs
; Description : Simple LED interfacing using port 0 of 8051
; Author : Anamika [4NM13EC---]
; Date : 30/10/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; initialize the port 0 as 00h(output port)
UP:MOV A,#00H
MOV P0,A ; turn off the leds for a specific period using
LCALL DELAY ; delay function
MOV A,#0FFH
MOV P0,A ; turn off the leds for a specific period using
LCALL DELAY ; delay function
SJMP UP

DELAY: ; procedure to give delay


MOV R0,#0FFH ; MOV instruction takes 1 machine cycle
RPT2:MOV R1,#0FFH
RPT1:DJNZ R1,RPT1 ; DJNZ instruction takes 2 machine cycles
DJNZ R0,RPT2
RET

END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure ={(2x255 + 2 + 1)x255}+ 1
= 130816
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 130816 x 1.086us = 0.142s

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 2
;---------------------------------------------------------------------------------------------------------------
; Title : To demonstrate Binary up counter on LEDs
; Description : To demonstrate Binary up counter on LEDs using port 0 as output
; port
; Author : Anamika [4NM13EC---]
; Date : 30/10/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; initialize the port 0 as 00h(output port)
MOV A,#00H
UP:MOV P0,A ; Turn on LED with corresponding value of A for
LCALL DELAY ; specific period using DELAY function
INC A ; increment the counter value
SJMP UP

DELAY: ; procedure to give delay


MOV R0,#0FFH ; MOV instruction takes 1 machine cycle
RPT2:MOV R1,#0FFH
RPT1:DJNZ R1,RPT1 ; DJNZ instruction takes 2 machine cycles
DJNZ R0,RPT2
RET

END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = {(2x255 + 2 + 1)x255 }+ 1
= 130816
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 130816 x 1.086us = 0.142s

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 2
;---------------------------------------------------------------------------------------------------------------
; Title : To demonstrate Binary down counter on LEDs
; Description : To demonstrate Binary down counter on LEDs using port 0 as
; output port
; Author : Anamika [4NM13EC---]
; Date : 30/10/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; initialize the port 0 as 00h(output port)
MOV A,#00H
UP:MOV P0,A ; Turn on LED with corresponding value of A for
LCALL DELAY ; specific period using DELAY function
DEC A ; decrement the counter value
SJMP UP

DELAY: ; procedure to give delay


MOV R0,#0FFH ; MOV instruction takes 1 machine cycle
RPT2:MOV R1,#0FFH
RPT1:DJNZ R1,RPT1 ; DJNZ instruction takes 2 machine cycles
DJNZ R0,RPT2
RET

END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = {(2x255 + 2 + 1)x255 }+ 1
= 130816
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 130816 x 1.086us = 0.142s

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

>Additional Exercise Program

;---------------------------------------------------------------------------------------------------------------
; Title : To read the status of DIP switches and display the value on LEDs
; Description : To read the status of DIP switches and display the value on LEDs
; using port 1 as input port and port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 30/10/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; Initialize port 0 as output port
MOV P1,#0FFH ; Initialize port 1 as input port
UP: MOV A,P1 ; reading the port 1
MOV P0,A ; write to port 0
SJMP UP
END

PROGRAM 13
;---------------------------------------------------------------------------------------------------------------
; Title : To read the status of DIP switches and display the key value on
; LEDs
; Description : To read the status of DIP switches and display the key value on
; LEDs using port 1 as input port and port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 30/10/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; Initialize port 0 as output port
MOV P1,#0FFH ; Initialize port 1 as input port
MOV DPTR,#VALUE ; look up table address is loaded on DPTR
UP:MOV A,P1 ; Read the switch status onto P1
ANL A,#0FH ; Mask the higher nibble
MOVC A,@A+DPTR ; load the look up table value
MOV P0,A ; display on P0
SJMP UP
ORG 0x3000
VALUE:DB 01H,02H,04H,08H,10H,20H,40H,80H
END

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 14
;---------------------------------------------------------------------------------------------------------------
; Title : To interface stepper motor with 8051
; Description : To rotate the stepper motor 180 degree clockwise and then
; 180 degree anticlockwise once using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV A,#11H ; initializing starting sequence of the step
MOV R2,#100 ; step count for clockwise rotation (100x1.8=180)
UP1:MOV P0,A ; loading the step sequence to port0
LCALL DELAY ; relaxation time for optimum rotation
RL A ; generating the next step sequence
DJNZ R2,UP1
MOV R2,#100 ; step count for anticlockwise rotation(100x1.8=180)
UP11:MOV P0,A ; loading the step sequence to port 0
LCALL DELAY ; relaxation time for optimum rotation
RR A ; generating the next step sequence
DJNZ R2,UP11
HERE: SJMP HERE
DELAY: ; function to give required delay between each step rotation
MOV R3,#0FH
HERE2:MOV R4,#0FFH
HERE1:DJNZ R4,HERE1
DJNZ R3,HERE2
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = {(2x255 + 2 + 1)x15 }+ 1
= 7696
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 7696 x 1.086us = 8.36ms

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 14
;---------------------------------------------------------------------------------------------------------------
; Title : To interface stepper motor with 8051
; Description : To rotate the stepper motor 360 degree clockwise or
; anticlockwise using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV A,#11H ; initializing starting sequence of the step
MOV R2,#200 ; step count for rotation (200x1.8=360)
UP1:MOV P0,A ; loading the step sequence to port0
LCALL DELAY ; relaxation time for optimum rotation
RR A ; generating the next step sequence
DJNZ R2,UP1
HERE:SJMP HERE

DELAY: ; delay function to give delay between each step rotation


MOV R3,#0FH
HERE2:MOV R4,#0FFH
HERE1:DJNZ R4,HERE1
DJNZ R3,HERE2
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = {(2x255 + 2 + 1)x15 }+ 1
= 7696
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 7696 x 1.086us = 8.36ms

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 15
;---------------------------------------------------------------------------------------------------------------
; Title : To interface Seven segment display with 8051
; Description : To display static message “1234” by interfacing seven segment
; display with 8051, using port 1 as output port for seven
; segment display and port 2 for clock pulses
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H

MOV R1,#04H ;number of segment count


MOV DPTR ,#SEVEN ;look up table for the seven segment code
DISP2:
MOV R0,#08H ;count to make 8 pulses for individual segment
CLR A
MOVC A,@A+DPTR
DISP1:
RL A
MOV P1,A
SETB P2.0 ; P2.0 port provides clock pulses to the seven segment
NOP
NOP ; nop instruction gives 1 machine cycle delay
NOP
CLR P2.0
DJNZ R0,DISP1
INC DPTR
DJNZ R1,DISP2
SJMP $

SEVEN: DB 0F9H,0A4H,0B0H,099H
END

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 16
;---------------------------------------------------------------------------------------------------------------
; Title : To interface DAC with 8051
; Description : To generate a square wave of frequency 1kHz
; by interfacing DAC with 8051, using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
UP: MOV P0, #00H ; Initialize Port 0 to Get 0V
LCALL DELAY ;Delay =(1/Frequency)
MOV P0, #0FFH ;Initialize Port 0 to get Max. Voltage (5V)
LCALL DELAY ; Delay = (1/Frequency)
SJMP UP ;Repeat Continuously

DELAY: MOV R0, #05H ; delay function to give delay=(1/frequency)


RPT2: MOV R1, #02DH
RPT1: DJNZ R1, RPT1
DJNZ R0, RPT2
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = {(2x45 + 2 + 1)x5 }+ 1
= 466
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 466 x 1.086us = 0.506ms

Time period of the square wave = 0.506ms x 2=1ms


Therefore frequency = 1/1m = 1kHz

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 16
;---------------------------------------------------------------------------------------------------------------
; Title : To interface DAC with 8051 to generate a ramp waveform
; Description : To generate a ramp wave of frequency 50Hz
; by interfacing DAC with 8051, using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
MOV P0,#00H ; initialize port 0 as output port
MOV A, #00H ; load initial value of 0 Volt to reg A
UP: MOV P0, A ; load the value to the port 0
INC A ; incrementing reg A to get a ramp( after A=0FF, INC A=> A=00)
LCALL DELAY ; calling delay procedure to generate required frequency
SJMP UP ; repeat continuously

DELAY:
MOV R1, #023H
RPT1: DJNZ R1, RPT1
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure = 2x35 + 1 = 71
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 71 x 1.086us = 0.0771ms

Time period of the ramp wave = 0.0771ms x 255=0.02s


Therefore frequency = 1/0.02m = 50Hz

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 16
;---------------------------------------------------------------------------------------------------------------
; Title : To interface DAC with 8051 to generate a step waveform
; Description : To generate a step wave of frequency 500Hz
; by interfacing DAC with 8051, using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
UP: MOV P0, #00H ; Initialize Port 0 for Value 0V
LCALL DELAY
MOV P0, #33H ; Initialize Port 0 for Value 1V
LCALL DELAY
MOV P0, #99H ; Initialize Port 0 for Value 3V
LCALL DELAY
MOV P0, #0FFH ; Initialize Port 0 for Value 5V
LCALL DELAY
SJMP UP

DELAY:
MOV R0, #05H
RPT2: MOV R1, #02DH
RPT1: DJNZ R1, RPT1
DJNZ R0, RPT2
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure ={( 2x45 + 2+ 1)x5} + 1 = 466
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 466 x 1.086us = 0.5061ms

Time period of the step wave = 0.5061ms x 4=2ms


Therefore frequency = 1/2m = 500Hz

Microprocessor & Microcontroller Application Lab - EC506


Department of Electronics & Communication Engineering, NMAMIT, Nitte

PROGRAM 16
;---------------------------------------------------------------------------------------------------------------
; Title : To interface DAC with 8051 to generate a triangular waveform
; Description : To generate a triangular wave of frequency 1 KHz
; by interfacing DAC with 8051, using port 0 as output port
; Author : Anamika [4NM13EC---]
; Date : 06/11/2015
; College/Dept : NMAMIT/ECE
;---------------------------------------------------------------------------------------------------------------

ORG 00H
CLR A
UP: INC A ;Initialize Port 0 to generate increasing Ramp
MOV P0, A
LCALL DELAY
CJNE A, #0FFH, UP ; compare with 5V then jump to generate decreasing ramp
DOWN: DEC A ; Initialize Port 0 to generate decreasing Ramp
MOV P0, A
LCALL DELAY
CJNE A, #00, DOWN ; compare with 0V then jump to generate increasing ramp
SJMP UP

DELAY:
MOV R0, #00H
MOV R1, #00H
RET
END

DELAY CALCULATION
Total machine cycles required to execute the delay procedure =1+ 1 = 2
1 Machine cycle = 12 clock cycles
Clock frequency of 8051 = 11.0592MHz

 Time Period = (1/11.0592M) = 0.09042us


 1 machine cycle takes 0.09042us x 12 = 1.086us

Therefore total delay produced by the delay procedure = total machine cycles x 1.086us
= 2 x 1.086us = 2.172us

Time period of the triangular wave = 2.172us x 255 x 2=1.1ms


Therefore frequency = 1/1.1m = 909Hz

Microprocessor & Microcontroller Application Lab - EC506

Вам также может понравиться