Friday, April 11, 2014

Is there multiply function in 8085 microprocessor


There is no multiplication instruction in the 8085 - I believe that was added in the 8086 & 8088 version of the series.

This has the entire instruction set for the 8085:

These operations are equivilent to multiplying by 2:

1) Shift left by 1 (shifting left by n is multiplying by 2^n)
2) Add the value to itself once.

Other than that you can write a loop to add the number to itself 'n' times.


Or, if you don't need to generalize you can use the following algorithm:

to multiply an 8 bit value (x) by 3:

.....0 x7 x6 x5 x4 x3 x2 x1 x0 --- (x * 1)
+ x7 x6 x5 x4 x3 x2 x1 x0 0 ---- (x * 2) (x << 1)
--------------------------------------...

to multiply by 5:

.....0...0 x7 x6 x5 x4 x3 x2 x1 x0 ---- (x * 1)
+ x7 x6 x5 x4 x3 x2 x1 x0...0...0 ---- (x * 4) (x << 2)
--------------------------------------...


The "."s are just to get the spacing right

Here is a site with a general bit serial algorithm:



Ooops, I didn't realize there wasn't a shift instruction either.

You can use RAL (rotate left with carry). That will rotate the high order bit to the carry flag and the carry flag to the low order bit. If you need to have the result be greater than 8 bits, you can use the carry flag to shift the bit values into another byte.

If I remember right, the 8085 is a 8 bit processor.
This is how you would shift an 8 bit value, yielding a 16 bit result:

STC
CMC
LDA [a]
RAL
STA [a]
LDA [a+1]
RAL
STA [a+1]

I'm actually more familiar with the 8088/6 and later processors. After looking at the instruction set in more detail, I believe the RAL will not only rotate the high order bit throuh the carry flag, but also rotate the carry flag to the low order bit. That's why you need to clear the carry flag before starting. Since there is no clear carry instruction, the way I did it above was to set the carry flag, then compliment it. Also, it doesn't appear that the RAL instruction allows you to rotate more than one bit at a time.

References
https://in.answers.yahoo.com/question/index?qid=20060917112827AAuPoOe

0 comments:

Post a Comment