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
Subscribe to:
Posts (Atom)