
I’ve problem with the size of long int on a 16-bit CPU. Looking at its architecture:

No register is more than 16-bit long. So, how come long int can have more than 16bits. In fact, according to me for any Processor, the maximum size of the data type must be the size of the general purpose register. Am I right?
Yes. In fact the C and C++ standards require that
sizeof(long int) >= 4.*(I’m assuming
CHAR_BIT == 8in this case.)This is the same deal with 64-bit integers on 32-bit machines. The way it is implemented is to use two registers to represent the lower and upper halves.
Addition and subtraction are done as two instructions:
On x86:
addandadcwhereadcis “add with carry”subandsbbwheresbbis “subtract with borrow”For example:
will compile to something like:
Where
eaxandedxare the lower and upper parts ofa. Andebxandecxare the lower and upper parts ofb.Multiplication and division for double-word integers is more complicated, but it follows the same sort of grade-school math – but where each “digit” is a processor word.