You are on page 1of 24

ALP & MP Lab Program List

BCA505P: ASSEMBLY LANGUAGE PROGRAMMING LAB

PART – A
Sl. No. Name of Program Page No.
1. Write an ALP to do Exchange of two 16 bit numbers. 04
2. Write an ALP to do Addition of two-8bit Binary numbers. 05
3. Write an ALP to do Subtraction of two-16bit numbers. 06
4. Write an ALP to do Addition of ‘N’-1byte Binary numbers. 07
5. Write an ALP to do Block Transfer of data (Direct Order). 08
6. Write an ALP to find 1’s complement of a 16bit number. 09
7. Write an ALP to find smallest of ‘N’-1byte HEX numbers. 10
8. Write an ALP to Simulate Decimal Counter from 00 to 99. 11
9. Write an ALP to do Addition of all even no’s in a given series. 12
10. Write an ALP to do Multiplication of 2 digit BCD number. 13

PART – B
Sl. No. Name of the Program Page No.
11. Write an ALP to do Exchange of two 32 bit numbers. 14
12. Write an ALP to do Addition of two-2digit Decimal numbers. 15
13. Write an ALP to do Addition of two-16 bit numbers. 16
14. Write an ALP to do Subtraction of ‘N’-1byte Binary numbers. 17
15. Write an ALP to do Block Transfer of data (Reverse Order). 18
16. Write an ALP to find 2’s complement of a 16bit number. 19
17. Write an ALP to find largest of ‘N’-1byte HEX numbers. 20
18. Write an ALP to Simulate Binary Counter from 00 to FF. 21
19. Write an ALP to do Addition of all Odd no’s in a given series. 22
20. Write an ALP to do Multiplication of 2-1byte Binary numbers. 23
GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

Accumulator (8bit) Status Flags (8bit)

B Register (8bit) C Register (8bit)

D Register (8bit) E Register (8bit)

H Register (8bit) L Register (8bit)

Stack Pointer - SP (16bit)

Program Counter - PC (16bit)

Data Bus Address Bus

Programming model: It is a Model to understand and write assembly programs.


To perform internal operations, processor requires 3 components:
1) REGISTERS, 2) ALU and 3) CONTROL LOGIC.
The hardware model has two major segments: 1) ALU and Accumulator, 2)
Registers (8/16bit). Both are connected to each other by internal bus.
ALU performs arithmetic (Addition, Subtraction) & logical (AND, OR & X-OR)
operations. Results are stored in Accumulator & Flags. Flags are set/reset to reflect the
results.
GPR’s: They are General Purpose Registers used to perform operations (store 8bit
data during program execution. It has six registers B, C, D, E, H and L for 8bit operations;
it can be used as 3 register-pair B-C, D-E, H-L for 16bit operations), along with 2 special
purpose registers PC (Program Counter) & SP (Stack Pointer) each of 16bit. They are
programmable and used to load, copy, store or perform arithmetic & logical operations
needed by the programmer.
Accumulator (A): It is 8bit register that is part of ALU. The result of an operation
is stored in it. This register is used to perform arithmetic and logical operations. It is
identified as ‘A’ register.

ALP Lab Manual Page |2 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES
Status Flags: Group of flip-flops used to test data conditions during any arithmetic
& logical operations with accumulator or other registers. They are Carry flag (CY), Zero
flag (Z), Sign flag (S), Parity flag (P) & Auxiliary Carry flag (AC).

D7 D6 D5 D4 D3 D2 D1 D0

S Z -- AC -- P -- CY

Flag Set Reset

Carry (CY) 1 (if excess) 0 (if ≠ excess)

Zero (Z) 1 (if Res=0) 0 (if Res ≠ 0)

Sign (S) 1 (if D7=1) (-ve) 0 (if D7 = 0) (+ve)

Parity (P) 1 (if even 1’s) 0 (if odd 1’s)

Aux Carry (AC) 1 (if D3=>D4) 0 (if D3 ≠ D4)

The status flags + Accumulator is known as PSW (Program Status Word). It is


used to branch or decision making process by the programmer based upon condition.

Program Counter (PC): It is a 16bit register used to hold memory address to


sequence the execution of instructions. It points to memory address from which next byte
is to be fetched. The Lower byte is PL, Higher byte is PH.

