3 ms·
I remember such a piece of code, perhaps the shortest ever created! It was 4 instructions in the machine language of ancient British ICL1900 computers. I - toge
by witrak 3y ago
I remember such a piece of code, perhaps the shortest ever created! It was 4 instructions in the machine language of ancient British ICL1900 computers. I - together with my colleague - spent some hours to understand it - firstly, what it does and then how and why it works!
The problem was that ICL1900 had a rather obscure method of storing 6-bit characters in its 24-bit words (yes, bytes were unknown in ICL computers). To copy character strings indexing was used but character position was stored on the first two bites of the index word while the word address offset on the right part of the index. Since memory was extremely valuable, the rest part of the index was used for the counter. Thus fetch and store instructions were working such that after a character was accessed counter was decremented and 1 was added to the 2-bit character position subregister with overflow used to increment address offset every 4th character. Very clever solution because the string copying loop was very tight!
The 4 instruction sequence we tried to interpret was a macro modifying character index register backward allowing to use of an almost identical loop for copying a string starting from its end... It was using arithmetic overflow in a way we weren't able to understand, and we hadn't access to hardware :-)