Assignment – 4
Name:-Krishna Sah
Group:-CS-B1
Reg No:-20194190
Keil Embedded C:
Q1. Implement an assembly language program to check whether the given
number is prime or not.
;To check if number is prime
LJMP MAIN
MAIN: MOV R2,#3; Loading the number to be checked whether it's a prime or
not
LABEL5: MOV A,R2
MOV B,#02
DIV AB ;Dividing the number by 2
MOV R0,A
CJNE R0,#01H,LABEL2 ;Checking whether the number is 2
SETB C
SJMP LABEL4
LABEL1: DEC R0 ; decrementing and checking whether the number is not
divisible by all possible values of number/2
CJNE R0,#01H,LABEL2
SETB C ; setting the carry flag to 1 if it is a prime number
SJMP LABEL4
LABEL2: MOV A,R2
MOV B,R0
DIV AB
MOV R3,B
CJNE R3,#0H,LABEL1
CLR C ; setting the carry flag to 0 if it not a prime number
LABEL4:
END
Q2. Move a block of data from one memory location to another where memory
is addressed through indirect mode in both overlapping and non overlapping
cases.
NON-OVERLAPPING
MOV R2,#05h; N value
MOV R0,#30h;source add
MOV R1,#40h;dest add
loop:
MOV A,@R0
MOV @R1,A
INC R1
INC R0
DJNZ R2, loop
END
OVERLAPPING
MOV R1,#30h;starting add
MOV R2,#38h;ending add
MOV R0,#35h;starting add
CLR C
MOV A,R2
SUBB A,R1
MOV R2,A
MOV A,R1
ADD A,R2
MOV R1,A
MOV A,R0
ADD A,R2
MOV R0,A
INC R2 loop:
MOV A,@R1
MOV @R0,A
DEC R1
DEC R0
DJNZ R2, loop
END
Q3. Write an assembly language program to transfer N = ___ bytes of data
from location
A: _______H to location B: _______H.
Where, N, A and B are: N = 05H, A: 30H B: 40H
MOV R2,#05h; N value
MOV R0,#30h;source add
MOV R1,#40h;dest add
loop:
MOV A,@R0
MOV @R1,A
INC R1
INC R0
DJNZ R2, loop
END
Q4. Write an assembly language program to exchange 05H bytes of data at
location 30H and 40H.
MOV R2,#05h; N value
MOV R0,#30h;source add
MOV R1,#40h;dest add
loop:
MOV A,@R0
MOV R3,A
MOV A,@R1
MOV @R0,A
MOV A,R3
MOV @R1,A
INC R1
INC R0
DJNZ R2, loop
END