0% found this document useful (0 votes)
2 views

ass2

The document contains solutions to five assembly programming assignments related to embedded systems. Each question includes assembly code for tasks such as calculating the sum of natural numbers, checking if a number is even or odd, summing numbers in an array, summing even numbers less than a given number, and performing arithmetic operations on 16-bit numbers. The document provides the necessary code snippets and comments for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ass2

The document contains solutions to five assembly programming assignments related to embedded systems. Each question includes assembly code for tasks such as calculating the sum of natural numbers, checking if a number is even or odd, summing numbers in an array, summing even numbers less than a given number, and performing arithmetic operations on 16-bit numbers. The document provides the necessary code snippets and comments for clarity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Embedded System

Lab
ASSIGNMENT 2 SOLUTION

Vaibhav Vardhan Tyagi


REG NO :- 20223302
Ques1: Write the assembly program to print the sum of n natural
numbers.

MOV A, #00H
MOV R1, 10H; Location where n is stored
MOV R3, #00H
AGAIN: ADD A, R1
JNC CARRY
INC R3
CARRY: DJNZ R1, AGAIN
MOV 21H, A; Result
MOV 20H, R3; Carry
Here: SJMP here;

Output:

Ques2: Write the assembly program to check whether the given


number is EVEN or ODD.
MOV A, 20H; Input value at location 10H
RRC A
JNC EVEN
MOV 30H, #01H; if odd
SJMP Here;
EVEN: MOV 20H, #00H; if even
Here: SJMP here;
Output:
Ques3: Implement an assembly program to print the sum of the
numbers given in an Array.

CLR PSW.3 ; Clear carry flag


CLR PSW.4 ; Clear auxiliary carry flag
CLR PSW.7 ; Clear overflow flag
MOV R3, #00H ; Initialize R3 to 0 (count for carries)
MOV R0, #0AH ; Set loop counter R0 to 10 (hexadecimal)
MOV R1, #40H ; Set pointer R1 to starting address 30H
MOV A, #00H ; Initialize accumulator A to 0
UP: ADDC A, @R1 ; Add value at address R1 to A with carry
JNC NEXT ; If no carry, jump to NEXT
INC R3 ; Increment R3 if there's a carry
NEXT: INC R1 ; Increment pointer R1
DJNZ R0, UP ; Decrement R0 and repeat UP if not zero
MOV @R1, A ; Store result in memory at R1
INC R1 ; Increment R1 to next address
MOV A, R3 ; Move carry count to accumulator A
MOV @R1, A ; Store carry count at R1
Here: SJMP Here ; Infinite loop to hold the program

Output:

Ques4: Write the assembly program to print the sum of all even
numbers less than “N” where “N” is a given positive number.

MOV R0, #10H


MOV A, #00H
MOV R1, #02H
LOOP: CJNE R0, #00H, ADDLOOP
SJMP LAST
ADDLOOP: ADD A, R1
INC R1
INC R1
DEC R0
DEC R0
SJMP LOOP
LAST: MOV 10H, A
HERE: SJMP HERE

Output:

Ques5: Write the assembly program for addition, subtraction and


multiplication of two 16-bit numbers.

 Addition
MOV A, 21H
ADD A, 11H
MOV 31H, A
MOV A, 20H
ADDC A, 10H
MOV 30H, A
JNC SKIP
INC R2
SKIP:MOV 40H, R2
HERE: SJMP HERE

Output:
 Subtraction
MOV A, 21H
SUBB A, 11H
MOV 31H, A
MOV A, 20H
SUBB A, 10H
MOV 30H, A
JNC SKIP
INC R2
SKIP: MOV 40H, R2
HERE: SJMP HERE

Output:

 Multiplication
; 16-BIT MULTIPLICATION
MOV 30H, #0FFH
MOV 31H, #0FFH
MOV 40H, #0FFH
MOV 41H, #0FFH

MOV A, 31H
MOV B, 41H
MUL AB
MOV 53H, A
MOV 52H, B

MOV A, 30H
MOV B, 40H
MUL AB
MOV 51H, A
MOV 50H, B

MOV A, 31H
MOV B, 40H
MUL AB
ADD A, 52H
MOV 52H, A
MOV A, B
ADDC A, 51H
MOV 51H, A
JNC SKIP
INC 50H
SKIP:

CLR C
MOV A, 30H
MOV B, 41H
MUL AB
ADD A, 52H
MOV 52H, A
MOV A, B
ADDC A, 51H
MOV 51H, A
JNC SKIP2
INC 50H
SKIP2:

SJMP $

Output:

You might also like