cogito@tjalk.UUCP (Robbert van Renesse) (06/30/85)
When right-shifting an unsigned variable, the compiler generates an EXTZV instruction. If the shift count exceeds 32, a reserved operand fault occurs and the program gets an illegal instruction signal, instead of giving a null result. -- Robbert van Renesse cogito@vu44.UUCP
ark@alice.UUCP (Andrew Koenig) (07/01/85)
> When right-shifting an unsigned variable, the compiler generates an > EXTZV instruction. If the shift count exceeds 32, a reserved operand > fault occurs and the program gets an illegal instruction signal, instead > of giving a null result. > -- > Robbert van Renesse > cogito@vu44.UUCP This is not a bug. K&R, page 189: "The result [of a shift] is undefined if the right operand is negative, or greater or equal to the length of the object in bits."
ado@elsie.UUCP (Arthur David Olson) (07/10/85)
In article <486@tjalk.UUCP>, cogito@tjalk.UUCP (Robbert van Renesse) writes: > When right-shifting an unsigned variable, the compiler generates an > EXTZV instruction. If the shift count exceeds 32, a reserved operand > fault occurs and the program gets an illegal instruction signal, instead > of giving a null result. The problem goes beyond unsigned variables. When right-shifting a signed variable, the compiler generates an ASHL instruction, which takes a byte as its shift count. If the shift count's magnitude is too large, things go awry, as compiling and running the following source shows: #include <stdio.h> main() { int i; i = 5; printf("%d\n", i >> 257); } As to whether the illegal instruction or the bogus answer is the bigger problem. . . -- Bugs is a Warner Brothers trademark. CC is a Canadian Club trademark. -- UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA DEC, VAX and Elsie are Digital Equipment and Borden trademarks