Statement:: Source Program 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Statement: Calculate the sum of series of numbers.

The length of the series is in memory


location 4200H and the series begins from memory location 4201H.

a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location

4300H.

b. Consider the sum to be 16 bit number. Store the sum at memory locations 4300H and 4301H.

Sample problem 1:

4200H  = 04H

4201H  = 10H

4202H  = 45H

4203H  = 33H

4204H  = 22H

Result = 10 +41 + 30 + 12 =  H

4300H  =  H

Flowchart for Source program1

Source program 1:
LDA 4200H

MOV C, A : Initialize counter

SUB A : sum = 0

LXI H, 420lH : Initialize pointer

BACK: ADD M : SUM = SUM + data

INX H : increment pointer

DCR C : Decrement counter

JNZ BACK : if counter  0 repeat

STA 4300H : Store sum

HLT : Terminate program execution


Sample problem 2:

4200H =  04H

420lH  = 9AH
4202H = 52H

4203H = 89H

4204H = 3EH

Result = 9AH + 52H + 89H + 3EH = H

4300H = B3H Lower byte

4301H = 0lH Higher byte

Source program 2
LDA 4200H

MOV C, A : Initialize counter

LXI H, 4201H : Initialize pointer

SUB A :Sum low = 0

MOV B, A : Sum high = 0

BACK: ADD M : Sum = sum + data

JNC SKIP

INR B : Add carry to MSB of SUM

SKIP: INX H : Increment pointer

DCR C : Decrement counter

JNZ BACK : Check if counter 0 repeat

STA 4300H : Store lower byte

MOV A, B

STA 4301H : Store higher byte

HLT :Terminate program execution

Statement: Multiply two 8-bit numbers stored in memory locations 2200H and 2201H by
repetitive addition and store the result in memory locations 2300H and 2301H.

Sample problem 1:

(2200H) = 03H

(2201H) = B2H
Result = B2H + B2H + B2H = 216H

               = 216H

(2300H) = 16H

(2301H) = 02H

Flowchart for program

Source program :
 LDA 2200H
 MOV E, A
 MVI D, 00 : Get the first number in DE
register pair
 LDA 2201H
 MOV C, A : Initialize counter
 LX I H, 0000 H : Result = 0
 BACK: DAD D : Result = result + first
number
 DCR C : Decrement count
 JNZ BACK : If count    0 repeat
 SHLD 2300H : Store result
 HLT : Terminate program execution

Statement: Program to shift a 16-bit data 1 bit left. Assume data is in the HL register

Source Program

Add each element of array with the elements of another array

Statement: Two decimal numbers six digits each, are stored in BCD package form. Each

number occupies a sequence of byte in the memory. The starting address of first number is

6000H Write an assembly language program that adds these two numbers and stores the sum in

the same format starting from memory location 6200H.


Source program : Flowchart for program

 LXI H, 6000H : Initialize pointer l to first number


 LXI D, 6l00H : Initialize pointer2 to second number
 LXI B, 6200H : Initialize pointer3 to result
 STC
 CMC : Carry = 0
 BACK: LDAX D  : Get the digit
 ADD M  : Add two digits
 DAA : Adjust for decimal
 STAX.B : Store the result
 INX H : Increment pointer 1
 INX D  : Increment pointer2
 INX B : Increment result pointer
 MOV A, L
 CPI 06H : Check for last digit
 JNZ BACK  : If not last digit repeat
 HLT : Terminate program execution 

Statement: Write an assembly language program to convert the contents of the five memory
locations starting from 2000H into an ASCII character. Place the result in another five memory
locations starting from 2200H.

Sample Problem

       (2000H) = 1

       (2001H) = 2

       (2002H) = 9

       (2003H) = A

       (2004H) = B

       Result:(2200H) = 31

               (2201H) = 32

               (2202H) = 39

               (2203H) = 41

               (2204H) = 42

Source program:

       LXI SP, 27FFH        : Initialize stack pointer


       LXI H, 2000H        : Source memory pointer

       LXI D, 2200H        : Destination memory pointer

       MVI C, O5H                : Initialize the counter

BACK: MOV A, M                : Get the number

       CALL ASCII                : Call subroutine ASCII

       STAX D                : Store result

       INX H                        : Increment source memory pointer

       INX D                        : Increment destination memory pointer

       DCR C                : Decrement count by 1        

       CJNZ                        : if not zero, repeat

       HLT                        : Stop program execution subroutine ASCII

ASCII: CPI, OAH                : Check if number is OAR

       JNC NEXT                : If yes go to next otherwise continue

       ADI 30H

       JMP LAST

NEXT: ADI 37H

LAST: RET                        : Return to main program

You might also like