# StackTest Problem Classic List Threaded 4 messages Open this post in threaded view
|

## StackTest Problem

 This post was updated on . So all the other tests pass except StackTest. I have gone through each RAM location referenced in StackTest.out and it lines up perfectly with the state of my memory upon termination of the StackTest.asm, yet the test fails. In addition to that, I have gone through each outputted command and written down the expected result beforehand and found that every command correctly satisfies my expectation of them. So I have two main questions: How does the test fail comparison when StackTest.out matches my memory state exactly. Does the test script examine more than what is output to StackTest.out? Secondly, I have begun to doubt my understanding what the commands should do. So I have the following questions: Whenever two operands are involved I assume where it matters say in x - y for the sub-command that x is *(SP-2) and y is *(SP-1) or something like that. Or is it the opposite way around? I assume whatever the convention is stays the same for all commands (where it matters of course). I chose that way since when implementing the high-level language we will be pushing onto the stack left-to-right (generally). Is this the wrong assumption. I am beginning to wonder whether and, or, and not are bitwise or logical I implemented them as logical (and according to my thorough examination or StackTest.asm (stepping through each line) they work by representing true as 1 and false as 0. Do I have any misunderstandings here? (EDIT) So I took a look at StackTest.cmp I wasn't aware that was the correct file. My bad. I didn't pay attention to that one video about testing. Anyway, it looks like not is not logical but bitwise and true should be represented as -1 not 1? Is that correct? (EDIT) 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. Thank you.
Open this post in threaded view
|

## Re: StackTest Problem

 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.