microprocessor intel 8086 programs

11
Microprocessor & Interfacing Assignment Name : Pushkar Anand Roll no. : BE/1322/2010 Semester : 5 th Branch : Information Technology

Upload: pushkar-anand

Post on 28-Apr-2015

121 views

Category:

Documents


3 download

DESCRIPTION

There are few 8086 programming question which are solved and tested on 8086. Main focus of this document is implementing Selection Sort Algorithm on 8086.

TRANSCRIPT

Page 1: Microprocessor Intel 8086 programs

Microprocessor & Interfacing Assignment

Name : Pushkar Anand Roll no. : BE/1322/2010 Semester : 5th Branch : Information Technology

Page 2: Microprocessor Intel 8086 programs

56. Six unpacked BCD numbers are given at random in 0C20H. Write

a program to form the largest 6-digit number which can be

formed by them and keep it in 0C40H.

;Sorting 0C20 to 0C25 mvi b, 00h oloop: lxi d, 0c20h lxi h, 0c21h mvi c, 01h iloop: ldax d cmp m jz next jc next mov d, h ;if the no. found is smallest till mov e, l ;now then it is saved in DE pair next: inx h inr c mvi a, 06h ;checking if c = 6 - b sub b cmp c jnz iloop dcx h mov a, m ;last memory is swapped with smallest no. xchg mov c, m xchg mov m, c stax d inr b mvi a, 06h cmp b jnz oloop

Page 3: Microprocessor Intel 8086 programs

;now forming the greatest no. possible lxi d, 0c40h lxi h, 0c20h mvi c, 03h again: mov a, m rlc rlc rlc rlc inx h ora m xchg mov m, a inx h mov a, m xchg inx h dcr c jnz again hlt

Page 4: Microprocessor Intel 8086 programs

57. Write a program to select only even bytes from a group of 12 bytes residing in locations starting from 0C30H and arrange them in ascending order from 0C41H. Keep the count (BCD) in 0C40H.

;Sorting 0C20 to 0C2B mvi b, 00h oloop: lxi d, 0c20h lxi h, 0c21h mvi c, 01h iloop: ldax d cmp m jz next jc next mov d, h ;if the no. found is smallest till mov e, l ;now then it is saved in DE pair next: inx h inr c mvi a, 0ch ;checking if c = 12 - b sub b cmp c jnz iloop dcx h mov a, m ;last memory is swaped with smallest no. xchg mov c, m xchg mov m, c stax d inr b mvi a, 0ch cmp b jnz oloop

Page 5: Microprocessor Intel 8086 programs

; copying even bytes to 0c41 mvi c, 00h mvi b, 0ch lxi h, 0c20h final: mov a, m ani 01h jnz check inr c mov d, m mov e, l mov a, c adi 40h mov l, a mov m, d mov l, e check: inx h dcr b jnz final mov a, c adi 00h daa sta 0c40h hlt

Page 6: Microprocessor Intel 8086 programs

58. 12 nos. are given at random (6 are even and 6 are odd) in locations starting from 0C20H. Write a program to arrange them alternatively first odd and next even in the same locations.

mvi b, 0ch mvi c, 00h mvi d, 00h lxi h, 0c20h loop: mov a, m ani 01h cpi 00h jnz odd mov e, m ; seprating even no. lxi h, 0c30h mov a, l add c mov l, a mov m, e inr c jmp check odd: mov e, m ; seprating odd no. lxi h, 0c40h mov a, l add d mov l, a mov m, e inr d check: lxi h, 0c20h mov a, l add c add d mov l, a dcr b

Page 7: Microprocessor Intel 8086 programs

jnz loop mvi b, 06h lxi h, 0c40h lxi d, 0c20h loop1: mov a, m ;arranging odd no. xchg mov m, a inx h inx h xchg inx h dcr b jnz loop1 mvi b, 06h lxi h, 0c30h lxi d, 0c21h loop2: mov a, m ;arranging even no. xchg mov m, a inx h inx h xchg inx h dcr b jnz loop2 hlt

Page 8: Microprocessor Intel 8086 programs

59. 8 hexadecimal nos. are given in locations starting from OC20H. Write a program to form the smallest 8-digit binary no. and store it in 0C40H.

;seperating higher and lower nibble of hexadecimal no. mvi b, 08h lxi h, 0c20h loop: mov a, m ani fh mov c, a mov a, m ani f0h rrc rrc rrc rrc mov m, a mov a, l adi 08h mov l, a mov m, c mov a, l sui 08h mov l, a inx h dcr b jnz loop ;sorting the numbers mvi b, 00h oloop: lxi d, 0c20h lxi h, 0c21h mvi c, 01h iloop: ldax d

Page 9: Microprocessor Intel 8086 programs

cmp m jz next jc next mov d, h ;if the no. found is smallest till mov e, l ;now then it is saved in DE pair next: inx h inr c mvi a, 10h ;checking if c = 16 - b sub b cmp c jnz iloop dcx h mov a, m ;last memory is swaped with smallest no. xchg mov c, m xchg mov m, c stax d inr b mvi a, 16h cmp b jnz oloop ;forming 8 digit binary no. lxi h, 0c2fh mov a, m rlc rlc rlc rlc dcx h ora m sta 0c40h hlt

Page 10: Microprocessor Intel 8086 programs

60. 3 groups of 12 bytes each are given in 3 locations starting from DATA1, DATA2 and DATA3. Write a program to form a 4th group, with largest of all groups and store it in locations starting from DATA4. (The nth byte of 4th group shall be the largest of nth byte of 1st, 2nd and 3rd groups)

mvi b, 04h mvi c, 00h loop: lxi h, DATA1 mov a, l add c mov l, a jnc next mov a, h adi 01h mov h, a next: mov d, m lxi h, DATA2 mov a, l add c mov l, a jnc next1 mov a, h adi 01h mov h, a next1: mov a, d cmp m ; comparing first and second block jnc second mov d, m second: lxi h, DATA3 mov a, l add c mov l, a

Page 11: Microprocessor Intel 8086 programs

jnc next2 mov a, h adi 01h mov h, a next2: mov a, d cmp m ; comparing largest to third block jnc store mov d, m store: lxi h, DATA4 mov a, l add c mov l, a jnc next3 mov a, h adi 01h mov h, a next3: mov m, d inr c dcr b jnz loop hlt