I have 47, in binary it's 0010 1111. I need to split 47 so I get 4 in binary 0000 0100 and 7 in binary 0000 0111.
I have see this answer but I wonder, as Intel 8085 doesn't have a div instruction I have to divide by doing consecutive subtractions, how do I get modulus as doing it so?
If your processor doesn't have a divide instruction (or BCD conversion instructions, which would be another way), you'll just have to do repeated subtraction. The pseudo-code for this would go something like:
Apologies for the rather BASIC coding style there, I just tried to make it a little closer to how it would look in assembler language. Otherwise, I would have used a
while
loop :-)Tho modulus is what's left in the
units
variable once it drops below ten.For completeness (and possibly extra marks if this is a homework assignment, nudge nudge, wink wink), since a single octet can handle up to 255:
As proof this method works, you can try the following Python code:
which does indeed output:
In terms of using those values to drive a LED device, a simple lookup table is probably easiest. Construct an array of values that you need to write to the two 8-bit memory addresses then use the digit to lookup those values for writing to the device.
I'll use a simplified seven-segment LED (plus decimal point) since it's easier to understand:
Let's say in this example that you write a single byte
abcdefgh
to a memory-mapped location and the bits in this byte control what segments are on.The values for the different digits (without the decimal point) are (untested, so may need some tweaking):
Given the value four, you would simply look up the byte at offset 4 in that table (using simple addition of the base address of the table and the value), then extract that byte from memory and use it to set the LED segments. That value
01100110
will set segmentsb
,c
,f
andg
, giving you:Your particular situation is a little more complicated since you have a fifteen-segment LED and have to write a word rather than a byte, but the theory is exactly the same.
Have a table of values that you need to write for each digit and use the values calculated from my algorithm above to offset into that table.