Stack Pointer (SP): It is a 16bit register used to point to memory address where
stack area begins (top). It points to a memory location in R/W memory (STACK). The
Lower byte is SPL, Higher byte is SPH. It is used in PUSH & POP instruction.

PROCEDURE To STORE Input, View Output and To RUN the PROGRAM

1. To Store the Program code:

Reset  Exam Memory  Start Address of Program  Next  Enter 1st Op-code
 Next  …….  Enter Last Op-code  Next.

2. To Enter the Input (data):

Reset  Exam Memory  Input Address  Next  Enter 1st value  Next …….
 Enter Last value  Next.

3. To Run or Execute the program:

Reset  Go  Start Address of Program  Execute.

4. To View the Output (data):

Reset  Exam Memory  Output Address  Next  View 1st value  Next …….
 View Last value  Next.

ALP Lab Manual Page |3 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 1. WRITE AN ALP TO DO EXCHANGE OF TWO-16BIT NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8600 to L
8000 2A 00 86 LHLD 8600
and 8601 to H register.
Exchange (Store contents of
8003 EB XCHG
HL into DE). HL  DE.
Load contents of 8700 to L
8004 2A 00 87 LHLD 8700
and 8701 to H register.
Store contents of L to 8600
8007 22 00 86 SHLD 8600
and H to 8601 location.
Exchange (Store contents of
800A EB XCHG
DE into HL). DE  HL.
Store contents of L to 8700
800B 22 00 87 SHLD 8700
and H to 8701 location.
800E 76 HLT End of the program.

INPUT: OUTPUT:

8600 3B 8700 3E 8600 3E 8700 3B

8601 AB 8701 FE 8601 FE 8701 AB

ALP Lab Manual Page |4 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 2. WRITE AN ALP TO DO ADDITION OF TWO-8BIT BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

9000 21 00 86 LXI H, 8600H Initialize HL as I/P Pointer.

9003 7E MOV A, M Get the 8bit no. into Acc.

9004 23 INX H Increment pointer by 1.

9005 86 ADD M Add Acc with M => Acc

9006 32 00 87 STA 8700H Store the Sum to 8700.

9009 3E 00 MVI A, 00H Initialize Acc with 00.

900B 8F ADC A Get the Carry into Acc.

900C 32 01 87 STA 8701H Store the Carry into 8701.

900F 76 HLT End of the program.

9000 3E 30 MVI A, 30H

9002 06 08 MVI B, 08H


Program to Add two bytes
9004 80 ADD B stored to Reg A and Reg and
store result at 8700H (Sum).
9005 32 00 87 STA 8700H
Get the carry into Acc &
9008 3E 00 MVI A, 00H store the carry into memory
locations 8701H (Carry out).
900A 8F ADC A

900B 32 01 87 STA 8701H

900E 76 HLT End of the program

INPUT: 1st 2nd OUTPUT: 1st 2nd

8600 30 8600 56 8700 38 8700 4B

8601 08 8601 F5 8701 00 8701 01

ALP Lab Manual Page |5 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 3. WRITE AN ALP TO DO SUBTRACTION OF TWO-16BIT BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8600 to L
8500 2A 00 86 LHLD 8600H
and 8601 to H register.
Exchange (Store contents of
8503 EB XCHG
HL into DE). HL  DE.
Load contents of 8700 to L
8504 2A 00 87 LHLD 8700H
and 8701 to H register.
8507 7B MOV A, E Get 1st byte of 16bit to Acc.
Subtract the 1st byte of both
8508 95 SUB L
no’s & store into Acc.
8509 6F MOV L, A Store back to L register.

850A 7A MOV A, D Get 2nd byte of 16bit to Acc.


Subtract 2nd byte of both
850B 9C SBB H
no’s & store into Acc.
850C 67 MOV H, A Store back to H register.
Store L contents to 8800 &
850D 22 00 88 SHLD 8800H
H to 8801 location.
8510 3E 00 MVI A, 00H Initialize Acc with 00.

8512 9F SBB A Get the Borrow into Acc.

8513 32 02 88 STA 8802H Store Acc contents to 8802.

8516 76 HLT End of the program.

INPUT: 1st 16bit 2nd 16bit OUTPUT:

8600 2A 8700 43 8800 E7


