Implement an assembly language program to print sum of first “n” natural numbers,check even or odd,prime,“exchange data blocks of 10 Bytes,Move a block of data from one memory location,“Addition of Array of numbers”. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Friday 8 May 2020

Implement an assembly language program to print sum of first “n” natural numbers,check even or odd,prime,“exchange data blocks of 10 Bytes,Move a block of data from one memory location,“Addition of Array of numbers”.

1. Implement an assembly language program to print sum of first “n”
natural numbers.
ANS→
MOV A,#07H
MOV B,A
INC A
MUL AB
MOV B,#02H
DIV AB
MOV R2,A

2. Write an assembly language program to check whether the given
the number is EVEN or ODD.
ANS→
MOV A,#07H
RRC A
JC ODD
MOV A,#00H
SJMP EVEN
ODD: MOV A,#01H
EVEN:NOP

3. Implement an assembly language program to check whether the given
number is prime or not.
ANS→

MAIN:    MOV R2,#11          ; 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 falg to 0 if it not a prime number
LABEL4:NOP
 END

4. Write an assembly language program for “Addition of Array of numbers”
in Edsim51.
ans-->
MOV A,#00H
MOV @R0,40H
MOV R1,#0AH
LOOP:
ADD A,@R0
INC R0
DJNZ R1,LOOP

5. Move a block of data from one memory location to others where memoryis addressed
through the indirect mode in both overlapping and non-overlapping case.
ans-->

WITHOUT OVERLAPPING

MOV @R0,40H
MOV R1,#0AH
MOV @R2,60H
LOOP:
MOV @R2,@R0
INC R0
INC R2
DJNZ R1, LOOP

WITH OVERLAPPING
MOV @R0,50H
MOV R1,#0AH
MOV @R2,5FH
LOOP:
MOV @R2,@R0
DEC R0
DEC R2

DJNZ R1, LOOP



6. Implement an assembly language program to “exchange data blocks of 10 Bytes”.
MOV R0,#20H
MOV R1,#30H
MOV R2,#0AH
UP:
MOV A,@R0
XCH A,@R1
MOV @R0,A
INC R0
INC R1
DJNZ R2,UP
RET