|
|
When I was dealing with NestedCall, The CPU emu had a logic flaw. Here are 2 screenshots of what happened:
|
Administrator
|
This post was updated on .
What was the breakpoint you set?
I've used that exact sequence numerous times to push something onto the stack.
What, exactly, is happening that shouldn't be happening?
Those static screenshots don't really make sense, but they don't tell the whole story, either.
All we really know is that (if I understand how the emulator works when it hits a breakpoint), in your first screenshot the instruction at line 271 will be the next instruction to be executed and that memory address 14 was the last RAM address accessed.
Note that what it does NOT indicate is which instruction was just executed.
Consider the following sequence located someplace in your code.
@14
A = M
0; JMP
Basically, any code that incorrectly loaded the contents of RAM[14] into the A register and then somehow performed a jump.
Notice how this is then consistent with your next screen shot. A is now equal to 271 and the instruction on line 271 loads it's contents minus one, which is -1, into the A register and then the next instruction tries to access the RAM cell at location -1 (or 65535), which doesn't exist and so it fails before executing that instruction.
It is HIGHLY likely that you have a logic error elsewhere in your code.
You might be able to find it by setting a breakpoint on when the A register gets set to 271. Hopefully this happens infrequently enough that you can verify the code at each instance and find a problem.
It is pretty unlikely that the CPU emulator has this bad of a bug after being in use this long.
There is a strong tendency, particularly among those new to programming, to quickly assume that the tool has a bug instead of the problem being a logic flaw in our own program that we just don't see.
I think we have all been there (I certainly know I have) and made that same mistake, only to always nearly discover that, no, the tool was right and we just didn't yet have the skill and the patience to track down our own mistake before we threw our hands up in frustration and blamed the tool.
With time and experience a few things happen. First, we get better at finding our own mistakes (I'd like to say that we also make fewer of them and, to some degree, that's probably true, but I don't know that for sure). Second, we have enough more techniques in our debugging tool bag that we don't get frustrated to the point of giving up nearly as quickly. Third, we have falsely accused the tool of being the culprit enough times and been proven wrong (usually by others at first and then, increasingly, by ourselves) that we become very hesitant to make that assertion (and require increasingly high levels of evidence before doing so).
The good news is that each time we do it and get proven wrong, we gain valuable knowledge and skills, so the experience is seldom truly a waste of time.
|
|
This post was updated on .
I'm positive that the instruction was 'call Sys.add12 1'. And also, when I was running it, when it was just before that M=D, A was 271, and then it suddenly turned into -1 after the next instruction (which was M=D). I don't know how the CPU Emu does math (because I don't know Java 😑), but if this is a problem, they should totally get it fixed (because 271-1 ≠-1, and even I know that 🤪), and also, this has never happened before. I have lots of those @0
M=M+1
A=M-1
M=D in the .asm file, so this is probably a problem
|
Administrator
|
Doesn't it seem unlikely to you that this emulator has been in use for about fourteen years and that you are the first person that has found this "bug" in it?
If the instruction that was highlighted when A was 271 was the one before M = D (namely A=M-1), then it did exactly what I said it did. Remember, the highlighted instruction has not been executed yet. Consider that when you reset the program the instruction on line zero is highlighted even though no instructions have executed.
Since the value stored in memory at address 271 is 0, when you execute A=M-1, M is 0 and so A gets set equal to -1.
The problem is almost certainly that there is a bug in the assembly code (not the emulator) elsewhere that is doing an unintended jump to this code and it causing the problem.
Have you tried what I suggested and setting a breakpoint when A is equal to 271?
|
|
Actually, yeah - it makes perfect sense to me that a project that has been in use for fourteen years will have bugs that no one but OP found.
Have you been developing software for a long time? If so, that would be your reality as well.
|
|
t0mgs wrote
Actually, yeah - it makes perfect sense to me that a project that has been in use for fourteen years will have bugs that no one but OP found.
Have you been developing software for a long time? If so, that would be your reality as well.
This is true. But you should always question your own code first. It was just developed, it's tested much less than the software you're using and, at least in this case, you are learning something new to you, so perhaps you didn't get this right is quite realistic.
|
|
The problem is - and I'm sorry if this goes off topic for this forum - that your tone was unwelcoming. This is a safe space for beginners to work their way through really, really difficult problem sets. If he thought he found a bug and was mistaken - which is most likely the case here - that's OK!
This is what he's here for!
Using the "project has been around for so long so it's probably been through the grinder...." schtick is true - just needless here. We need to be nice! We were beginners as well once! Let's keep that in mind.
And of course - I might've misunderstood your point. But it just stung personally to see a harsh comment on what is a nicely-asked question from someone who just dug deep and took a swing. On Tue, May 7, 2019 at 4:02 PM ivant [via Nand2Tetris Questions and Answers Forum] < [hidden email]> wrote:
t0mgs wrote
Actually, yeah - it makes perfect sense to me that a project that has been in use for fourteen years will have bugs that no one but OP found.
Have you been developing software for a long time? If so, that would be your reality as well.
This is true. But you should always question your own code first. It was just developed, it's tested much less than the software you're using and, at least in this case, you are learning something new to you, so perhaps you didn't get this right is quite realistic.
|
|
t0mgs wrote
The problem is - and I'm sorry if this goes off topic for this forum - that
your tone was unwelcoming.
This is a safe space for beginners to work their way through really, really
difficult problem sets.
I just want to point out, that the comments in question weren't mine. In this thread and up until now I only replied to your previous message.
|
|
That it.... unfortunate and true.
I still disagree with that person's tone, though.
|
Administrator
|
t0mgs wrote
Actually, yeah - it makes perfect sense to me that a project that has been in use for fourteen years will have bugs that no one but OP found.
Have you been developing software for a long time? If so, that would be your reality as well.
Please note that there is a huge difference between asking if it makes sense that A bug went unnoticed for fourteen years and asking if it makes sense that THIS particular claimed bug (subtracting 1 from 271 and getting -1) has gone unseen for fourteen years.
|
Administrator
|
t0mgs wrote
The problem is - and I'm sorry if this goes off topic for this forum - that
your tone was unwelcoming.
This is a safe space for beginners to work their way through really, really
difficult problem sets.
If he thought he found a bug and was mistaken - which is most likely the
case here - that's OK!
This is what he's here for!
Using the "project has been around for so long so it's probably been
through the grinder...." schtick is true - just needless here.
We need to be nice! We were beginners as well once! Let's keep that in mind.
And of course - I might've misunderstood your point. But it just stung
personally to see a harsh comment on what is a nicely-asked question from
someone who just dug deep and took a swing.
Please consider the context. The initial post claimed to have found a bug. I analyzed the information and offered an explanation for the behavior seen as well as specific steps to help the TS explore and and verify whether this explanation was correct.
The response to that was merely a reassertion that the emulator has a bug and that it needs to be fixed without any indication of even attempting to do what was suggested. THAT is when I asked whether it made sense that such a serious bug would go unnoticed for so long -- and once again walked through the likely chain of events that allowed a flaw in the program to produce the observed behavior.
|
|
After reading the entire context - which I did earlier (except for missing the username of the person who replied first), I still think that a different phrasing was in order. Look at Stack Overflow these days - if someone dares ask a wrong question he's constantly bombarded for it. Let's not get there. On Tue, May 7, 2019 at 5:44 PM WBahn [via Nand2Tetris Questions and Answers Forum] < [hidden email]> wrote:
t0mgs wrote
The problem is - and I'm sorry if this goes off topic for this forum - that
your tone was unwelcoming.
This is a safe space for beginners to work their way through really, really
difficult problem sets.
If he thought he found a bug and was mistaken - which is most likely the
case here - that's OK!
This is what he's here for!
Using the "project has been around for so long so it's probably been
through the grinder...." schtick is true - just needless here.
We need to be nice! We were beginners as well once! Let's keep that in mind.
And of course - I might've misunderstood your point. But it just stung
personally to see a harsh comment on what is a nicely-asked question from
someone who just dug deep and took a swing.
Please consider the context. The initial post claimed to have found a bug. I analyzed the information and offered an explanation for the behavior seen as well as specific steps to help the TS explore and and verify whether this explanation was correct.
The response to that was merely a reassertion that the emulator has a bug and that it needs to be fixed without any indication of even attempting to do what was suggested. THAT is when I asked whether it made sense that such a serious bug would go unnoticed for so long -- and once again walked through the likely chain of events that allowed a flaw in the program to produce the observed behavior.
|
Administrator
|
t0mgs wrote
After reading the entire context - which I did earlier (except for missing
the username of the person who replied first), I still think that a
different phrasing was in order.
Look at Stack Overflow these days - if someone dares ask a wrong question
he's constantly bombarded for it.
Let's not get there.
We will probably have to agree to disagree. I don't think that asking someone to consider the likelihood of an undiscovered bug in the tool versus a bug in their code is unreasonable when they refuse to even consider that their code might have a bug and insists that it must be the tool, even when the likely nature of the bug is presented along with steps on how to track it down.
But, by all means, feel free to respond in the manner you feel is appropriate. You might well change my opinion.
|
|
It is the nature of conversation we have with new developers that bug me. So, when you come to a workplace as a junior dev, it's expected that there will be a senior dev to instruct you. Heck, a lot of the time these senior devs do so with pleasure - they love what they do, and are happy to include the new guys in the game.
However, when we're talking online, the conversation turns sideways quickly. It's expected that everyone will google everything before asking, which kind of beats the purpose of an online forum to begin with. No one explanation is universally sufficient. Might as well explain a few times over.
And since you seem like a level-headed person, I'd assume you meant no harm and I'm throwing my own personal bias against the wall here. But still - nice to have a discussion going. On Tue, May 7, 2019 at 6:55 PM WBahn [via Nand2Tetris Questions and Answers Forum] < [hidden email]> wrote:
t0mgs wrote
After reading the entire context - which I did earlier (except for missing
the username of the person who replied first), I still think that a
different phrasing was in order.
Look at Stack Overflow these days - if someone dares ask a wrong question
he's constantly bombarded for it.
Let's not get there.
We will probably have to agree to disagree. I don't think that asking someone to consider the likelihood of an undiscovered bug in the tool versus a bug in their code is unreasonable when they refuse to even consider that their code might have a bug and insists that it must be the tool, even when the likely nature of the bug is presented along with steps on how to track it down.
But, by all means, feel free to respond in the manner you feel is appropriate. You might well change my opinion.
|
Administrator
|
t0mgs wrote
It is the nature of conversation we have with new developers that bug me.
So, when you come to a workplace as a junior dev, it's expected that there
will be a senior dev to instruct you.
Heck, a lot of the time these senior devs do so with pleasure - they love
what they do, and are happy to include the new guys in the game.
However, when we're talking online, the conversation turns sideways quickly.
It's expected that everyone will google everything before asking, which
kind of beats the purpose of an online forum to begin with.
No one explanation is universally sufficient. Might as well explain a few
times over.
And since you seem like a level-headed person, I'd assume you meant no harm
and I'm throwing my own personal bias against the wall here.
But still - nice to have a discussion going.
It's very possible that's at least part of what's going on.
A huge problem with written communication is that it is difficult to convey tone. So the reader has to assume what tone it should be "heard" with. The problem there is many-fold -- most written statements could be spoken aloud with several different tones of voice, often making it possible for the same exact words to take on very different connotations ranging from humorous or reflective to demeaning or derogatory. Worse, once the reader has initially (and subconsciously) chosen a tone of voice, it becomes very difficult to not continue hearing it in that tone of voice.
I suspect that, in many cases, we tend to quickly select a tone to match the tone we recall hearing something vaguely similar lurking in our memory spoken aloud.
|
|
That is indeed true, and I'm kinda happy we had this discussion. It's weird that even on the outskirts of the interwebs (a Nabble forum for a university class is outskirt-ish, from my perspective) there are nice people. :)Â On Tue, May 7, 2019 at 8:43 PM WBahn [via Nand2Tetris Questions and Answers Forum] < [hidden email]> wrote:
t0mgs wrote
It is the nature of conversation we have with new developers that bug me.
So, when you come to a workplace as a junior dev, it's expected that there
will be a senior dev to instruct you.
Heck, a lot of the time these senior devs do so with pleasure - they love
what they do, and are happy to include the new guys in the game.
However, when we're talking online, the conversation turns sideways quickly.
It's expected that everyone will google everything before asking, which
kind of beats the purpose of an online forum to begin with.
No one explanation is universally sufficient. Might as well explain a few
times over.
And since you seem like a level-headed person, I'd assume you meant no harm
and I'm throwing my own personal bias against the wall here.
But still - nice to have a discussion going.
It's very possible that's at least part of what's going on.
A huge problem with written communication is that it is difficult to convey tone. So the reader has to assume what tone it should be "heard" with. The problem there is many-fold -- most written statements could be spoken aloud with several different tones of voice, often making it possible for the same exact words to take on very different connotations ranging from humorous or reflective to demeaning or derogatory. Worse, once the reader has initially (and subconsciously) chosen a tone of voice, it becomes very difficult to not continue hearing it in that tone of voice.
I suspect that, in many cases, we tend to quickly select a tone to match the tone we recall hearing something vaguely similar lurking in our memory spoken aloud.
|
|