Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Examples.

Similar presentations


Presentation on theme: "Programming Examples."— Presentation transcript:

1 Programming Examples

2 The following listing show the same function using indirect addressing
Example 1: Write a program to store the data byte FFH in memory location 9000H MVI A, FFH ; STORE FFH IN THE ACCUMULATOR STA 9000H ; COPY ACCUMULATOR CONTENTS TO THE ADDRESS 9000H HLT ; STOP PROGRAM EXECUTION The following listing show the same function using indirect addressing LXI H, 9000H ; LOAD HL EITH 9000H MVI A, FFH ; STORE FFH IN THE ACCUMULATOR MOV M,A ; STORE FFH IN MEMORY LOCATION POINTED BY THE HL REGISTER PAIR HLT ; STOP PROGRAM EXECUTION

3 Example 2: Write a program to exchange the contents of memory location 9000H and 9050H
LDA 9000H ;Load the contents of memory location 9000H in the accumulator MOV C,A ; Move the contents of the accumulator in register C LDA 9050H ;Load the contents of memory location 9050H in the accumulator STA 9000H ; STORE THE CONTENTS OF THE ACCUMULATOR IN MEMORY ADDRESS 9000H MOV A,C ; Move the saved contents in register C back to the accumulator STA 9050H ; Store the contents of the accumulator in 9050H HLT ; STOP PROGRAM EXECUTION

4 The following listing show the same function using indirect addressing
LXI H, 9000H ;Load the first address 9000H in the HL register pair LXI D, 9050H ;Load the second address 9050H in the DE register pair MOV C, M ;Move the contents of memory location 9000H to register C LDAX D ; Move the contents of memory location 9050H to the accumulator MOV M, A ; Store the contents of the accumulator in memory location 9000H MOV A, C ; Move the contents of register C to the accumulator STAX D ; Store the contents of the accumulator in memory location 9050H HLT ; STOP PROGRAM EXECUTION

5 Example 3: Write a program to add the values presented in memory locations 9000H and 9001H, then store the results in memory location 9002H LXI H, 9000H ;Load the first address 9000H in HL MOV A, M ; Load the first operand in the accumulator INX H ;Increment HL by 1 so it will point to the second memory location ADD M ; Add the contents of the memory location to the accumulator ; Increment HL MOV M, A ; Store the contents of the accumulator in 9002H HLT ; STOP PROGRAM EXECUTION

6 Example 4: Write a program to subtract the values presented in memory locations 9000H and 9001H, then store the results in memory location 9002H Homework

7 Example 4: Write a program to add two 16-bit values presented in memory locations 9000H and 9001H, and 9002H and 9003H, then store the results in memory location 9004H and 9005H. Note the most significant bytes are 9001H, 9003H and 9005H LHLD 9000H ; Load the first 16 bit value to HL XCHG ; Save the value of HL in DE LHLD 9002H ; Load the second 16-bit value in HL MOV A, E ; Move the lower byte of the first value to A ADD L ; Add the lower bytes of the two numbers MOV L, A ; Store the result in L MOV A, D ; Move the higher byte of the first value to A ADC H ; Add the higher bytes with carry MOV H, A ; store the results in H SHLD 9004H ; store the results in memory location 9004H HLT ; Stop the program

8 LHLD 9000H ; Load the first 16 bit value to HL
XCHG ; Save the value of HL in DE LHLD 9002H ; Load the second 16-bit value in HL DAD D ; Add the contents of DE to HL SHLD 9004H ; store the results in memory location 9004H HLT ; Stop the program


Download ppt "Programming Examples."

Similar presentations


Ads by Google