8601 96 8701 5B 8801 3A
1ST 16 BIT NUM: 96 2A 8802 00
ND
2 16 BIT NUM: 5B 43
DIFF (RESULT) 00 3A E7

ALP Lab Manual Page |6 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 4. WRITE AN ALP TO DO ADDITION OF ‘N’-1BYTE BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8200 21 00 85 LXI H, 8500H Initialize HL as Pointer.

8202 0E 04 MVI C, 04H Set C = 04H as Counter.

8205 06 00 MVI B, 00H Clear B reg to store carry.

8207 7E MOV A, M Get the 1st no to Acc.

8208 23 L1: INX H Increment pointer by 1.

8209 86 ADD M Add Acc + M, Sum to Acc.

820A D2 0E 82 JNC L2 Jump if CY=0 to loop L2.

820D 04 INR B Increase the B reg by 1.

820E OD L2: DCR C Decrease the Count by 1.

820F C2 08 82 JNZ L1 Jump if Z=0 to loop L1.

8212 32 00 87 STA 8700H Store the Sum into 8700.

8215 78 MOV A, B Get carry from B reg to Acc.

8216 32 01 87 STA 8701H Store the Carry into 8701.

8219 76 HLT End of the program.

INPUT: OUTPUT: 30
8500 => 30 8700 3F 22
8501 => 22 8701 01 10
8502 => 10 2A
8503 => 2A B3
8504 => B3 01 3F

ALP Lab Manual Page |7 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 5. WRITE AN ALP TO DO BLOCK TRANSFER OF ‘N’ BYTES OF DATA (DIRECT ORDER).

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8200 21 00 85 LXI H, 8500H Load HL as input Pointer.

8203 11 00 86 LXI D, 8600H Load DE as output Pointer.

8206 06 0A MVI B, 0AH Set B reg as Counter.

8208 7E L1: MOV A, M Get the number to Acc.

8209 12 STAX D Store to DE pointed ML.

820A 23 INX H Increase the HL pair by 1.

820B 13 INX D Increase the DE pair by 1.

820C 05 DCR B Decrease the Count by 1.

820D C2 08 82 JNZ L1 Jump if Z=0 to L1 (Loop).

8210 76 HLT End of the program.

INPUT: OUTPUT:

8500  30 8600  30
8501  45 8601  45
8502  6E 8602  6E
8503  2B 8603  2B
8504  38 8604  38

ALP Lab Manual Page |8 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 6. WRITE AN ALP TO FIND 1’S COMPLEMENT OF A 16BIT NUMBER.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Get the 1st byte to L and 2nd
8500 2A 00 87 LHLD 8700H
byte to H register.
8503 7D MOV A, L Get the 1st byte to Acc.

8504 2F CMA Complement the Acc.

8505 67 MOV L, A Store back to L register.

8506 7C MOV A, H Get the 2nd byte to Acc.

8507 2F CMA Complement the Acc.

8508 6F MOV H, A Store back to H register.


Store L contents to 8800
8509 22 00 88 SHLD 8800H
and H contents to 8801.
850C 76 HLT End of the Program

INPUT: OUTPUT:

8700 3E 8800 C1

8701 52 8801 AD

523E => 0101 0010 0011 1110

1’S COMPLEMENT => 1010 1101 1100 0001 == A D C 1

ALP Lab Manual Page |9 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 7. WRITE AN ALP TO FIND SMALLEST OF ‘N’ 1BYTE BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8300 21 00 85 LXI H,8500H Load HL as input Pointer.

8303 0E 04 MVI C, 04H Set the C reg as Counter.

8305 7E MOV A, M Get the 1st no. to Acc.

8306 0D DCR C Decrease the Count by 1.

8307 47 MOV B, A Set the 1st no. as small.

8308 23 L2: INX H Increase pointer by 1.

8309 BE CMP M Compare with another no.

830A DA 0E 83 JC L1 Jump if CY=0 to L1 (Loop).

830D 46 MOV B, M If small, Get it into B reg.

830E 78 L1: MOV A, B Get the small no. to Acc.

830F 0D DCR C Decrease the Count by 1.

8310 C2 08 83 JNZ L2 Jump if Z=0 to L2 (Loop).


