Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does an X-bit computer work with 2X-bit numbers?

This isn't the first time the question occurred to me, but I was playing an old SNES game today when I thought about it again and wanted to seek an answer from people who know more about it than I do.

Take the Super Nintendo for example. It's a 16-bit system. With 16 bits, you can count up to 65536, or 2^16. So how does the machine cope with me having, for instance, a score of greater than 65536?

like image 894
Ryan Ries Avatar asked May 26 '13 01:05

Ryan Ries


1 Answers

In reality it's a bit more complex, but the simple explanation is that a 16bit processor can do a operations on 16 bit numbers in a single operation, and to deal with larger numbers you need to break things up. For example to add two 32-bit numbers, you would add least significant words in one operation, then add the most significant words and then add any carry bits.

Obviously this is much slower (3 instructions instead of one), but almost any operation can be done if needed. This is a reason that processors with larger words can be faster; they can do larger operations with a single instruction instead of several instructions. From the programmers point of view, the compiler will usually take care of this, you'd never do it by hand unless you're writing assembly.

In reality though, many processors have dedicated hardware to do math operations, so calling a processor 32-bit or 64-bit really has more to do with memory addressing and the size of registers.

like image 184
stevenstevensteven Avatar answered Oct 30 '22 14:10

stevenstevensteven