Rect.asm and RectL.asm are broken?

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

Rect.asm and RectL.asm are broken?

selfstudent
I downloaded Rect.asm and it looks broken to me

   @0
   D=M
   @INFINITE_LOOP
   D;JLE
...
(INFINITE_LOOP)
   @INFINITE_LOOP
   0;JMP

@0  // A=0
D=M // D = RAM[0] = 0
@INFINITE_LOOP // A = INFINITE_LOOP
D;JLE  // D==0, JUMP_LESS_THAN_EQUAL

This will always jump to infinite loop right?
Reply | Threaded
Open this post in threaded view
|

Re: Rect.asm and RectL.asm are broken?

cadet1620
Administrator
selfstudent wrote
I downloaded Rect.asm and it looks broken to me
Rect.asm is the source for the rect.hack test program used in project 5.  The ComputerRect.tst script puts a 4 into memory location 0 before running the program, which keeps it from immediately jumping to the halt loop.

For project 6, it suffices to show that your assembler and the supplied assembler generate the same .hack file for the various .asm files in project 6.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Rect.asm and RectL.asm are broken?

Lozminda
I appreciate this is some four years after, but again handy if anyone comes across the same problem.
I have found the same issue. Thanks to Mark for the answer !

Lozminda
Reply | Threaded
Open this post in threaded view
|

Re: Rect.asm and RectL.asm are broken?

WBahn
Administrator
Note the big assumption that was made by the original poster -- that the value of M[0] was zero when the code never stored a value in that location.

In general, when you power up anything that has volatile registers (such as most RAM) you have no idea what values will be stored in each location. As the chips power up each memory cell settles into either a 0 or a 1 depending on a lot of various factors including temperature, variations in transistor threshold, the phase of the moon, you name it. This is why uninitialized memory locations should always be treated as unknown garbage.

So in a program like this, the question that should be asked is whether the program has a logic error because it reads from an uninitialized memory location, or whether there is something else that initializes that memory. This should then prompt you to look at the test script.