Tech notes
    Il "Quarto" fuso ] The 4th Time Zone ]   


 

Introduction
Tech notes


                                   

[ Index ][ Back ]

Format of numbers into the CPU's registers

Three number formats are used: 16 bits, 32 bits and 32 bits floating-point.

The simplest is the 16 bits one that allows to represent a signed integer number between -32768 and +32767 where the sign is kept by the more significant bit; alternatively it allows to represent an unsigned integer number between 0 and 65535.

reg. H L
16 bits sbbb bbbb bbbb bbbb

Into the CPU's registers, an integer is normally handled with the HL registers couple, with the more significant part in H register. In memory, an integer takes up two adjacent bytes. The byte at the lower address contains the less significant part, the one usually stored in L. The byte at the higer address contains the more significant part. 

The second format takes up four bytes, two integer together forming a 32 bits number, called double or long integer, which allows to represent a signed integer number between -2147483648 e +2147483647, and the sign is kept by the more significant bit of the first integer.

reg. H L D E
32 bits sbbb bbbb bbbb bbbb bbbb bbbb bbbb bbbb

Into the CPU's registers, a double is normally handled with the HLDE registers double-couple, where the more significant part is in H register, and so forth, i.e. register E is the less significant byte. In memory, a double takes up four adjacent bytes, splitted in two integer, where the more significant integer (HL) is stored in the locations with the lower address, while the less significant one (DE) is stored in the locatons with higher address. Therefore onto the Stack, the more significant integer is the top of the Stack, and the other is the second accessible.

Stack. CPU Memory
SP+3 D addr+3
SP+2 E addr+2
SP+1 H addr+1
SP+0 L addr+0

The third format requires a 32 bits double, but internally the bits are used in a different way, representing a real number approximately between -1.7 * 10^38 and +1.7 * 10^38 with a 7 digits precision. The sign is stored into the more significant bit, then a 8 bits exponent and a 23 bits mantissa follow.

reg. H L D E
32 bits f.p. seee eeee ebbb bbbb bbbb bbbb bbbb bbbb

Z80 register usage 

BC stores the instruction pointer. SP keeps the data stack pointer

A F  
B C  
D E  
H L  
PC Z80 program counter
SP Stack pointer
IX  
IY  
A' F'  
B' C'  
D' E'  
H' L'  
I R  

[ Index ][ Back ]


Ultimo aggiornamento: 06-09-2002. Copyright (c) 2000-2002 Matteo Vitturi. 
Per problemi o domande relativamente a questo sito contattare il webmaster
Last update: 09.06.2002. Copyright (c) 2000-2002 Matteo Vitturi.
For problems or questions related to this web please contact the webmaster.
1