Stack Test output

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Stack Test output

invin
The output given in StackTest.cmp file is:
|  RAM[0]  | RAM[256] | RAM[257] | RAM[258] | RAM[259] | RAM[260] |
|     266  |      -1  |       0  |       0  |       0  |      -1  |
| RAM[261] | RAM[262] | RAM[263] | RAM[264] | RAM[265] |
|       0  |      -1  |       0  |       0  |     -91  |

My first RAM[0] and last RAM[265] are same but rest all RAM locations have opposite output.
For example RAM[256] = 0, RAM[257=-1 and so on

When I ran the stack operations on paper, it looks my answers are correct.
For example:
push constant 17
push constant 17
eq

This operation should produce RAM[256] = 0, since they are equal

Please help me understand why there is -1 at RAM[256] and so on?

Reply | Threaded
Open this post in threaded view
|

Re: Stack Test output

cadet1620
Administrator
The most common problem is misunderstanding the integer values for true and false because the book's description is written using a slightly strange idiom. (And one of the course slides is just plain wrong!)

Explicitly, when returning a value from gt, lt, eq:
    true = -1 = 111..111 binary,
    false = 0 = 000..000 binary.

When testing for true/false in the if-goto command:
    0 = false,
    all other values = true.