Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!stanford.edu!neon.Stanford.EDU!kaufman From: kaufman@neon.Stanford.EDU (Marc T. Kaufman) Newsgroups: comp.sys.mac.programmer Subject: Re: 68000 Assembly question -- overflow Message-ID: <1991May25.021530.17126@neon.Stanford.EDU> Date: 25 May 91 02:15:30 GMT Article-I.D.: neon.1991May25.021530.17126 References: <1991May24.213815.16227@midway.uchicago.edu> Organization: Computer Science Department, Stanford University, Ca , USA Lines: 30 In article <1991May24.213815.16227@midway.uchicago.edu> tisu@quads.uchicago.edu (Seth Tisue) writes: >For class, I'm writing a four-function stack-based calculator in >assembly language. The program uses 32-bit signed integers. My >question concerns the overflow bit of the status register. Here's the code: deleted... >This code works as expected for all but one case. >Suppose the two items popped off the stack are $80000001 and $00000001 -- >i.e., in decimal, the function to be performed is (-2147483648) minus one. >Since that number is the most negative number you can fit into 32 bits, >it seems to me that this should generate. However, it does NOT generate >an overflow (I've stepped through w/MacsBug and checked), and the answer >returned is $80000000, which is meaningless ("negative zero"). Sigh! What kind of class is this where they don't explain the difference between 1's complement, 2's complement, and sign-magnitude representations? The native mode of a 68000 for instance is 2's complement. In that mode, $80000001 = -2147483647, and that minus 1 gives $80000000 - -2147483648. Yes, it is the case that there is no representation in 2's comp form of the positive number +2147483648 (at least in 32 bits). In 1's complement and sign-magnitude notation there are, indeed, 2 representations of zero (+0 and -0), and the positive and negative ranges are symmetric. But you don't have that, in terms of the 68000 Flag bits at least. Marc Kaufman (kaufman@Neon.stanford.edu) [a believer in the principle that there should be no such thing as an UNDERGRADUATE CS major]