MALP Lab Manual
MALP Lab Manual
Semester: V
PART – A
Write an assembly language program to exchange two 16-bit
1. 4
numbers
Write an assembly language program for Addition of two 8-bit
2. 5
numbers and Subtraction of two 8-bit numbers
Write an assembly language program for Addition of two 16-bit
3. 7
numbers
Write an assembly language program for Two N-Byte numbers
4. 8
addition
PART – B
Write an assembly language program to find the 1’s complement
11. 15
of a 16-bit number.
Write an assembly language program to find the 2’s complement
12. 16
of an 8-bit number
Write an assembly language program to shift left 8-bit number by
13. 16
1 bit
Write an assembly language program to find largest of two 8-bit
14. 17
numbers
2
Instructions to Students
3
01. Write an assembly language program to exchange two 16-bit numbers
Memory Machine
Label Mnemonics Operand Comments
Location Code
Ste Register B as counter to
8000 MVI B, 02H 06
exange two 16-bit numbers
8001 02
8002 LXI H, 8500H 21
Set HL Register pair as pointer to
8003 00
8500 memory location
8004 85
8005 LXI D, 8600H 11
Set DE Register pair as pointer to
8006 00
8600 memory location
8007 86
Move the contents of memory
8008 Next: LDAX D 1A pointer specified by the DE
register pair into accumulator
Save the contents of accumulator
8009 MOV C, A 4F
in C register
Move the data byte of memory
800A MOV A, M 7E pointer specified by HL register
pair into accumulator
Transfer the dat byte of HL
800B STAX D 12 register pair mmeory pointer to
DE register pair memory pointer
Transfer the dat byte of DE
800C MOV M, C 71 register pair mmeory pointer to
HL register pair memory pointer
Increment the source memory
800D INX H 23
pointer to get next byte data
Increment the destination memory
800E INX D 13
pointer to get next byte data
800F DCR B, 02H 05 Decrement the counter by 1
8010 JNZ Next: C2 If counter in not zero, go back to
8011 08 specified loaction to exchange
8012 80 next data byte.
8013 HLT 76 Terminate program execution
4
02. Write an assembly language program for Addition of two 8-bit numbers and Subtraction
of two 8-bit numbers
5
Subtraction of two 8-bit numbers
Memory Machine
Label Mnemonics Operand Comments
Location Code
8000 LXI H, 8500 21 Initializa HL Register pair
8001 00H
8002 85H
8003 MVI C, 00 0E Clear Register C to store carry
8004 00H
8005 MOV A, M 7E Move first data byte to Accumulator
8006 INX H, 8500 23 Increment the memory pointer by 1
8007 SUB M 96 Subtract contents of [A]+[M]
8008 JNC Next: D2 Is carry? No - go to lable location
8009 0CH
800A 80H
In carry? Yes - increment C register
800B INR C 0C
by 1
Store the sum in to specified
800C Next: STA 8502 32
location
800D 02H
800E 85
800F MOV A, C 79 Move carry to accumulator
8010 STA 8503 32 Store carry in to specified loaction
8011 03H
8012 85
8013 HLT 76 Terminate program execution
6
03. Write an assembly language program for Addition of two 16-bit numbers
Memory Machine
Label Mnemonics Operand Comments
Location Code
Clear C Register to save
8000 MVI C,00H 0E
carry
8001 00
Load the H-L Register
pair direct with the
8002 LHLD 8500H 2A
contents of 8500H and
8501H locations
8003 00
8004 85
Exchange the contents of
8005 XCHG EB H-L and D-E Register
Pairs
Load the H-L Register
pair direct with the
8006 LHLD 8700H 2A
contents of 8700H and
8701H locations
8007 00
8008 87
Add the contents of H-L
8009 DAD D 19 and D-E register pairs
and result in H-L Pair
If there is no carry after
800A JNC Next: D2 addition, Junp to Next
(Specified) Location
800B 0E
800C 80
If there is a carry after
800D INR C,00H 0C addition operation,
increment register C by 1
Store the contents of L
register in 8900H and H
800E Next: SHLD 8900H 22
Register in 8901H
location
800F 00
8010 89
Move carry to
8011 MOV A, C 79
accumulator
Store the carry in 8903H
8012 STA 8903H 32
location
8013 03
8014 89
Terminate the program
8015 HLT 76
execution
7
04. Write an assembly language program for Two N-Byte numbers addition
Memory Machine
Label Mnemonics Operand Comments
Location Code
Set up C as a byte counter. To add
8000 MVI C, 04H 06 two 4-Bytes of data. Register C is
loaded with 04H
8001 04H
H, HL-Register pair pointing to
8002 LXI 21
8500H specified memory location
8003 00
8004 85
D, DE-Register pair pointing to
8005 LXI 11
8600H specified memory location
8006 00
8007 86
8008 XRA A AF Clear Carry
Get the data byte of 2nd number tp
8009 Next: LDAX D 1A
accumulator
800A ADC M 8E Add [M]+[A] with carry
Save the sum in memory ponter
800B MOV M, A 77
specified by HL register pair
Increment the memory pointer of
800C INX H 23
HL by 1
Increment the memory pointer of
800D INX D 13
DE by 1
800E DCR C 0D Decrement counter by 1
If counter is not zero, go to
800F JNZ Next: C2 specified memory location to add
next data byte.
8010 09
8011 80
8012 MVI A, 00H 3E Clear accumulator
8013 00H
Rotate the contents of accumulator
through carry to move the generated
8014 RAL 17
carry during addition to
accumulator
Save carry in memory pointed by
8015 MOV M, A 77
HL-Register pair
8016 HLT 76 Terminate program execution
8
05. Write an assembly language program for Block Transfer
Memory Machine
Label Mnemonics Operand Comments
Location Code
H, Set up HL pair as a memory
8000 LXI 21
8500H location for the source
8001 00H
8002 85H
D, Set up DE pair as a memory
8003 LXI 11
8600H location for the Destination
8004 00H
8005 85H
8006 MVI B, 05H 6 Load B register as counter with 05H
8007 05H
Move the data byte of source
8008 Next: MOV A, M 7E
menory to accumulator
8009 00H
800A 85H
D, Transfer the data byte to the
800B STAX 12
8600H destination memory
800C INX H 23 Increment register pair HL by 1
800D INX D 13 Increment register pair DE by 1
800E DCR B 5 Decrement the counter by 1
Jump to specified address location
800F JNZ Next: C2
if counter is not zero.
8010 08H
8011 80H
8012 HLT 76 Terminate program execution
9
06. Write an assembly language program for 'N' Decimal Number addition
Memory Machine
Label Mnemonics Operand Comments
Location Code
Ste up C-Register with a counter
8000 MVI C, 0AH 0E value OA to add 10 Decimal
numbers
8001 0A
Clear the accumulator to save
8002 XRA A AF
sum
Clear register B to save generated
8003 MOV B, A 47
carry
Set HL Register to point
8004 LXI H, 8500 21
specified memory location
8005 00
8006 85
8007 Loop: ADD M 86 Add [A]+[M]
8008 DAA 27 Adjust the sum for decimal value
8009 JNC Next: D2 If no carry: go to next
800A 0D
800B 80
If Carry: increment register B by
800C INR B 04
1
Increments the memory pointer
800D Next: INX H 23 to store the next data byte for
addition
800E DCR C 0D Decrement the counter by 1
If counter is not zero: go to
800F JNZ Loop: C2
specified memory location
8010 07
8011 80
Stores the sum in 8600 memory
8012 STA 8600H 32
location
8013 00
8014 86
Moves the contents of B register
8015 MOV A, B 78
to accumulator
Stores the carry in 8600H
8016 STA 8601H 32
memory location
8017 01
8018 86
8019 HLT 76 Terminate program execution
10
07. Write an assembly language program for 4 Digit BCD Addition
Memory Machine
Label Mnemonics Operand Comments
Location Code
8000 MVI C, 00H 0E Clear C Register to save carry
8001 00
8002 LHLD 8500H 2A Load HL Register pair direct with
8003 00 the contents of 8500, 8501 memory
location to get first 4-digit BCD
8004 85 number
Exchange the contents of H-L and
8005 XCHG EB
D-E register pairs
8006 LHLD 8502 2A Load HL Register pair direct with
8007 02 the contents of 8502, 8503 memory
location to get second 4-digit BCD
8008 85 number
Move the lower byte of 1st 4-digit
8009 MOV A, E 7B
BCD number to accumulator
Add the lower byte of 1st number
800A ADD L 85
with lower byte of 2nd Number
800B DAA 27 Adjust the sum for decimal value
800C JNC Loop1: D2 If no carry, jump to Loop1:
800D 10
800E 80
800F INR D 14 Increment D by 1 if Carry
8010 Loop1: STA 8600H 32
Store the lower byte BCD sum in
8011 00
8600H memory location
8012 86
Load the higher byte of 1st 4 digit
8013 MOV A, D 7A
BCD number to accumulator
Add the heigher byte of 1st number
8014 ADD H 84
with 2nd number
8015 DAA 27 Adjust the sum for decimal value
8016 JNC Loop2: D2 If no carry, jump to Loop2:
8017 1A
8018 80
8019 INR C 0C Increment C by 1 if Carry
801A Loop2: STA 8601H 32
Store the lower byte BCD sum in
801B 01
8601H memory location
801C 86
801D MOV A, C 79 Move the carry to Accumulator
801E STA 8602H 32
Store the carry in 8602H memory
801F 02
location
8020 86
8021 HLT 76 Terminate Program execution
11
09. Write an assembly language program to subtract 16-bit numbers
Memory
Mnemonic Operan Machin
Locatio Label Comments
s d e Code
n
8000 MVI C, 00H 0E
Clear register C to save carry
8001 00
8002 LHLD 8500H 2A Load HL Register Pair direct with
8003 00 the contents of 8500 and 8501
8004 85 locations
Exchange the contents of HL and
8005 XCHG EB
DE register pairs
8006 LHLD 8502H 2A Load HL Register Pair direct with
8007 02 the contents of 8502 and 8503
8008 85 locations
Move lower byet of the minuend
8009 MOV A, E 7B
to accumulator
800A SUB L 95 Subtract lower bytes of data
800B JNC Loop1: D2
800C 0F If [E]>[L], go to Loop1:
800D 80
If [E]<[L], decrement D by 1,
800E DCR D 15
since barrow is needed
Loop1
800F STA 8504H 32 Store the lower byte difference in
:
memory location 8504 address
8010 04
location
8011 85
Move higher byet of the minuend
8012 MOV A, D 7A
to accumulator
8013 SUB H 94 Subtract higher bytes of data
8014 JNC Loop2: D2
8015 18 If [D]>[H], go to Loop1:
8016 80
If [D]<[H], decrement D by 1,
8017 INR C 0C
since barrow is needed
Loop2
8018 STA 8505H 32 Store the lower byte difference in
:
memory location 8505 address
8019 05
location
801A 85
8016 MOV A, C 79 Move the barry into accumulator
8017 STA 8506H 32
Move the carry into 8506 address
8018 06
location
8019 85
801A HLT 76 Terminate program execution
12
09. Write an assembly language program for sorting of array in ascending order
Memor
y Mnemonic Operan Machin
Label Comments
Locatio s d e Code
n
Set up Register D as counter with
8000 MVI D, 05H 16 value 05 - indicating array size as
5
8001 05
Loop3 Set up HL Register pair pointing
8002 LXI H, 8500 21
: to array beginning index 8500
8003 00
8004 85
Set up Register C as 2nd Counter
8005 MVI C, 05H 0E
with value 05
8006 05
Loop2 Moves the data yte sorted in
8007 MOV A, M 7E
: memory pointer to accumulator
8008 INX H 23 Increment pointer by 1
Compare contents of memory with
8009 CMP M BE
accumulator contents
If[A]<[M], jump to Loop1. Else,
800A JC Loop1: DA exchange the content of [A] &
[M]
800B 12
800C 80
Moves contents of [M] into temp
800D MOV B, M 46
register B
Moves contents of [A] into
800E MOV M,A 77
memory location [M]
800F DCX H 2B Decrement pointer by 1
Moves contents of register B int
8010 MOV M, B 70
[M]
8011 INX H 23 Increment pointer by 1
Loop1
8012 DCR C 0D decrement 2nd counter
:
If counter is not zero, go to
8013 JNZ Loop2: C2
Loop2: address location
8014 07
8015 80
8016 DCR D 15 Decrement 1st Counter
If counter is not zero, go to
8017 JNZ Loop3: C2
Loop3: address location
8018 02
8019 80
801A HLT 76 Terminate Program execution
13
10. Write an assembly language program for multiplication of 2 digit BCD numbers
Memory Machine
Label Mnemonics Operand Comments
Location Code
8000 MVI C, 08 0E Get multiplicand in C Register
8001 08
8002 MVI D, 04 16 Get multiplier in D Register
8003 04
8004 XRA A AF Clear accumulator to save sum
Clear B register to save generated
8005 MOV B, A 47
carry
8006 Loop: ADD C 81 Add multiplicand to accumulator
8007 DAA 27 Adjust the Sum for decimal value
8008 JNC Next: D2 If no carry, go to Next:
8009 0C
800A 80
If carry B register is incremented by
800B INR B 04
1
Decrement the D register by 1, if
800C Next: DCR D 15 the multiplicand is added to
accumulator once.
If multiplier is not zero, go to loop
800D JNZ Loop: C2
to add multiplicand again.
800E 06
800F 80
Stores the product in 8600 memory
8010 STA 8600H 32
location
8011 00
8012 86
Moves the contents of B register to
8013 MOV A, B 78
accumulator
Stores the carry in 8601 memory
8014 STA 8601H 32
location
8015 01
8016 86
8017 HLT 76 Terminate program execution
14
11. Write an assembly language program to find the 1’s complement of a 16-bit number.
Program:
Address Instruction Operand Opcode
8000 LHLD 8100 2A
8001 00
8002 81
8003 MOV A, L 7D
8004 CMA 2F
8005 MOV L, A 6F
8006 MOV A, H 7C
8007 CMA 2F
8008 MOV H, A 67
8009 SHLD 8200 22
800A 00
800B 82
800C HLT 76
Input:
Input Address Value
8100 45
8101 6A
Output:
Output Address Value
8200 BA
8201 95
15
12. Write an assembly language program to find the 2’s complement of an 8-bit number.
Program:
Address Instruction Operand Opcode
8000 LDA 8100 3A
8001 00
8002 81
8003 CMA 2F
8004 INR A 3C
8005 STA 8200 32
8006 00
8007 82
8008 HLT 76
Input:
Input Address Value
8100 85
Output:
Output Address Value
8200 7B
13. Write an assembly language program to shift left 8-bit number by 1 bit.
Program:
Address Instruction Operand Opcode
8000 LDA 8100 3A
8001 00
8002 81
8003 RAL 17
8004 STA 8200 32
8005 00
8006 82
8007 HLT 76
Input:
Input Address Value
8100 05
Output:
Output Address Value
8200 0A
16
14. Write an assembly language program to find largest of two 8-bit numbers.
Program:
Address Label Instruction Operand Opcode
8000 LXI 8100 21
8001 00
8002 81
8003 MOV A, M 7E
8004 INX H 23
8005 MOV B, M 46
8006 CMP B B8
8007 SKIP: JNC D2
8008 MOV A, B 78
8009 SKIP: INX H 23
800A MOV M, A 77
800B HLT 76
Input:
Input Address Value
8100 13
8101 05
Output:
Output Address Value
8103 13
17
15. Write an assembly language program to largest from an array.
Program:
Address Label Instruction Operand Opcode
8000 LXI 8100 21
8001 00
8002 81
8003 MOV C, M 4E
8004 INX H 23
8005 MOV A, M 7E
8006 DCR C 0D
8007 LOOP: INX H 23
8008 MOV B, M 46
8009 CMP B B8
800A SKIP: JNC 800E D2
800B 0E
800C 80
800D MOV A, B 78
800E SKIP: DCR C 0D
800F LOOP: JNZ 8007 CE
8010 INX H 23
8011 MOV M, A 77
8012 HLT 76
Input:
Input Address Value
8100 05
8101 02
8102 32
8103 48
8104 09
8106 65
Output:
Output Address Value
8106 65
18
16. Write an assembly language program to perform division of two 8-bit numbers.
Program:
Address Label Instruction Operand Opcode
8000 LDA 8100 3A
8001 00
8002 81
8003 MOV B, A 47
8004 LDA 8101 3A
8005 01
8006 81
8007 MVI C, 00 0E
8008 00
8009 NEXT: CMP B B8
800A LOOP: JC 8010 DA
800B SUB B 90
800C INR C 0C
800D NEXT: JMP 8009 C3
800E 09
800F 80
8010 LOOP: STA 8102 32
8011 02
8012 81
8013 MOV A, C 79
8014 STA 8103 32
8015 03
8016 81
8017 HLT 76
Input:
Input Address Value
8100 09
8101 02
Output:
Output Address Value
8102 01
8103 04
19
17. Write an assembly language program to calculate the sum of series of numbers.
Program:
Address Label Instruction Operand Opcode
8000 LDA 8100 3A
8001 00
8002 81
8003 MOV C, A 4F
8004 LXI H, 8101 21
8005 01
8006 81
8007 SUB A 97
8008 MOV B, A 47
8009 LOOP: ADD M 86
800A SKIP: JNC 800E D2
800B 0E
800C 80
800D INR B 04
800E SKIP: INX H 23
800F DCR C 0D
8010 LOOP: JNZ 8009 C2
8011 09
8012 80
8013 STA 8200 32
8014 00
8015 82
8016 MOV A, B 78
8017 STA 8201 32
8018 01
8019 82
801A HLT 76
Input: Output:
Input Address Value Output Address Value
8100 04 8102 17
8101 07 8103 00
8102 09
8103 03
8104 04
20
18. Write an assembly language program to find factorial of an 8-bit number.
Program:
Address Label Instruction Operand Opcode
8000 LXI H, 8100 21
8001 00
8002 81
8003 MVI C, M 4E
8004 MVI E, M 5E
8005 DCR E 1D
8006 LOOP1: INX H 23
8007 DCR C 0D
8008 MOV M, C 71
8009 LOOP1: JNZ 8006 C2
800A 06
800B 80
800C LXI H, 8200 21
800D 00
800E 82
800F LOOP2: MOV A, M 7E
8010 INX H 23
8011 MOV B, M 46
8012 MOV C, A 4F
8013 MVI A, 00 3E
8014 00
8015 GO: ADD B 80
8016 DCR C 0D
8017 GO: JNZ 8015 C2
8018 15
8019 80
801A MOV M, A 77
801B DCR E 1D
801C LOOP2: JNZ 800F C2
801D 0F
801E 80
801F STA 8250 32
8020 50
8021 82
8022 HLT 76
21
Input:
Input Address Value
8100 05
Output:
Output Address Value
8200 78