Beruflich Dokumente
Kultur Dokumente
S.NO.
Page No.
1.
2-3
2.
3-5
3.
5-6
4.
5.
8-9
6.
7.
11-12
8.
9.
13-14
10.
14-15
11.
15
12.
16
13.
16-17
14.
18
I.
LABEL
BACK:
HERE:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV DPH,#80H
MOV R0,#35H
MOV R1,#41H
MOV R3,#0AH
MOV DPL,R0
MOVX A@DPTR
MOV DPL,R1
MOVX @DPTR,A
INC RO
INC R1
DJNZ R3,BACK
SJMP HERE
END
COMMENTS
//Source address
//destination address
//count
RESULT:
Before execution : 10 locations X:8035H are filled up with data
After execution : 10 locations X: 8041H are filled up with data from 8035H.
PROGRAM -2:
AIM: Write an assembly language program to exchange n=5 bytes of data at location
0027H and at location 0041H.
LABEL
BACK:
MNEMONICS
ORG 00H
SJMP 30H
ORG 30H
MOV R0,#27H
MOV R1,#41H
MOV R3,#05H
MOVX A@r0
MOV r2,a
MOVX a,@r1
COMMENTS
//Source address
//destination address
//count
HERE:
MOVX @r0,a
MOV a,r2
MOVX @r1,a
INC RO
INC R1
DJNZ R3,BACK
SJMP HERE
END
BACK:
HERE:
MNEMONICS
ORG 00H
SJMP 30H
ORG 30H
MOV R0,#27H
MOV R1,#41H
MOV R3,#05H
MOVX A@r0
MOV r2,a
MOVX a,@r1
XCH a,r2
MOV @r1,a
XCH a,r2
MOVX @r0,a
INC RO
INC R1
DJNZ R3,BACK
SJMP HERE
END
COMMENTS
//Source address
//destination address
//count
RESULT:Before execution : 5 locations X:0027H & X:0041H are filled up with data
LABEL
L1:
L2:
NOEXCHG:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R0,#05
MOV DPTR,#9000h
MOV A,R0
MOV R1,A
MOVX a, @DPTR
MOV B,A
INC DPTR
MOVX a, @DPTR
CLR C
MOV R2,A
SUBB A,B
JC NOEXCHG
MOV A,B
MOVX @DPTR,a
DEC DPL
MOV a,R2
MOVX @DPTR,a
INC DPTR
DJNZ R1,L2
DJNZ R0,L1
SJMP $
END
COMMENT
PROGRAM-4:
AIM: Write an assembly language program to find the largest element in a given string of n=
6bytes at location 4000h .store the largest element at location 4062h.
LABEL
NEXTBYTE:
SKIP:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R3,#6
MOV DTR,#4000H
MOVX A,@DPTR
MOV r1,a
INC DPTR
MOVX A,@
CLR C
MOV R2,A
SUBB A,R1
JC SKIP
MOV A,r2
MOV R1,A
DJNZ R3,NEXTBYTE
MOV DPL,#62H
MOVA,R1
MOVX @DPTR,A
SJMP $
END
COMMENTS
//length of array
//starting address of array
RESULT:Before Execution:
(II)
ARITHMETIC INSTRUCTIONS :-
PROGRAM -5
AIM: Write an assembly language program the following: If x=0 perform w+v else if x=1
perform w-v; else if x=2 perform w*v, else if x=3 perform w/v, where w &v are eight bit
numbers.
LABEL
SKIP:
CKSUB:
SKIP:
CKMUL:
CKDIV:
OTHER:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R0,#40H
MOVX A,@R0
MOV R1,A
INC R0
MOVX A,@R0
MOV B,A
INC R0
MOVX A,@R0
CJNE R1,#00,CKSUB
ADD A,B
MOV B,#00
JNC SKIP
MOV B,#01H
SJMP LAST
CJNE R1,#01,CKMUL
CLR C
SUBB A,B
MOV B,#00
JNC SKIP1
MOV B,#0FFH
SJMP LAST
CJNE R1,#02,CKDIV
MUL AB
SJMP LAST
CJNE R1,#03,OTHER
DIV AB
SJMP LAST
MOV A,#00
MOV,B#00
8
COMMENTS
//perform addition
//B has carry
LAST:
HERE:
INC R0
MOVX @R0,A
INC R0
MOVX @R0,A
INC R0
MOV A,B
MOVX @R0,A
SJMP HERE
END
RESULT:
Before Execution: ADD
After Execution : ADD
Before Execution : MUL
SUB
After Execution : SUB
After Execution : MUL
PROGRAM -6:
AIM : An eight bit number X is stored in external memory location 9000h. write an ALP to
compute (1)the square of the number X if LSB of data RAM 20H(bit address01H)is set (2) the
cube of the number X if LSB of data RAM 20H(bit address 01H) is reset. Store your result at
location 9001, 9002, 9003H.
LABEL
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV R0,A
MOV B,A
MUL AB
CLR C
JB 01,LAST
COMMENT
//get number X
//store in R0
//square it X^2
//for storing result
//if bit 01 is set then END, else do
cube
//store upper part of square
//B-lower part of X2
// A-X
//X*LOWER X^2
PUSH B
MOV B,A
MOV A,R0
MUL AB
INC DPTR
MOVX @DPTR,A
MOV A,B
MOV R2,A
POP B
LAST:
MOV A,R0
MUL AB
ADD A,R2
INC DPTR
MOVX @DPTR,A
MOV A,B
ADDC A,#00
INC DPTR
MOVX @DPTR,A
SJMP $
END
10
RESULT:
CUBE of 56H is 9B498 which is stored as 98,B4,09 (Lower Byte First)
To get SQUARE make the D1 bit of data memory 20H high ,say FF,02,06 etc. The bit address is
01 .similarly bit address 78H correspond to D0 bit of data RAM location 2FH.
LABEL
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV DPTR,#8000H
MOVX A,@DPTR
MOV R0,A
INC DPTR
MOVX A,@DPTR
CLR C
SUBB A,R0
COMMENTS
11
JZ EQUAL
JNC BIG
SETB 78H
SJMP END1
SETB 7FH
SJMP END1
CLR 77H
CLR 7FH
SJMP END1
END
BIG:
EQUAL:
END1:
RESULT:
1. Before Execution : X : 08000H = 45 & X :8001 = 35
After Execution: D : 02FH = 01
2. Before Execution : X : 08000H = 25 & X :8001 = 35
After Execution: D : 02FH = 80
3. Before Execution: X : 08000H = 45 & X :8001 = 45
After Execution: D : 02FH = 00
(III)
COUNTERS
PROGRAM -8
AIM: Write an ALP to implement (display) an eight bit up/down binary (hex) counters on watch
window.
LABEL
MNEMONICS
ORG 0H
SJMP 30H
ORG 0H
MOV a,#00
COMMENTS
12
BACK:
HERE:
DELAY:
DECR1:
DECR:
ACALL DELAY
INC a
JNZ BACK
SJMP HERE
MOV r1,#0FFH
MOV r2,#0FFH
MOV r3,#0FFH
DJNZ r3,$
DJNZ r2,DECR
DJNZ r1,DECR1
RET
END
RESULT:
Acccumulator A is incremented in binary from 00, 01, 02,. . . . . . 09, 0A, 0B,. . . ,0F, 10,
11, . . . FF.
PROGRAM -9
AIM: Write an ALP to implement (display) an eight bit up/down BCD counters on watch
window.
LABEL
HERE:
MNEMONICS
ORG 0H
SJMP 30H
ORG 30H
MOV a,#00
ACALL DELAY
ADD a,#99H
DA A
JNZ BACK
SJMP HERE
DELAY:
MOV r1,#0FFH
BACK:
COMMENTS
13
DECR1:
DECR:
MOV r2,#0FFH
MOV r3,#0FFH
DJNZ r3,$
DJNZ r2,DECR
DJNZ r1,DECR1
RET
END
RESULT:
Acccumulator A is incremented in BCD from 00, 01, 02,. . . . . . 09, 10, 11,. . . ,99.
PROGRAM-10:
AIM: Write an ALP to implement decimal to hex conversion.
LABEL
HERE:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV DPTR,#40H
MOVX A,@DPTR
ANL A,#0F0H
SWAP A
MOV B,#0AH
MUL AB
MOV r1,a
MOVX A,@DPTR
ANL A,#0FH
ADD A,R1
INC DPTR
MOVX @DPTR,A
SJMP HERE
END
COMMENTS
14
RESULT:
Before Execution: X:0040H=45(Decimal/BCD)
After Execution: X:0041H=2D(hex value)
PROGRAM -11:
AIM: Write an ALP to implement hex to decimal conversion.
LABEL
HERE:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV DPTR,#9000H
MOVX A,@DPTR
MOV B,#10
DIV AB
INC DPTR
XCH A,B
MOVX @DPTR,A
XCH A,B
MOV B,#10
DIV AB
INC DPTR
XCH A,B
MOVX @DPTR,A
XCH A,B
INC DPTR
MOVX @DPTR,A
SJMP HERE
END
COMMENTS
15
PROGRAM-12
AIM: Write an ALP to implement BCD to ASCII conversion.
LABEL
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R1,#50H
MOV A,@R1
MOV R2,A
ANL A,#0FH
ORL A,#30H
INC R1
MOV @R1,A
MOV A,R2
SWAP A
ANL A,#0FH
ORL A,#30H
INC R1
MOV @R1,A
SJMP HERE
END
HERE:
COMMENTS
RESULT:
The BCD code 28 at D : 0050H is converted to 2 ASCII codes- 38H 32H
PROGRAM -13:
AIM: Write an ALP to implement Hexadecimal to ASCII conversion.
//This program also illustrates conditional branching (JNC), call and return instructions.
16
LABEL
ASCII:
SKIP:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R1,#50H
MOV A,@R1
MOV R2,A
ANL A,#0FH
ACALL ASCII
INC R1
MOV @R1,A
MOV A,R2
SWAP A
ANL A,#0FH
ACALL ASCII
INC R1
MOV @R1,A
SJMP $
MOV R4,A
CLR C
SUBB A,#0AH
MOV A,R4
JNC SKIP
ADD A,#07H
ADD A,#30H
RET
END
COMMENTS
//Store a
//Check if digit>=0A
//Add 07 if>09
//Else add only30H for 0-9
RESULT: The BCD code 2C at D : 0050H is converted to 2 ASCII codes- 43H (for 0C) & 32H (for
02)
Another Example BA
17
PROGRAM-14
AIM: Write an ALP to implement ASCII to Hexadecimal conversion.
LABEL
SKIP:
MNEMONICS
ORG 0000H
SJMP 30H
ORG 30H
MOV R1,#50H
MOV A,@R1
CLR C
SUBB A,#41H
MOV A,@R1
JC SKIP
CLR C
SUBB A,#07H
CLR C
SUBB A,#30H
INC R1
MOV @R1,A
SJMP $
END
COMMENTS
RESULT:
The ASCII code 45 at D : 0050H is converted to hexadecimal -0E at 51H.
18