Store the small no. that is to
8313 32 F1 8F STA 8FF1H
be displayed in Data field.
8316 CD 4C 04 CALL 044CH Call Subroutine to display.

8319 76 HLT End of the program.

INPUT: OUTPUT:

8500 => 30 DISPLAYS – 1F ON THE DATA FIELD


8501 => 24
8502 => 1F Smallest
8503 => 25
8504 => 4B

ALP Lab Manual P a g e | 10 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 8. WRITE AN ALP TO SIMULATE DECIMAL COUNTER (DISPLAY FROM 00 TO 99)

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8200 3E 00 MVI A, 00H Set the Acc with start 00.


Store the no. that is to be
8202 32 F1 8F L1: STA 8FF1H
displayed in data field.
8205 F5 PUSH PSW Push Acc + Flags to Stack.

8206 CD 4C 04 CALL 044CH Call Subroutine to display.

8209 CD 55 55 CALL 5555H Call Subroutine to delay.

820C F1 POP PSW Pop Acc + Flags from Stack.

820D C6 01 ADI 01H Increment the no. by 1.

820F 27 DAA Adjust the no. to Decimal.

8210 FE 00 CPI 00H Compare the no. with 00.

8212 C2 02 82 JNZ L1 Jump if Z=0 to L1 Loop).

8215 76 HLT End of the program.

SUBROUTINE FOR TIME DELAY

8250 0E FF MVI C, FFH Set the Count = FFH

8252 0D L2 DCR C Decrement the count

8253 C2 52 82 JNZ L2 If Z=0, jump to Loop L2

8256 RET Return to main program

INPUT: OUTPUT:

NO INPUT DISPLAYS DECIMAL COUNT FROM => 00 TO 99

(INITIALIZE WITH COUNT 00)

ALP Lab Manual P a g e | 11 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 9. WRITE AN ALP TO DO ADDITION OF ALL EVEN NO’S IN A GIVEN SERIES.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Set HL as Pointer for the
8700 21 00 89 LXI H, 8700H
series of given numbers.
8703 0E 04 MVI C, 04H Initialize C as N-1 values.

8704 06 00 MVI B, 00H Clear B reg. to store Sum

8707 7E L2: MOV A, M Get the number into Acc.


Mask the LSB to check odd
8708 E6 01 ANI 01H
or even number.
870A C2 10 87 JNZ L1 If the Z = 0 jump to L1

870D 7E MOV A, M Get the no. to Acc again.

870E 80 ADD B Add the number with B reg.

870F 47 MOV B, A Store back to B register.

8710 23 L1: INX H Increment the Pointer.

8711 0D DCR C Decrement the Count.

8712 C2 07 87 JNZ L2 If the Z = 0, jump to L2.

8715 78 MOV A, B Get the sum to Acc.

8716 32 00 8A STA 8A00H Store the Acc to memory.

8719 76 HLT End of the program.

INPUT: 8900 25 OUTPUT: 8A00 9A


8901 30
8902 15 Even Sum = 30 + 6A = 9A
8903 2B
8904 6A

ALP Lab Manual P a g e | 12 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 10. WRITE AN ALP TO DO MULTIPLICATION OF 2 DIGIT DECIMAL NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8300 to L &
8400 2A 00 83 LHLD 8300H
contents of 8301 to H.
8403 AF XRA A Clear Acc and flags.

8404 47 MOV B, A Initialize B reg with 00.

8405 84 L2: ADD H Add Acc + H. Store to Acc.

8406 27 DAA Adjust Acc. to Decimal.

8407 D2 0B 84 JNC L1 Jump if Cy=0 to L1 (Loop).

840A 04 INR B If Cy=1, Increase B reg by 1.

840B 2D L1: DCR L Decrease no. of additions.

840C C2 05 84 JNZ L2 Jump if Z=0 to L2 (Loop).

840F 6F MOV L, A Store Acc contents to L.

8410 60 MOV H, B Store B reg contents to H.

8411 22 EF 8F SHLD 8FEFH Store product to display.

8414 CD 40 04 CALL 0440H Call Subroutine to display.

8417 76 HLT End of the program.

INPUT: OUTPUT:

8300 04 DISPLAYS 0012 IN ADDRESS FIELD

8301 03

8300 06 DISPLAYS 0030 IN ADDRESS FIELD

