Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utfyzx!oscvax!rico From: rico@oscvax.UUCP Newsgroups: comp.sys.amiga Subject: Re: Caveat for Manx C (3.20 and 3.40) Message-ID: <478@oscvax.UUCP> Date: Tue, 24-Mar-87 10:28:51 EST Article-I.D.: oscvax.478 Posted: Tue Mar 24 10:28:51 1987 Date-Received: Wed, 25-Mar-87 07:22:04 EST References: <477@oscvax.UUCP> <210@rocky.STANFORD.EDU> Reply-To: rico@oscvax.UUCP (Rico Mariani) Organization: Ontario Science Centre, Toronto Lines: 76 Keywords: Manx, unsigned, subscript, assembler, bug Summary: Watch out for unsigned array subscripts... Here's a little more elaboration on the problem that Tom Rockiki(sp?) pointed out. This only causes difficulty when using 16 bit integers as there is no difference between signed and unsigned addition/indexing when you use the full width of your registers. The following two expressions must generate slightly different code, I'm not sure which one makes the wrong code because I can't remember whether indexing is signed or unsigned on the 68000. I think it's signed, which would mean that the a[i] code is wrong... Lattice probably isn't vulnerable to this bug because it uses only 32 bit int's Here's the source: char *a ; unsigned int i ; int j; test() { a[i] = 1; a[j] = 2; } Aztec C 3.40a generates the following assembler: ;:ts=8 ;char *a ; global _a,4 ;unsigned int i ; global _i,2 ;int j; global _j,2 ; ;test() { public _test _test: link a5,#.2 movem.l .3,-(sp) ; a[i] = 1; move.w _i,d0 move.l _a,a0 move.b #1,(a0,d0.w) <--- wrongo! ; a[j] = 2; move.w _j,d0 move.l _a,a0 <--- I would've been real impressed if this move.b #2,(a0,d0.w) wasn't here... oh well maybe next time :-) ;} .4 movem.l (sp)+,.3 unlk a5 rts .2 equ 0 .3 reg public .begin dseg end The code that a[i] = 1 should generate is move.l #0,d0 ;this gets squeezed into a moveq automagically move.w _j,d0 move.l _a,a0 move.b #1,(a0,d0.l) Like I said... this is not a problem if you're using 32 bit integers... -Rico P.S. Nobody's got back to me about my big monitor/tim king questions. What'sa matter don'tcha got no opinions no more :-) -- [NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode] [CSIS food: supermailbox, tuna, fiberglass coffins, Mirabel, microfiche] [Cat food: Nine Lives, Cat Chow, Meow Mix, Crave]