Programs

Programs I
Write a program to add two numbers stored in memory location 2000h and 2001h and store the result in 2002h.
answer:
LDA 2000H
MOV B,A
LDA 2001H
ADD B
STA 2002H
JNC DOWN
MVI A,01H
STA 2003H
HLT

WAP to subtract two number stored in memory location 2000 and 2001 h and store the result in 2002h.

LDA 2000H
MOV B,A
LDA 2001H
SUB B
STA 2002H

10 bytes of data are stored at memory location starting from 2000h onwards. WAP to add these data and store the result in memory location 3000h
LXI H,2000H
MVI B,0AH
MVI A,00H
mvi d,00h
UP1: ADD M
jnc down
inr d
down: INX H
DCR B
JNZ UP1
mov e,a
HLT

WAP to add given series of 8 bit data byte whose length is specified at the memory location 3000h and the series itself starts from 4000h onwards.The sum is to be stored at 5000h and the Carry(if produced ) at 5001h
LXI H,4000H
LDA 3000H
MOV B,A
MVI C,00H
MVI A,00H
UP1: ADD M
JNC DOWN
INR C
DOWN: INX H
DCR B
JNZ UP1
STA 5000H
MOV A,C
STA 5001H
HLT

WAP to copy 16 data from memory address 2000h onwards to 2020h onwards.
LXI B,2000H
LXI D,2020H
MVI H,0FH
UP1: LDAX B
STAX D
INX B
INX D
DCR H
JNZ UP1
HLT

WAP to copy 10 data from memory address 2040h-2049h to 2045h- 204eh
LXI B,2049H
LXI D,204EH
MVI H,0aH
UP1: LDAX B
STAX D
DCX B
DCX D
DCR H
JNZ UP1
HLT

Programs II


WAP to find the square of a given number stored in memory address 2000h


LDA 2000H
MOV B,A
MOV C,A
MVI A,00H
UP1: ADD C
DCR B
JNZ UP1
MOV D,A
HLT

WAP to find the highest data in the array of 10 bytes .The array starts from 2000h. store the highest number in memory address 3000h.


lxi h,2000h
mvi c,0Ah

mov a,m
next:
cmp m
jnc down
mov a,m
down: inx h
dcr c
jnz next
sta 3000h
hlt


 WAP to find the lowest data in the array of 10 bytes .The array starts from 2000h. store the number in memory address 3000h.

lxi h,2000h
mvi c,09h

mov a,m
next:
cmp m
jc down
mov a,m
down: inx h
dcr c
jnz next
sta 3000h
hlt

write a program to multiply two numbers by shifting method

LHLD 2000H
XCHG
CALL MULTIPLY
SHLD 2002H
HLT

MULTIPLY:
MOV A,D
MVI D,00H
LXI H,0000H
MVI B,08H
NXTBIT:RAR
JNC NOADD
DAD D
NOADD:XCHG
DAD H
XCHG
DCR B
JNZ NXTBIT
RET


Program to divide two numbers. 

suppose you want to divide 05h by 02h
mvi a, 05h
mvi b,02h
mvi c,00h
aaa:
sub b
jc down
inr c
jmp aaa
down:
add b
mov l,a
mov h,c
hlt
here the quotient will be stored in H register and remainder in L register

Program to seperate even numbers from the list of 10 bytes of data stored starting from memory address 2000h and stored it it memory location starting from 4000h.

lxi h,2000h
lxi d,4000h
mvi c, 0ah
aaa:
mov a,m
mov b,a
rrc
jc down
mov a,b
stax d
inx d
down:
inx h
dcr c
jnz aaa
hlt


Program to seperate odd numbers from the list of 10 bytes of data stored starting from memory address 2000h and stored it it memory location starting from 4000h.

lxi h,2000h
lxi d,3000h
mvi c, 0ah
aaa:
mov a,m
mov b,a
rrc
jnc down
mov a,b
stax d
inx d
down:
inx h
dcr c
jnz aaa
hlt

10 bytes of data are stored starting from memory location C000h.If the data contains "1" in bit position A2 and A4 replace the sata with EDh ,otherwise leave the data as it was.


lxi h,2000h
mvi c,0ah
aaa:
mov a,m
rrc
rrc
rrc
jnc down
rrc
rrc
jnc down
mvi m,edh
down:
inx h
dcr c
jnz aaa
hlt

Wap to sort the 10 bytes of data stored from memory address 2000h
( hint use bubble sorting)

mvi d,09h
bbb:
lxi h, 2000h
mvi c, 09h
aaa:
mov a,m
inx h
cmp m
jnc down
mov b,m
mov m,a
dcx h
mov m,b
inx h
down:
dcr c
jnz aaa

dcr d
jnz bbb

hlt


Write a program to add 10 bytes of data each data from memory column 2000h and another data from column 3000h and store it in third column at 4000h
lxi h,2000h
lxi d,3000h
lxi b,4000h
aaa:
ldax d
add m
stax b
jnc down
mvi a,01h
inx b
stax b
down:
inx b
inx d
inx h
mov a,l
cpi 05h
jnz aaa
hlt


A ten bytes of signed data are stored in memory location starting from 2000h, count the number of positive data and output the result at port address 50h or store the result at memory address 3000h

lxi h,2000h 
mvi c,0ah
mvi d,00h
aaa:
mov a,m
ral
jc reject
inr d
reject:
inx h
dcr c
jnz aaa
mov a,d
sta 3000h
out 50h
hlt



A set of ten readings is stored in memory location starting at 1160H. The readings are expected to be positive (<127). WAP to
- Check each reading to determine whether it is positive or negative.
- Reject all negative readings.
- Add all positive readings & display sum in Port 1 and carry in Port 2.

        mvi b, 00h 
        mvi c, 00h
        mvi d, 0ah
        lxi h, 1160h
pqr: mov a, m
        ral
        jc next
        rar
        add b
        jc abc
        mov b, a
abc: inr c
next: inx h
        dcr d
        jnz pqr
        mov a, b
        out port 1
        mov a, c
        out port 2
        hlt

A set of six data bytes is stored starting from memory location 2050H. The set includes some blank spaces (bytes with zero values). WAP to eliminate the blanks from the block.

        mvi d, 06h

        lxi h, 2050h 
        lxi b, 2050h
abc: mov a, m
        cpi 00h
        jz xyz
        stax b
        inx b
xyz: inx h
        dcr d
        jnz abc
        hlt






No comments: