Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!uw-june!kolding From: kolding@uw-june (Eric Koldinger) Newsgroups: comp.arch Subject: Re: while (*p++ = *p++); (was Re: Endian wars) Message-ID: <7211@june.cs.washington.edu> Date: 8 Feb 89 23:16:25 GMT Sender: kolding@june.cs.washington.edu Reply-To: kolding@uw-june (Eric Koldinger) Distribution: usa Organization: U of Washington, Computer Science, Seattle Lines: 37 In article <775@atanasoff.cs.iastate.edu> hascall@atanasoff.cs.iastate.edu (John Hascall) writes: >In article <3300050@m.cs.uiuc.edu> gillies@m.cs.uiuc.edu writes: > >>instruction (or something amazingly short) on the PDP-11, C's mother >>machine: > >>while (*p++ = *q++); > >>This is perhaps part of the reason why strings were designed with >>null-termination > > First, I assume you mean: > > char *p,*q; > while (*p++ == *q++); > > I can see no way to code this in 1 PDP instruction, the best I can see > is (assume R1 is p, R2 is q): Piece of cake: For the loop as he put it, with your assumptions: loop: movb (r2)+, (r1)+ bneq loop Two instructions for the loop. The loop as you wrote it (which doesn't really do very much, but here goes), again with your assumptions: loop: cmpb (r2)+, (r1)+ beq loop God it's good to write some PDP-11 code again. Now there was a great machine even if it did only have 64K of memory. ------ _ /| Eric Koldinger \`o_O' University of Washington ( ) "Gag Ack Barf" Department of Computer Science U kolding@cs.washington.edu