From 3337e122cc2367b5939cf30869ea7dba854a90bf Mon Sep 17 00:00:00 2001 From: Perry Kivolowitz Date: Fri, 13 Jan 2023 08:18:09 -0600 Subject: [PATCH] added 68K results --- .vscode/settings.json | 28 +++++++++++++++------------- section_3/endian/README.md | 28 ++++++++++++++++++++++------ section_3/endian/main.c | 25 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 section_3/endian/main.c diff --git a/.vscode/settings.json b/.vscode/settings.json index 4861e92..57d7de3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -33,19 +33,21 @@ "MD024":false }, "cSpell.ignoreWords": [ - "Rypo", - "dless", - "dmore", - "foov", - "ndless", - "ndmore", - "onditionally", - "onsole", - "rotypo", - "rwtypo", - "slen", - "ssize" - ], + "Athanasios", + "Pavlidis", + "Rypo", + "dless", + "dmore", + "foov", + "ndless", + "ndmore", + "onditionally", + "onsole", + "rotypo", + "rwtypo", + "slen", + "ssize" + ], "files.associations": { "ostream": "cpp" } diff --git a/section_3/endian/README.md b/section_3/endian/README.md index 5c1e89a..1bd1b32 100644 --- a/section_3/endian/README.md +++ b/section_3/endian/README.md @@ -156,8 +156,25 @@ on a little endian machine, it is the first byte in the long in memory. ## Output on a big endian machine -We tried and tried but could not get anyone to run this code on a -big-endian machine. +We tried and tried to find a kind soul to run the above program on a +big-endian machine. Redditor Athanasios Pavlidis ran a C version of the +code on both an Amiga A4000/MC68040 and an Amiga A3000/MC68030. The +results were: + +```text +Endianness of this computer: +i16: 0123 +i32: 01234567 +i64: 89abcdef01234567 +``` + +Notice the values for `i16` and `i32` match the right hand column above. +The value for `i64` is borked in that we specified it in the C code as a +`long`. We then tried specifying the `long` as a `long long`. Apparently +there is little support for 64 bit numbers on this ancient but +venerable architecture. + +Athanasios Pavlidis has our appreciation and thanks. ## Can't the ARM swing both ways? @@ -169,7 +186,8 @@ install the big-endian version of the toolchain. Here is a quote from Wikipedia: ```text -ARM, C-Sky, and RISC-V have no relevant big-endian deployments, and can be considered little-endian in practice. +ARM, C-Sky, and RISC-V have no relevant big-endian deployments, and can +be considered little-endian in practice. ``` ## What is Intel? @@ -178,6 +196,4 @@ The common Intel processors are also little-endian. ## So what's big-endian? -The Motorola 68K family - we reached out to the Amiga user community in -the hopes that someone would run the code, but no one has and this makes -us sad. :( +IBM mainframes and the Motorola 68K family come to mind. See above. diff --git a/section_3/endian/main.c b/section_3/endian/main.c new file mode 100644 index 0000000..ab4df2b --- /dev/null +++ b/section_3/endian/main.c @@ -0,0 +1,25 @@ +#include + +void Dump(void * i, int length) { + unsigned char * ptr = (unsigned char *) i; + + for (int counter = 0; counter < length; counter++) { + printf("%02x", *(ptr++)); + } + printf("\n"); +} + +int main() { + unsigned short i16 = 0x0123; + unsigned int i32 = 0x01234567; + unsigned long i64 = 0x0123456789ABCDEF; + + printf("Endianness of this computer:\n"); + printf("i16: "); + Dump((void *) &i16, 2); + printf("i32: "); + Dump((void *)&i32, 4); + printf("i64: "); + Dump((void *)&i64, 8); + return 0; +} \ No newline at end of file