Saturday, 15 October 2011

To find factorial of a number.

To find factorial of a number we can use the same procedure as in C++ programming.


CODE:



MVI B,05
MOV C, B
DCR C
LABEL2: MOV E, C
SUB A
LABEL1: ADD B
DCR E
JNZ LABEL1
MOV B, A
DCR C
JNZ LABEL2
STA 00H
HLT




Screen Shot:



To multiply two numbers.

To multiply two numbers we can use multiple addition of that number up to the second number.

CODE:



MVI D,3
MVI B,2
MVI A,00
LABEL: ADD D
DCR B
JNZ LABEL
HLT




Screen Shot:

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:




Monday, 10 October 2011

8085 Architecture


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