8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
On Thu, 18 Dec 2025 19:20:09 +0100, Rosario19 wrote:
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
Leor Zolman sometimes hangs out around here; you could ask him about
BDS C for the 8bit Intel 8080.
Alternatively, you could just check out BDS C at https://www.bdsoft.com/resources/bdsc.html.
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
There are no "true" 8 bit systems in this sense, as pretty much every existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every
existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s
or so.
It had a total of 8 bits of storage.
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
On 12/18/2025 12:20 PM, Rosario19 wrote:
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
There are no "true" 8 bit systems in this sense, as pretty much every existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
So, in this sense, it makes more sense to call them 8/16 instead, as the exact line between 8-bit machines and 16-bit machines is often a little fuzzy (and both tend to look basically similar as far as C is concerned;
for the machines big enough to where running C on them is viable).
One could then ask, what would a minimal 8-bitter look like.
Might make sense to go with fixed-length 16-bit instructions.
Likely 8x8b registers;
...
Say:
AL, AH
BL, BH
CL, CH
SP, LR
If you want a 16-bit ADD, you do two:
ADD, ADC
On 18/12/2025 19:20, Rosario19 wrote:
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
No, 8-bit cpus don't need 16-bit registers or 16-bit operations. 8-bit cpus typically only have 8-bit general registers (though most will have
a 16-bit PC register). Some will allow you to use a couple of 8-bit registers in a pair, primarily for memory addressing, but a pair of 8-
bit registers is not the same as a 16-bit register.
The C requirement for a minimum size of 16-bit int, together with the integer promotion rules, is one of the reasons C was often considered inefficient and inappropriate for small 8-bit microcontrollers.
On 19/12/2025 08:19, David Brown wrote:
On 18/12/2025 19:20, Rosario19 wrote:
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
No, 8-bit cpus don't need 16-bit registers or 16-bit operations.
8-bit cpus typically only have 8-bit general registers (though most
will have a 16-bit PC register). Some will allow you to use a couple
of 8-bit registers in a pair, primarily for memory addressing, but a
pair of 8- bit registers is not the same as a 16-bit register.
The C requirement for a minimum size of 16-bit int, together with the
integer promotion rules, is one of the reasons C was often considered
inefficient and inappropriate for small 8-bit microcontrollers.
I'm targeting Z80 right now from my systems language.
As well as making 'int' 16 bits, I've removed the promotion rules. This means 8-bit quantities needing to be cast to 16 bits as needed.
So if 'a b c' are 8 bits, and 'x' is 16 bits then the Clang Z80 compiler generates 8-bit code only for:
a = b + c;
No promotions.
But here:
x = b + c;
'b' and 'c' are first widened to 16 bits (using some ugly code when they
are signed).
This is where my language will differ: b + c produces an 8-bit result,
and it is that that is widened.
Casts are needed to emulate the behaviour of the auto-widening done in
C. But this means somewhat more efficient code with a simpler compiler.
On 19/12/2025 14:43, bart wrote:
I'm targeting Z80 right now from my systems language.
This is where my language will differ: b + c produces an 8-bit result,
and it is that that is widened.
Okay. I think that is a better choice for a language for 8-bit devices than the choice C made. I understand the rules for C integer promotion, but I don't like them.
Casts are needed to emulate the behaviour of the auto-widening done in
C. But this means somewhat more efficient code with a simpler compiler.
Yes.
Why are you targeting the Z80? Is it just for fun?
It was a great
device in its time, and I learned a lot of assembly with that processor,
but has been decades since it was used for anything new. While the
chips are still available,
On 19/12/2025 15:16, David Brown wrote:
On 19/12/2025 14:43, bart wrote:
I'm targeting Z80 right now from my systems language.
This is where my language will differ: b + c produces an 8-bit
result, and it is that that is widened.
Okay. I think that is a better choice for a language for 8-bit
devices than the choice C made. I understand the rules for C integer
promotion, but I don't like them.
I think it is a better choice for a capable processor, and I actually adopted C's approach at some point.
Currently it works very well for my 64-bit product, but here C stops
short at promoting only to 32 bits! (When 'int' is 32 bits.) So you have
a mix of auto-promotion plus explicit casts to 64 bits.
Casts are needed to emulate the behaviour of the auto-widening done
in C. But this means somewhat more efficient code with a simpler
compiler.
Yes.
Why are you targeting the Z80? Is it just for fun?
Mostly, yes. My Z80 will be emulated, and I hadn't worked on an emulator before.
Currently, emulated Z80 code runs at an equivalent clock-speed of 2-4GHz (for whole-instruction-based emulation; some emulate clock-by-clock and
do pin-signals too).
The original Z80s ranged from 2.5 to 8MHz. (Newer Z80-based CPUs take
fewer clocks per instruction, and may use pipelining.)
The other side of it is in exercising the IL I use for my compilers, and seeing how well it can cope with a small device. My product will be a cross-compiler, and it'll be a novelty seeing modern language features
(lots don't depend on target capabilities) be used for such a device.
(I wrote real Z80 compilers in the past; those actually ran on the Z80!
But were crude.)
It was a great device in its time, and I learned a lot of assembly
with that processor, but has been decades since it was used for
anything new. While the chips are still available,
They stopped making Z80 chips in 2024 (you can still get Z180 etc). I've
got one on my shelf somewhere (decades ago my company bought them in
bulk!). I might get around to using it for real.
On 19/12/2025 17:05, bart wrote:
Currently it works very well for my 64-bit product, but here C stops
short at promoting only to 32 bits! (When 'int' is 32 bits.) So you
have a mix of auto-promotion plus explicit casts to 64 bits.
I think making "int" 64-bit would have been a bad choice overall for C.
The key issue is that there is a conflict of uses and efficiency on 64-
bit processors between "a type that is fast and convenient for local
use" and "a type that is big enough to handle most numbers, and fast and efficient for storage". Data in memory, especially in arrays, is more efficient if it is smaller
- 32-bit is still a good size for the
majority of numbers stored in memory. For local variables in registers,
or even on the stack, 64-bit is more efficient on x86-64 as it avoids
the need of any kind of sign or zero extension or masking.
However, given that such a
large proportion of code was written with the assumption that "int"
always means 32-bit, it made sense to keep it at 32-bit.
On 19/12/2025 17:57, David Brown wrote:
On 19/12/2025 17:05, bart wrote:
[Default size 'int' being 32 or 64 bits]
Currently it works very well for my 64-bit product, but here C stops
short at promoting only to 32 bits! (When 'int' is 32 bits.) So you
have a mix of auto-promotion plus explicit casts to 64 bits.
I think making "int" 64-bit would have been a bad choice overall for C.
The key issue is that there is a conflict of uses and efficiency on
64- bit processors between "a type that is fast and convenient for
local use" and "a type that is big enough to handle most numbers, and
fast and efficient for storage". Data in memory, especially in
arrays, is more efficient if it is smaller
Sure. Then you choose the smallest size that can represent all likely values.
But if you don't know the range of values, would you just use 'int' and
hope nothing is outside the i32 range? Or would you use 64 bits?
If the latter, then a default i64 size (with a range /4 billion times
wider/ than i32) can make more sense.
- 32-bit is still a good size for the majority of numbers stored in
memory. For local variables in registers, or even on the stack, 64-
bit is more efficient on x86-64 as it avoids the need of any kind of
sign or zero extension or masking.
One mild downside on x64 is the need for a 'REX' prefix on some
instructions that work on 64-bits (to set the 'W' bit). Unless the instructions already use x64's 8 extra registers so the prefix is needed anyway.
However, given that such a large proportion of code was written with
the assumption that "int" always means 32-bit, it made sense to keep
it at 32-bit.
Could the same assumptions have been made about 'long'? I guess was
'long' was 32 bits when 'int' was 16 bits, then when the latter became
32 bits, 'long' stayed the same...
...until 64 bit machines came along. Then 'int' stayed the same, but
'long' became 64 bits - on some OSes but not others!
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every
existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s
or so.
There are no "true" 8 bit systems in this sense, as pretty much every existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
On 2025-12-18, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every
existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s
or so.
Any guitar pedal with an electronic bypass toggle is a 1 bit system.
Kaz Kylheku <046-301-5902@kylheku.com> writes:
On 2025-12-18, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every
existing 8-bit CPU has had support for 16-bit operations in some way,
though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s >>> or so.
Any guitar pedal with an electronic bypass toggle is a 1 bit system.
But not a 1-bit computer.
The system I referred to above was an actual computer with 8 bits of
storage.
On 21/12/2025 02:55, Keith Thompson wrote:
Kaz Kylheku <046-301-5902@kylheku.com> writes:
On 2025-12-18, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:But not a 1-bit computer.
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every >>>>> existing 8-bit CPU has had support for 16-bit operations in some way, >>>>> though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s >>>> or so.
Any guitar pedal with an electronic bypass toggle is a 1 bit system.
The system I referred to above was an actual computer with 8 bits of
storage.
Do you really mean a total of 8 bits of storage, or do you mean
storage addressable by 8 bits (thus avoiding the need for any 16-bit registers or other registers bigger than 8 bits) ?
David Brown <david.brown@hesbynett.no> writes:
On 21/12/2025 02:55, Keith Thompson wrote:
Kaz Kylheku <046-301-5902@kylheku.com> writes:
On 2025-12-18, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:But not a 1-bit computer.
BGB <cr88192@gmail.com> writes:
[...]
There are no "true" 8 bit systems in this sense, as pretty much every >>>>>> existing 8-bit CPU has had support for 16-bit operations in some way, >>>>>> though often by using register pairs.
I vaguely recall reading about a true 8-bit system, maybe from the 1950s >>>>> or so.
Any guitar pedal with an electronic bypass toggle is a 1 bit system.
The system I referred to above was an actual computer with 8 bits of
storage.
Do you really mean a total of 8 bits of storage, or do you mean
storage addressable by 8 bits (thus avoiding the need for any 16-bit
registers or other registers bigger than 8 bits) ?
As I wrote in the original followup, in context that was later
snipped, "It had a total of 8 bits of storage."
I think it used vacuum tubes.
I can't find a reference. As you can imagine, web searches for
"8-bit computer" are not productive.
There could be any number of reasons why it wouldn't qualify as a programmable computer. I don't remember, or never knew, the details.
8 bit cpu for access memory other than 0..255 location has need at
last one 16 bit register and 16 bits operations, so i think that even
a 8 bit cpu has to have int in C language as 16 bits
I do not know whether C standards permit 8-bit ints,
but[...]
cc65 is a real-world 6502 C cross-compiler available straight
from the standard repositories on Fedora Linux 43 and FreeBSD 15.
We can install cc65 and VICE emulator to do a simple test:
kalevi@kolttonen.fi (Kalevi Kolttonen) writes:
[...]
I do not know whether C standards permit 8-bit ints,
It does not. C (up to C17) requires INT_MIN to be -32767 or lower,
and INT_MAX to be +32767 or higher. (C23 changes the requirement
for INT_MIN from -32767 to -32768, and mandates 2's-complement for
signed integer types.)
but[...]
cc65 is a real-world 6502 C cross-compiler available straight
from the standard repositories on Fedora Linux 43 and FreeBSD 15.
We can install cc65 and VICE emulator to do a simple test:
I have cc65 on my Ubuntu system. Here's how I demonstrated the same
thing (that sizeof (int) is 2):
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,090 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 45:25:00 |
| Calls: | 13,946 |
| Calls today: | 3 |
| Files: | 187,034 |
| D/L today: |
8,063 files (2,942M bytes) |
| Messages: | 2,460,945 |