8301 05

ALP Lab Manual P a g e | 13 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 11. WRITE AN ALP TO DO EXCHANGE OF TWO-32 BIT NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8600 to L
8000 2A 00 86 LHLD 8600
and 8601 to H register.
Exchange (Store contents of
8003 EB XCHG
HL to DE pair). HL  DE.
Load contents of 8700 to L
8004 2A 00 87 LHLD 8700
and 8701 to H register.
Store contents of L to 8600
8007 22 00 86 SHLD 8600
and H to 8601 location.
Exchange (Store contents of
800A EB XCHG
DE to HL pair). DEHL.
Store contents of HL pair to
800B 22 00 87 SHLD 8700
8700 & 8701 location.
Load contents of 8602 to L
800E 2A 02 86 LHLD 8602
and 8603 to H register.
Exchange (Store contents of
8011 EB XCHG
HL to DE pair). HL  DE.
Load contents of 8702 to L
8012 2A 02 87 LHLD 8702
and 8703 to H register.
Store contents of L to 8602
8015 22 02 86 SHLD 8602
and H to 8603 location.
Exchange (Store contents of
8018 EB XCHG
DE to HL pair). DEHL.
Store contents of HL pair to
8019 22 02 87 SHLD 8702
8702 & 8703 location.
801C 76 HLT End of the program.

INPUT: OUTPUT:

8600 24 8700 45 8600 45 8700 24


8601 3E 8701 4D 8601 4D 8701 3E
8602 AB 8702 56 8602 56 8701 AB
8603 3C 8703 C3 8603 C3 8703 3C

ALP Lab Manual P a g e | 14 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 12 WRITE AN ALP TO DO SUBTRACTION OF TWO-8BIT BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

9000 21 00 86 LXI H, 8600H Initialize HL as I/P Pointer.

9003 7E MOV A, M Get the 8bit no. into Acc.

9004 23 INX H Increment the pointer by 1

9005 96 SUB M Subtract Acc with M => Acc

9006 32 00 87 STA 8700H Store Difference to 8700.

9009 3E 00 MVI A, 00H Initialize Acc with 00.

900B 9F SBB A Get the Borrow to Acc.

900C 32 01 87 STA 8701H Store the Borrow into 8701.

900F 76 HLT End of the program.

9000 3E 30 MVI A, 30H

9002 06 08 MVI B, 08H


Program to Sub two bytes
9004 80 SUB B stored to Reg A and Reg and
store result at 8700H (Sum).
9005 32 00 87 STA 8700H
Get borrow into Acc & store
9008 3E 00 MVI A, 00H borrow into the memory
locations 8701H (Borrow).
900A 8F SBB A

900B 32 01 87 STA 8701H

900E 76 HLT End of the program

INPUT: OUTPUT:

8600 30 8600 08 8700 28 8700 D8

8601 08 8601 30 8701 00 8701 FF

ALP Lab Manual P a g e | 15 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 13. WRITE AN ALP TO DO ADDITION OF TWO-16BIT BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8600 to L
9000 2A 00 86 LHLD 8600H
and 8601 to H register.
Exchange (Store contents of
9003 EB XCHG
HL into DE). HL  DE.
Load contents of 8700 to L
9904 2A 00 87 LHLD 8700H
and 8701 to H register.
9007 7B MOV A, E Get 1st byte of 16bit. to Acc.
Add the 1st byte of both no’s
9008 85 ADD L
& store into Acc.
9009 6F MOV L, A Store back to L register.

900A 7A MOV A, D Get 2nd byte of 16bit. to Acc.


Add the 2nd byte of both no’s
900B 8C ADC H
& store into Acc.
900C 67 MOV H, A Store back to H register.
Store L contents to 8800 & H
900D 22 00 88 SHLD 8800H
contents to 8801 location.
9010 3E 00 MVI A, 00H Initialize Acc with 00.

9012 8F ADC A Get the Carry into Acc.

9013 32 02 88 STA 8802H Store Acc contents to 8802.

9016 76 HLT End of the program.

INPUT: OUTPUT:

8600 2A 8700 43 8800 6D


8601 96 8701 5B 8801 F1
ST
1 16 BIT NUM: 96 2A 8802 00
ND
2 16 BIT NUM: 5B 43
SUM (RESULT) 00 F1 6D

