Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!rna!dan From: dan@rna.UUCP (Dan Ts'o) Newsgroups: net.arch Subject: re: Using C as an aid to hand writing assembler Message-ID: <491@rna.UUCP> Date: Tue, 6-May-86 18:54:11 EDT Article-I.D.: rna.491 Posted: Tue May 6 18:54:11 1986 Date-Received: Sat, 10-May-86 13:48:49 EDT References: <817@harvard.UUCP> <460@cubsvax.UUCP> <850@harvard.UUCP> <839@umcp-cs.UUCP> <2107@peora.UUCP> <2110@gondor.UUCP> <36 May 86 22:54:11 GMT Organization: Rockefeller Neurobiology Lines: 32 Original-Subject: Re: Arch support for C > Some years ago when I was learning 6800 assembler (anybody remember > D2 kits?) I used to first write everything in C and then hand compile it > into M6800 asm. When I told my professor (are you reading this Professor > Efe?) that I did this instead of drawing flow-charts, he laughed at me, but > as long as you keep your code simple, the conversion is trivial and can be > done in your head as fast as you can write down the asm code. Perhaps the > simplicity of the M6800 (dare I call it a RISC machine? :-)) makes this > easier than for something like a vax, but I can still do it; let's see: > > char i, j; > j = 0; > for (i = 0; i <= 10; i++) > j = j + i; > > clr j > loop1: clr i > cmp i, #10 > bge out > lda j > adda i > sta j > lda i > inca > sta i > bra loop1: > out: Not too good, I'm afraid. The loop1 label is misplaced - you "clr i" on every iteration. Also #10 is octal 8 instead of 10. You probably don't want the colon at the end of the "bra" statement. You don't want "bge out" but "bgt out" (since you say i <= 10). And finally, i and j should be local variables on the stack. I can see why your professor laughed.