Você está na página 1de 11

Microprocessor & Interfacing Assignment

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

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 mov e, l next: inx h inr c mvi a, 06h sub b cmp c jnz iloop dcx h mov a, m xchg mov c, m xchg mov m, c stax d inr b mvi a, 06h cmp b jnz oloop

;if the no. found is smallest till ;now then it is saved in DE pair

;checking if c = 6 - b

;last memory is swapped with smallest no.

;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

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 mov e, l next: inx h inr c mvi a, 0ch sub b cmp c jnz iloop dcx h mov a, m xchg mov c, m xchg mov m, c stax d inr b mvi a, 0ch cmp b jnz oloop

;if the no. found is smallest till ;now then it is saved in DE pair

;checking if c = 12 - b

;last memory is swaped with smallest no.

; 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

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 mov a, m ani 01h cpi 00h jnz odd mov e, m lxi h, 0c30h mov a, l add c mov l, a mov m, e inr c jmp check mov e, m lxi h, 0c40h mov a, l add d mov l, a mov m, e inr d lxi h, 0c20h mov a, l add c add d mov l, a dcr b

loop:

; seprating even no.

odd:

; seprating odd no.

check:

loop1:

loop2:

jnz loop mvi b, 06h lxi h, 0c40h lxi d, 0c20h mov a, m xchg mov m, a inx h inx h xchg inx h dcr b jnz loop1 mvi b, 06h lxi h, 0c30h lxi d, 0c21h mov a, m xchg mov m, a inx h inx h xchg inx h dcr b jnz loop2 hlt

;arranging odd no.

;arranging even no.

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

cmp m jz next jc next mov d, h mov e, l next: inx h inr c mvi a, 10h sub b cmp c jnz iloop dcx h mov a, m 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

;if the no. found is smallest till ;now then it is saved in DE pair

;checking if c = 16 - b

;last memory is swaped with smallest no.

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 lxi h, DATA1 mov a, l add c mov l, a jnc next mov a, h adi 01h mov h, a mov d, m lxi h, DATA2 mov a, l add c mov l, a jnc next1 mov a, h adi 01h mov h, a mov a, d cmp m jnc second mov d, m lxi h, DATA3 mov a, l add c mov l, a

loop:

next:

next1:

; comparing first and second block

second:

next2:

store:

next3:

jnc next2 mov a, h adi 01h mov h, a mov a, d cmp m jnc store mov d, m lxi h, DATA4 mov a, l add c mov l, a jnc next3 mov a, h adi 01h mov h, a mov m, d inr c dcr b jnz loop hlt

; comparing largest to third block

Você também pode gostar