Jump to content

Recommended Posts

2 minutes ago, apersson850 said:

Yes, the compiler treats the constant -32768 as a long integer, since it can't negate that number within the 16 bit range. You may call it a "bug", but since it's by design it's probably if not a "feature" then at least a "characteristic".

But if I assign -32767 to an integer then subtract 1, -32768 does get stored in that integer as I've demonstrated earlier.

TEST.JPG.6e6699472c4c33adea0a643995a3c083.JPG

Yes, the exception for the integer value -32768 applies only when it's compiled as a constant.

What you demonstrated is a runtime calculation and they execute as expected. They are literally translated to the A (add) instruction in the TMS 9900.

Note that UCSD Pascal doesn't do any range checking on integer arithmetic, so you can do unsigned math too. If you add 10 to 32767 you'll get the binary result that's equivalent to 32777 if you look at the 16-bit value as an unsigned one and there is no error. If you use write to print it out Pascal will report it as -32759, but the value 8009H unsigned represents 32777. You'll have to write your own printout functions if you want proper printing of unsigned numbers. But the math you can do with the standard functions.

  • Like 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...