firgunner wrote

I figured it all out except for one thing. in StackTest.cmp the result of a not operation is -91. How can this be? My result is 0 since the operation in the test acts on 1 as a result of the previous or. I am moving on with the course for now since I feel like this is a small detail that I have missed or something but it is still bothering me so I would appreciate any answers and help.

Here is the relevant part of the test and I put the contents of the stack after each operation:

push constant 57
// 57
push constant 31
// 31 57
push constant 53
// 53 31 57
add
// 84 57
push constant 112
// 112 84 57
sub
// -28 57
neg
// 28 57
// or in binary (and I'll use just 8 bits because the rest are just a copy of the leftmost one
// 00011000 00111001
and
// 00011000
push constant 82
// 01010010 00011000
or
// 01011010
not
// 10100101

The last number on the stack is negative, because it's sign bit is 1. To find it's value, we can convert it to positive (NOT, then +1), convert it to decimal and then change its sign. So the NOT part we already have:
01011010. +1 gives us 01011011. Convert to decimal: 1 + 2 + 8 + 16 + 64 = 91. Change sign: -91.