jayaram@SUN.COM (Jayaram Kalpathy) (06/10/89)
/* From: Jayaram Kalpathy oliveb!cirrusl!jayaram@sun.com */
#include <stdio.h>
/* try running with > echo hello | a.out */
main() {
int i = 0;
while (i != EOF) {
i = getchar();
printf("(%c %d)", i, i);
}
}
/* ---------------------------------------------------------
Bug: generates erroneous assembly code. The following two similar cases
generate correct code:
1. Change "int i.." to "char i.."
2. Change the while line and the next to:
while ((i = getchar()) != EOF)
Here's what the assembly code looks like:
#NO_APP
.text
LC0:
.ascii "(%c %d)\0"
.even
.globl _main
_main:
link a6,#-4
clrl a6@(-4)
L2:
moveq #-1,d1
cmpl a6@(-4),d1
jeq L3
subql #1,__iob
tstl __iob
jlt L4
movel __iob+4,a0
moveb a0@,d0
clrl a6@(-4)
movel a6@(-4),d1
moveb d0,d1
movel d1,d1
## needs a line: movel d1,a6@(-4) here
addql #1,__iob+4
jra L5
L4:
pea __iob
jbsr __filbuf
addqw #4,sp
movel d0,a6@(-4)
L5:
movel a6@(-4),sp@-
movel a6@(-4),sp@-
pea LC0
jbsr _printf
addw #12,sp
jra L2
L3:
L1:
unlk a6
rts
------------------------------------------------------------- */