This PABX is now sold as an improved version with a better translated manual; but (as I have some Chinese ancestry on my fathers side) I prefer the “Chinglish” version 😀
gcc can compile either c source or assembler (.s extension) or even a combination of both.
As I had the assembler source, decided to experiment with altering the string data (I don’t yet know enough to do anything else).
it still worked 🙂
note how the addresses of the array pointer change, as the strings have grown by a few characters…
below is the original code
of course this is basic easy stuff; those strings are static/constant data and declared at compile time. if your code is dealing with strings that can change their length, it must always have sufficient free memory allocated to wherever the string data ends up, enough for the largest of the data. Otherwise you get a buffer overflow and your goose is cooked…
I wanted to remind myself about C coding and how pointers work – never quite got my head round them at sons.
One of these was experimenting with C code so flawed it caused buffer overflows that crashed the kernel on multi user systems. That means the whole computer must be rebooted and other users would have their projects/data disrupted (it was in 1991, so a 32 bit machine was still known as a minicomputer and often used proprietary flavours of Unix and multiple users logged on using VT100 type terminals). I was already becoming disaffected with the place the profs thought I’d done it deliberately!
Todays Raspberry PI Model 2, placed in a suitable box (use a dark one as strong light can crash it due to a flaw in the chip design) is about the size of two packs of cigarettes; costs way less than they now do in the UK and is less unhealthy.
Aside: I can understand why younger people still smoke as I certainly did back then; but tobacco will knacker your insides and you become very ill as you get past your middle age. it has finished off a lot of my older friends on the electronics/radio scene. So at least try to stop with smoking when you get past age 30 if not before..
Back to the RPi – this amazing device is as powerful as the multi user computer I was using in 1991! The biggest advantage is if I screw up and hose the kernel it is only myself who gets affected by it. and I have done at least once, although most likely via accidental hard shutdowns i.e accidentally disconnecting the DC input whilst it is writing to the SD-card.
It is more tolerant of flawed code (I have made a silly mistake below; who can spot it?)
I used the console (having set the framebuffer font larger using sudo dpkg-reconfigure-console-setup as I couldn’t get the codeblocks debugger to play nicely and I find the GUI IDE more distracting when coding (probably because I am old 😉 )
Tip: To get a console from X-windows on RPI press CTRL-ALT-F2, this opens a separate virtual terminal. (you can use CTRL-ALT-Fn) up to F6 – CTRL-ALT-F7 returns you to the X-window and CTRL-ALT-F1 has some odd error because it is in use as part of the X-windows system.
This version is better.
OK the code doesn’t do much but it reminds me that in C strings are an array of char, so each string has a char * to point to it. The contents of the char* are, as you would expect, a memory address where the string starts!
I then wanted to see what was going on at lower level, so used gdb. You must compile the code with gcc -g for the debugger to work.
back in the day (1986-1990!) I even knew a bit about Assembler, but left high school just as Acorn ARM computers were available. So I thought I’d see if I could still remember any of it today. If you compile with gcc -S you get assembler code.
this is what the source looks like, I can see the char* array, and its contents 🙂
This bit I do not quite understand as well yet but I can grasp the fact it is part of the main loop..
Of course I need to learn much more about how ARM works (especially as you can only work with registers rather than put memory addresses directly in opcodes) and I am clearly no smarter than I was in my teens but at least my brain hasn’t deteriorated too much over the years 🙂
PS: letting random geese loose in Groningen Netherlands (the message is partly in the Gronings dialect) is not just silly but (quite rightly) illegal under their animal welfare rules.
There would no one to look after it and there are plenty of stray ones already.
However if they were going to be otherwise eaten or put down and I’d arranged with the good folk at Akka’s Ganzenparadijs that the birdies had somewhere suitable to stay it would be a good deed. Emden geese aren’t that expensive (Emden is only just the other side in Germany anyway) and are cheaper alive than dead (a friend of mine farms them).
Although the Ganzenparadijs are a Buddhist animal sanctuary and I am baptised as a Catholic (not a very good one though); sparing the lives of these creatures to atone for someone else’s sin is the sort of thing many religions encourage.
I don’t expect this would get me to Heaven on a chariot towed by geese, but it would be sufficiently silly that all the various Gods would have a good laugh about it and I might even get one of those electric trolleys used at airports and large stations to haul the various heavy items through Purgatory required for the maintenance work I am tasked with.