On 01-Nov-04 Mark Rogers wrote:
Ted Harding writes:
The basic idea was that an 8-bit byte would store two decimal digits, one in each half-byte ("nibble") of 4 bits, of course in binary form "0" = 0000, "1" = 0001, ... , "8" = 1000, "9" = 1001. The only arithmetic available is add or subtract, which operate on full 8-bit or 16-bit binary numbers. However,
[...] A key advantage in pocket calculators and similar is that the raw data as presented on the databus can easily be split out four bits (ie four "wires") at a time, each going to a seperate 7-seg display, which have internal logic to decode those four bits into the 0-9 digits. Without that a *lot* of extra logic is required.
Agreed! (BTW, anyone remember the earliest vacuum-tube based calculators where the display was a rack of tubes with chunks of wire in which glowed? Similar visual principle to the 7-seg LCD display, and I suppose might be supported by a similar logic; though I doj't know about that, and used to wonder ... ).
[...] However, I'm still not clear on the specific connection with fractional numbers. BCD to me is just a different way of representing decimal integers (and at its simplest means internal instructions which allow incrementing 9 to result in 16(dec) = 10(hex)). Maybe I'm looking too hard...
Well, I suppose it's swings and roundabouts again. Nothing stops you programming arbitrary-precision arithmetic in binary throughout -- indeed it's probably simpler that way. You just set up a long string of bytes with as many bits as you are going to need, and off you go. The native instruction set will cope directly with arithmetic on the short "words" in the string, and a bit of footwork with the "carry" bits enables you to glue it all together.
However, when it comes to presenting the decimal output to the user, it gets more complicated. Suppose you have been working to (say) 3 Kbit binary (about 1000 decimal digits). Stripping out the integer part of the decimal digits would'nt be too hard; but 0.1, 0.01m 0.001, ... is more of a mess: each is theoretically an infinite string of binary bits, so you have to first work out what 0.1 is to 3K binary places, subtract that till it goes negative (goving you the multiple of 0.1), then the same for 0.01, and so on.
It's much easier in that context to work in BCD throughout. Programming the BCD arithmetic operations is straightforward, and the human-readable answer is then just sitting there. Indeed, the program 'bc' which I described earlier stores its numbers internally in decimal.
PS: I also have that Zilog manual, although it's not as readily to hand as yours clearly is :-)
Well, that's only the case by virtue of the coincidence that I've lately been "organising" stacks of things that I've been hoarding for years. A few days ago I came across my box of stuff from the Z80-CP/M era, and there it was. A week ago, and I wouldn't have known where mine was either!
On of my first major programming applications, written in my teens and as far as I know still in use today in a pretty high-profile location, was a Z80-based protocol converter allowing two radically different fire alarm systems to talk to each other. I have fond memories of that chip!
So do I! My first major personal computer was a Sharp MZ-80B, very nice, and Z80-A based. And CP/M was remarkable in what it could fit into the top few K of 64K of RAM.
But I'd first learned the chip on the Sinclair ZX-81, actually disassembling the ROM by hand with pencil and paper (and the Z80 ref manual to hand). Incidentally, the ZX-81 stored numbers, and did arithmetic on them, in a very strange format. Not BCD at all, and not straight binary floats either, but binary floats with weird extras. I never worked out why they did it that way.
-- Mark Rogers, More Solutions Ltd :: Tel: 0845 45 89 555
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 [NB: New number!] Date: 01-Nov-04 Time: 10:44:50 ------------------------------ XFMail ------------------------------