ALP Lab Manual P a g e | 16 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 14. WRITE AN ALP TO DO SUBTRACTION OF ‘N’-1BYTE BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8200 21 00 85 LXI H, 8500H Initialize HL as Pointer.

8202 0E 04 MVI C, 04H Set C = 04H as Counter.

8205 06 00 MVI B, 00H Clear B reg to store carry.

8207 7E MOV A, M Get the 1st no to Acc.

8208 23 L1: INX H Increment pointer by 1.

8209 96 SUB M Sub Acc - M, Diff to Acc.

820A D2 0E 82 JNC L2 Jump if CY=0 to loop L2.

820D 05 DCR B Decrement B reg by 1.

820E OD L2: DCR C Decrement Count by 1.

820F C2 08 82 JNZ L1 Jump if Z=0 to loop L1.

8212 32 00 87 STA 8700H Store the Diff into 8700.

8215 78 MOV A, B Get the Borrow into Acc.

8216 32 01 87 STA 8701H Store the Borrow into 8701.

8219 76 HLT End of the program.

INPUT: OUTPUT: AE
8500 => AE 8700 A6 22
8501 => 22 8701 FF 10
8502 => 10 23
8503 => 2A B3
8504 => B3 FF A6

ALP Lab Manual P a g e | 17 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 15. WRITE AN ALP TO DO BLOCK TRANSFER OF N BYTES OF DATA (REVERSE ORDER)

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8200 21 00 85 LXI H, 8500H Load HL as input Pointer.

8203 11 04 86 LXI D, 8604H Load DE as output Pointer.

8206 06 05 MVI B, 05H Set B reg as Counter.

8208 7E L1: MOV A, M Get the number to Acc.

8209 12 STAX D Store to DE pointed ML.

820A 23 INX H Increase the HL pair by 1.

820B 1B DCX D Decrease the DE pair by 1.

820C 05 DCR B Decrease the Count by 1.

820D C2 08 82 JNZ L1 Jump if Z=0 to L1 (Loop).

8210 76 HLT End of the Program.

INPUT: OUTPUT:
8500 30 8600 38
8501 45 8601 2B
8502 6E 8602 6E
8503 2B 8603 45
8504 38 8604 30

ALP Lab Manual P a g e | 18 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 16. WRITE AN ALP TO FIND 2’S COMPLEMENT OF A 16BIT NUMBER.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Get the 1st byte to L and 2nd
8500 2A 00 87 LHLD 8700H
byte to H register.
8503 7D MOV A, L Get the 1st byte to Acc.

8504 2F CMA Complement the Acc.

8505 C6 01 ADI 01H Add 01 to get 2’s comp.

8507 67 MOV L, A Store back to L register.

8508 7C MOV A, H Get the 2nd byte to Acc.

8509 2F CMA Complement the Acc.

850A 6F MOV H, A Store back to H register.


Store L contents to 8800
850B 22 00 88 SHLD 8800H
and H contents to 8801.
850E 76 HLT End of the Program.

INPUT: OUTPUT:

8700 3E 8800 C2

8701 52 8801 AD

523E => 0101 0010 0011 1110

2’S COMPLEMENT => 1010 1101 1100 0010 == A D C 2

ALP Lab Manual P a g e | 19 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 17. WRITE AN ALP TO FIND THE LARGEST OF ‘N’-1BYTE OF BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8400 21 00 85 LXI H, 8500H Load HL as. input Pointer.

8403 0E 05 MVI C, 05H Set the C reg as Counter.

8405 7E MOV A, M Get the 1st no. to Acc.

8406 0D DCR C Decrease the Count by 1.

8407 47 MOV B, A Set the 1st no. as large.

8408 23 L2: INX H Increase pointer by 1.

8409 BE CMP M Compare with another no.

840A D2 0E 84 JNC L1 Jump if CY=0 to L1 (Loop).

840D 46 MOV B, M If large, Get it into B reg.

840E 78 L1: MOV A, B Get the large no. to Acc.

840F 0D DCR C Decrease the Count by 1.

8410 C2 08 84 JNZ L2 Jump if Z=0 to L2 (Loop).


Store the large no. that is to
8413 32 F1 8F STA 8FF1H
be displayed in Data field.
8416 CD 4C 04 CALL 044CH Call Subroutine to display.

