Assembly Language Programs
Assembly Language Programs
Assembly Language Programs
Program:
ORG 00H
MOV A, R2
ADD A, R3
MOV R4, A
END
C] AIM: Suppose two bytes are stored in memory
locations 3000H and 3001H. Add two numbers
from external memory locations and store the
result in memory location 3002H of external
memory.
Algorithm:
Step 1: Start
Step 2: Initialize memory pointer using DPTR register
with 3000H
Step 3: Load the 1st number from memory
location 3000H.
Step 4: Increment memory pointer by 1.
Step 5: Load the 2nd number from memory
location 3001H.
Step 6: Add both numbers
Step 7: Store the result in memory location 3002H by
incrementing memory pointer
Step 8: Stop.
Flowchart:
Program:
ORG 0000H
MOV DPTR, #3000H
MOVX A, @DPTR
MOV R0, A
INC DPTR
MOVX A, @DPTR
ADD A, R0
INC DPTR
MOVX @DPTR, A
END
3) SUBTRACTION OF TWO 16
BIT NUMBERS
AIM: Assume two 16 bit numbers 1234H and
4321H stored in internal bank registers
R0,R1,R2 and R3. After Subtraction, store
the result in R4 and R5.
Program:
ORG 00H
MOV A, R0
SUBB A, R2
MOV R4, A
MOV A, R1
SUBB A, R3
MOV R5, A
END
PROGRAM:
ORG 00H
MOV R0, #0AH
MOV R1, #50H
MOV A, #00H
UP: ADD A, @R1
INC R1
DJNZ R0, UP
MOV @R1, A
END
AIM:
Write an ALP for performing addition of three 8
bit numbers stored in internal RAM location from
60H, 61H and 62H. Store the carry and sum at
63H and 64H location. (Assume data)
PROGRAM:
ORG 00H
MOV R0, #03H
MOV R1, #60H
MOV A, #00H
MOV R7, #00H
UP: ADD A, @R1
JNC NEXT
INC R7
NEXT: INC R0
DJNZ R2, UP
MOV 63H, A
MOV 64H, R7
END
AIM:
Write an ALP to calculate sum of five consecutive
numbers stored in internal RAM location from
20H. Store the lower byte at memory location 25H
and higher byte at 26H.
PROGRAM:
ORG 00H
MOV R0, #05H
MOV R1, #20H
MOV A, #00H
MOV R7, #00H
UP: ADDC A, @R1
JNC NEXT
INC R7
NEXT: INC R1
DJNZ R0, UP
MOV @R1, A
INC R1
MOV A, R7
MOV @R1, A
END
PROGRAM:
ORG 00H
MOV R0, #0AH ; Initialize byte counter
PREPARED BY: SNEHAL
GORDE
MOV R1,#20H ; Initialize memory pointer
DEC R0 ; Decrement byte counter by 1
MOV 60H, @R1 ; Store the no. in memory location 60H
UP: INC R1 ; Increment memory pointer by 1
MOV A, @R1 ; Read the next no.
CJNE A,60H,HERE ; If 1st no.is not = next no.,then go to
HERE
AJMP NEXT ; Orelse go to next
HERE: JC NEXT ; If next no. is < than 1st no. then go to
NEXT
MOV 60H,A ; Orelse replace next no.with 1st no.
NEXT: DJNZ R0,UP ; Decrement byte counter by 1,if
byte counter is not = 0,then go to UP
END
PROGRAM:
ORG 00H
MOV R0, #0AH ; Initialize byte counter
MOV DPTR, #3000H ; Initialize memory pointer
DEC R0 ; Decrement byte counter by 1
MOVX A, @DPTR ; Load the number in accumulator
MOV 40H, A ; Store the no. in memory location 40H
PREPARED BY: SNEHAL
GORDE
UP: INC DPTR ; Increment memory pointer by 1
MOVX A, @DPTR ; Read the next no.
CJNE A,40H,HERE ; If 1st no.is not = next no.,then go to
HERE
AJMP NEXT ; Orelse go to next
HERE: JC NEXT ; If next no. is < than 1st no. then
go to NEXT
MOV 40H,A ; Or else replace next no.with 1st no.
NEXT: DJNZ R1,UP ; Decrement byte counter by 1,if
byte counter is not=0,then go to UP
INC DPTR ; Increment memory pointer by 1
MOV A, 40H
MOVX @DPTR, A ; Store the result in external memory
END
PROGRAM:
ORG 00H
MOV R0, #0AH ; Initialize byte counter
MOV R1, #20H ; Initialize memory pointer
DEC R0 ; Decrement byte counter by 1
MOV 60H, @R1 ; Store the no. in memory location 60H
UP: INC R1 ; Increment memory pointer by 1
PREPARED BY: SNEHAL
GORDE
MOV A, @R1 ; Read the next no.
CJNE A,60H,HERE ; If no.is not = next no.,then go to
HERE
AJMP NEXT ; Or else go to next
HERE: JNC NEXT ; If next no. > than 1st no. then go
to NEXT
MOV 60H,A ; Or else replace next no. with 1 no.
st
PROGRAM:
ORG 00H
MOV R0, #0AH ; Initialize byte counter
MOV DPTR, #3000H ; Initialize memory pointer
DEC R0 ; Decrement byte counter by 1
MOVX A, @DPTR ; Load the number in accumulator
MOV 40H, A ; Store the no. in memory location 40H
UP: INC DPTR ; Increment memory pointer by 1
MOVX A, @DPTR ; Read the next no.
CJNE A,40H,HERE ; If 1st no.is not = next no.,then go to
HERE
PREPARED BY: SNEHAL
GORDE
AJMP NEXT ; Or else go to next
HERE: JNC NEXT ; If next no. is > than 1st no. then
go to NEXT
MOV 40H,A ; Orelse replace next no.with 1st no.
NEXT: DJNZ R1,UP ; Decrement byte counter by 1,if
byte counter is not = 0,then go to UP
INC DPTR ; Increment memory pointer by 1
MOV A, 40H
MOVX @DPTR, A ; Store the result in externalmemory
END
BLOCK EXCHANGE
AIM:
Write an ALP for exchanging block of 10 bytes stored in internal
RAM location from address 40H. Starting address of destination
block is 50H.
PREPARED BY: SNEHAL
GORDE
PROGRAM:
ORG 00H
MOV R3, #0AH ; Initialize byte counter
MOV R0, #40H ; Initialize memory pointer for source
array
MOV R1, #50H ; Initialize memory pointer for
destination array
UP: XCH A, @R0 ; Read first no.from source Array
XCH A, @R1 ; Read first no.from destination array
XCH A, @R0 ; Exchange source and dest. array
INC R0 ; Increment source memory pointer
by 1
INC R1 ; Increment dest. memory pointer
by 1
DJNZ R3, UP ; Decrement byte counter, if byte
counter is not= 0, then go to UP
END ; Stop