Printing Numbers – Part 3

The third system for printing numbers is very similar to the second – where we stored each digit of the number separately.  This gave us complete control over how big the number could be, and removed some of the drawbacks of storing the number as an 8 or 16-bit value.

However… doesn’t it seem a little wasteful to store a single digit – 0 to 9 – using a whole byte?  And doesn’t it also seem a little strange there there appears to be no support for doing this kind of thing in Z80 itself?  Surely it’s not such a ‘custom’ concept?

Well, welcome to Binary Coded Decimal!

Continue reading

Advertisements

Printing numbers – Part 2

So we’ve covered the method required for printing the value from an 8 or 16-bit register, but have found two drawbacks with it – the size of the number we can print, and the time it takes to print it (as it has to keep looping for each value in each numeric ‘column’)  I also hinted that there are at least two other methods you can use for doing this tasks, and both rely on using a more ‘direct’ method for storing the number – just store the digits themselves instead of using binary as the registers do.

Continue reading

Printing numbers – Part 1

Something which is very simple in BASIC is to print a number:

10 LET A = 42
20 PRINT A

Easy as that.  This isn’t quite so simple in machine code however, as you need to work out, and print, each ‘column’ of the number – the units, the tens, the hundreds, and so on.

There are a number of different ways to do this – I can think of 3 which work well – with each having it’s own pros and cons, so will start with the most simple – printing a number from a register.

Continue reading