8419 76 HLT End of the Program.

INPUT: OUTPUT:

8500 => 30 DISPLAYS – 4B ON DATA FIELD


8501 => 24
8502 => 1F
8503 => 25
8504 => 4B Largest

ALP Lab Manual P a g e | 20 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 18. WRITE AN ALP TO SIMULATE THE BINARY COUNTER (DISPLAY FROM 00 TO FF)

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND

8000 3E 00 MVI A, 00H Set the Acc with start 00.


Store the no. that is to be
8002 32 F1 8F L1: STA 8FF1H
displayed in data field.
8005 F5 PUSH PSW Push Acc + Flags to Stack.

8006 CD 4C 04 CALL 044C Call Subroutine to display.

8009 CD 55 55 CALL 5555 Call Subroutine to delay.

800C F1 POP PSW Pop Acc + Flags from Stack.

800D C6 01 ADI 01H Increment the no. by 1.

800F FE 00 CPI 00H Compare the no. with 00.

8011 C2 02 80 JNZ L1 Jump if Z=0 to L1 (Loop).

8014 76 HLT End of the Program.

INPUT: OUTPUT:

NO INPUT DISPLAYS BINARY COUNT FROM=> 00 TO FF

(INITIALIZED WITH COUNT 00)

ALP Lab Manual P a g e | 21 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 19. WRITE AN ALP TO DO ADDITION OF ALL ODD NO’S IN A GIVEN SERIES.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Set HL as Pointer for the
8700 21 00 89 LXI H, 8700H
series of given numbers.
8703 0E 04 MVI C, 04H Initialize C as N-1 values.

8704 06 00 MVI B, 00H Clear B reg. to store Sum

8707 7E L2: MOV A, M Get the number into Acc.


Mask the LSB to check odd
8708 E6 01 ANI 01H
or even number.
8709 CA 10 87 JZ L1 If the Z = 1 jump to L1

870A 7E MOV A, M Get the no. to Acc again.

870D 80 ADD B Add the number with B reg.

870E 47 MOV B, A Store back to B register.

870F 23 L1: INX H Increment the Pointer.

8710 0D DCR C Decrement the Count.

8711 C2 07 87 JNZ L2 If the Z = 0, jump to L2.

8712 78 MOV A, B Get the sum to Acc.

8713 32 00 8A STA 8A00H Store the Acc to memory.

8716 76 HLT End of the program.

INPUT: 8900 25 OUTPUT: 8A00 65


8901 30
8902 15 Odd Sum = 25 + 15 + 2B = 65
8903 2B
8904 6A

ALP Lab Manual P a g e | 22 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

PROGRAM: 20. WRITE AN ALP TO DO MULTIPLICATION OF 2 DIGIT BINARY NUMBERS.

HEX- CODE MNEMONICS


ADDRESS LABEL COMMENTS
1B 2B 3B OPCODE OPERAND
Load contents of 8300 to L &
8400 2A 00 83 LHLD 8300H
contents of 8301 to H.
8403 AF XRA A Clear Acc and flags.

8404 47 MOV B, A Initialize B reg with 00.

8405 84 L2: ADD H Add Acc + H. Store to Acc.

8406 D2 0A 84 JNC L1 Jump if Z=0 to L1 (Loop).

8409 04 INR B Increase the B reg by 1.

840A 2D L1: DCR L Decrease no. of additions.

840B C2 05 84 JNZ L2 Jump if Z=0 to L2 (Loop).

840E 6F MOV L, A Store Acc contents to L.

840F 60 MOV H, B Store B reg contents to H.

8410 22 EF 8F SHLD 8FEFH Store product to display.

8413 CD 40 04 CALL 0440H Call Subroutine to display.

8416 76 HLT End of the Program.

INPUT: OUTPUT:

8300 04 DISPLAYS 000C IN ADDRESS FIELD

8301 03

8300 08 DISPLAYS 0028 IN ADDRESS FIELD

8301 05

ALP Lab Manual P a g e | 23 BCA – V SEM/GIMS


GLOBAL INSTITUTE OF MANAGEMENT SCIENCES

ALP Lab Manual P a g e | 24 BCA – V SEM/GIMS

You might also like