UNIT 4 Programming in 8085 4 1addition and

  • Slides: 22
Download presentation
UNIT 4 Programming in 8085

UNIT 4 Programming in 8085

(4. 1)addition and subtraction programmes (1)Write a program to add two 8 bit numbers.

(4. 1)addition and subtraction programmes (1)Write a program to add two 8 bit numbers. MVI A, 12 H MVI B, 17 H ADD B HLT

(2) Write a program to add two 8 bit numbers which are stored at

(2) Write a program to add two 8 bit numbers which are stored at memory location. LDA 2050 H MOV B, A LDA 2051 H ADD B HLT

(3) Write a program to add two 16 bit number. LXI H, 2032 H

(3) Write a program to add two 16 bit number. LXI H, 2032 H LXI B, 4262 H MOV A, L ADD C MOV L, A MOV A, H ADC B MOV H, A HLT

(4)Write a program to add two 16 bit number using DAD. LXI H, 5746

(4)Write a program to add two 16 bit number using DAD. LXI H, 5746 H LXI B, 7647 H DAD B HLT

(4. 2) (6)Write a program to multiply two 8 bit numbers. • MVI A,

(4. 2) (6)Write a program to multiply two 8 bit numbers. • MVI A, 00 H • • • MVI B, 15 H MVI C, 05 H MVI D, 00 H BACK: ADD B JNC L 1 INC D DEC C JNZ BACK END

(7)Write a program for division. MVI A, 15 H MVI B, 2 H BACK:

(7)Write a program for division. MVI A, 15 H MVI B, 2 H BACK: SUB B JC NEXT JMP BACK NEXT: ADD B HLT • • •

(4. 3)Looping Counting and Indexing

(4. 3)Looping Counting and Indexing

 • (8)Write a program to move a block of data start at location

• (8)Write a program to move a block of data start at location 2051 h to 4051 h. the length of the block is given in memory location 2050 h. . • LXI H, 2050 H • MOV C, M • INX H • LXI B, 4051 H • NEXT: MOV A, M • STAX B • DCR C

 • • • JZ OVER INX H INX B JMP NEXT OVER: NOP

• • • JZ OVER INX H INX B JMP NEXT OVER: NOP HLT

(9)Write a program to find maximum no. from block of numbers stored in memory.

(9)Write a program to find maximum no. from block of numbers stored in memory. LXI H, 2050 H MOV C, M MVI A, 00 H NEXT: INX H CMP M JNC SKIP

 • • • MOV A, M SKIP: DCR C JNZ NEXT INX H

• • • MOV A, M SKIP: DCR C JNZ NEXT INX H MOV M, A HLT

(4. 4) • PROGRAM BASED ON LOGICAL OPERATION

(4. 4) • PROGRAM BASED ON LOGICAL OPERATION

 • (10)Write a program to mask the lower 4 bit of the content

• (10)Write a program to mask the lower 4 bit of the content of the memory location 2050 h. • • • LDA 2050 H MOV B, F 0 H ANA B STA 2050 H HLT

 • (11)Write a program to set higher 4 bit of content of the

• (11)Write a program to set higher 4 bit of content of the memory location 2050 h to 1. • • LDA 2050 H ORI F 0 H STA 2050 H HLT

(4. 5)COUNTER AND TIMING DELAY (12)Write a program to count 0 to 9 repeatedly

(4. 5)COUNTER AND TIMING DELAY (12)Write a program to count 0 to 9 repeatedly with 1 ms delay between two successive counts. • • START: MVI A, 00 H NEXT: ACALL DELAY INR A CPI 0 AH

 • • JNZ NEXT JMP START DELAY: MVI C, 8 EH NEXT: DCR

• • JNZ NEXT JMP START DELAY: MVI C, 8 EH NEXT: DCR C JNZ NEXT RET HLT

(4. 6) STACK and SUBROUTINES • What is Stack? Stack is a temporary storage

(4. 6) STACK and SUBROUTINES • What is Stack? Stack is a temporary storage memory and it is a part of RAM. - It works in a LIFO manner. - Operation related stack are PUSH and POP. - The CALL instruction uses stack to store return address , while RET instruction uses stack to get return address.

 • PUSH: Push instruction is used to store the data temporary. • POP:

• PUSH: Push instruction is used to store the data temporary. • POP: Pop instruction is used to get data back from stack. • SUBROUTINE: The repeated group of instruction can be defined as subroutine. A subroutine itself is a self contained small program that performs a small but specific task.

(13)Write a subroutine program to exchange two 8 bit numbers. use it to reverse

(13)Write a subroutine program to exchange two 8 bit numbers. use it to reverse a given block of data as follows. • Given data: 32 h, 55 h, 62 h, 37 h, E 2 h, 75 h • Result: 75 h, E 2 h, 37 h, 62 h, 55 h, 32 h • LXI H, 2050 H • MOV D, M • LXI B, 2050 H

 • • • MOV A, D ADD C MOV C, A INX H

• • • MOV A, D ADD C MOV C, A INX H NEXT: MOV E, M LDAX B CALL EXCH MOV M, E STAX B MOV A, L

 • • • CMP C JNC OVER INX H DCX B JMP NEXT

• • • CMP C JNC OVER INX H DCX B JMP NEXT OVER: HLT EXCH: PUSH B MOV B, A MOV A, E MOV E, B POP B RET