This blog is dedicated to impart programming knowledge about Intel's 8085 micro-processor.
Saturday, 15 October 2011
Friday, 14 October 2011
How to add two numbers without using ADD command?
To add two numbers without using ADD command first we need to understand the basics of addition. The basic of addition is that we increment the first number by 1 upto second number to reach the answer of their additon. The same procedure will be followed here in this program
CODE
MVI A,08
MVI B,54
LABEL: INR A
DCR B
JNZ LABEL
HLT
Screen shot of the program ran in simulator is here:
CODE
MVI A,08
MVI B,54
LABEL: INR A
DCR B
JNZ LABEL
HLT
Screen shot of the program ran in simulator is here:
Monday, 10 October 2011
How to count number of 1's in a byte?
To count the number of 1's in a byte[8 bits] the technique is as follows:-
We use RAR instruction to rotate the D0 bit via CARRY flag and check the status of carry flag for 1. And we count the number of times the CARRY flag is set[ie equal to 1].
Code-
MVI A,FFH ; Load A with Immediate data as FF
MVI B,08 ; Initialize B with 08 for counting
LABEL2: RAR ; Rotate Right through CARRY
JC LABEL1 ; Check for CARRY flag
DCR B ; Decrement counter
JNZ LABEL2 ; Check for number of counting
LABEL1: INR C ; Increment C for number of 1's
DCR B ;
JNZ LABEL2 ;
HLT
We use RAR instruction to rotate the D0 bit via CARRY flag and check the status of carry flag for 1. And we count the number of times the CARRY flag is set[ie equal to 1].
Code-
MVI A,FFH ; Load A with Immediate data as FF
MVI B,08 ; Initialize B with 08 for counting
LABEL2: RAR ; Rotate Right through CARRY
JC LABEL1 ; Check for CARRY flag
DCR B ; Decrement counter
JNZ LABEL2 ; Check for number of counting
LABEL1: INR C ; Increment C for number of 1's
DCR B ;
JNZ LABEL2 ;
HLT
Monday, 3 October 2011
Table of 2
In this program the starting address is taken as 2001H.
The table of 2 {2,4,6,8,.......,20} would be saved in memory location starting from 2001H location.
CODE:
LXI H,2001H ; Make H/L pair as pointer to location 2001H
MVI A,00H ;
MVI B,10 ; Taking Register B as a counter for table
LABEL: ADI 02 ; Add 02 as immediate value toRregister A
MOV M,A ; Save value of Register A to memory location pointed by H
INX H ; Increment the address pointed by Register H
DCR B ; Decrement the B
JNZ LABEL ; Check for ZERO and Jump to LABEL
The table of 2 {2,4,6,8,.......,20} would be saved in memory location starting from 2001H location.
CODE:
LXI H,2001H ; Make H/L pair as pointer to location 2001H
MVI A,00H ;
MVI B,10 ; Taking Register B as a counter for table
LABEL: ADI 02 ; Add 02 as immediate value toRregister A
MOV M,A ; Save value of Register A to memory location pointed by H
INX H ; Increment the address pointed by Register H
DCR B ; Decrement the B
JNZ LABEL ; Check for ZERO and Jump to LABEL
Sunday, 25 September 2011
How to exchange the content of two memory location.
1. Using XCHG operation
Instruction Comment
LXI H, D000 H ; HL pointing to D000 H
LXI D, D001 H ; DE pointing to D001 H
MOV B, M ; B (HL) (first byte)
LDAX D ; Load second byte in ACC.
XCHG ; Exchange DE and HL pair contents.
MOV M, B ; Store first byte in second location
STAX D ; Store second byte in first location.
HLT ; Stop
Foot note:
The XCHG memonic can only be used for exchanging contents of DE and HL pair. So for exchanging the contents of any two memory location its better to make DE and HL as memory pointer.
2. Without using XCHG operation.
Instruction Comment
LXI H,D000H ; HL pointing to D000H
LXI B,D001H ; BC pointing to D001H
MOV D,M ; Move the contents of M to D
LDAX B ; Move the contents of BC to Accumulator
MOV M,A ; Move the contents of BC to HL
STAX D ; Move the contents of HL to BC
HLT ; Stop
Subscribe to:
Posts (Atom)