4 ms·
One can write a string copy routine using two instructions, assuming that the source and destination are already in registers. loop: MOVB (src)+, (dst)+
by panic 9y ago
One can write a string copy routine using two instructions, assuming that the source and destination are already in registers.
loop: MOVB (src)+, (dst)+
BNE loop
Suddenly the C idiom
while (*dst++ = *src++);
makes a lot more sense!
- dbcurtis 9y agoFor sure. If you look at Old Testament K&R C and PDP-11 assembly language side by side, you can see the mapping very clearly. It's been a looooong time since I did PDP-11 at that level, but if memory serves, I'm pretty sure that a switch(e) {...} can be done as a single jump instruction with indexed-indirect addressing mode.
- agumonkey 9y agoTeacher regularly called C a macroassembler
- davidw 9y ago"C: all the power of assembly language with all the ease-of-use of assembly language"
- beefhash 9y agoNot quite, unfortunately. In assembly language, you don't have to fear that your compiler optimizes out clearing cryptographic keys out of memory at the end of a function.
- syrrim 9y agoIn assembly, you don't have to worry about pesky optimizations speeding up your code at all. A similar effect can be achieved in C by not manually enabling optimizations.
- dangerface 9y ago"A similar effect can be achieved in C by not manually enabling optimizations." Good luck with that.
- mpweiher 9y agoNor in K&R C. Or even early ANSI-C. This whole "we can use undefined behavior to "optimize" away half your program" idea is fairly new.
- hazeii 9y agoAdding fun with PDP-11 autoincrement:- MOV (PC)+,(PC)+ What does that do? It's a single-instruction program that replicates itself throughout memory.
- cesarb 9y agoSuddenly Core War (https://en.wikipedia.org/wiki/Core_War https://en.wikipedia.org/wiki/Core_War) makes a lot more sense.
- Crashprofessor 9y agoThough Ritchie has portrayed the similarities as coincidence, http://csapp.cs.cmu.edu/3e/docs/chistory.html http://csapp.cs.cmu.edu/3e/docs/chistory.html The influence of the 11's indexing [Bell] versus the 8 on C/Unix abounds, whatever your perspective on 'Macro' move instructions, they were certainly the obvious follow on rage, witness the Movc3/Movc5 in the Vax. I've always enjoyed the notes K&R made following a non-disclosure presentation of the Vax, the most prescient I recall being a comment on the 512 page size. https://www.bell-labs.com/usr/dmr/www/vax1.html https://www.bell-labs.com/usr/dmr/www/vax1.html I revered the 11, had Qbus machines which could be assembled with superior 3rd party components in places, scattered through my apt/basement as a student from the 23 through the j11 all the way up to a MV2. Everything since has been anticlimactic :)
- OliverJones 9y agoYah, and guess what machine instructions bk and dmr were targeting with that compiler!