Fill.asm help

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

Fill.asm help

Idrisadeniyi
I don't seem to be getting the fill.asm project right. I need some help. The program is failing at the first test of the fillautomatic.asm, comparison failure at line 3 and it will only write a pixel on the screen. I quite understood how the program should work but implementing it has been a bit more difficult. I think my major obstacle is to change all the bits in a selected register as well as move to the next register in the screen memory.

Here is my code:

@SCREEN
D=A  
@addr
M=D  //ADDR = 16384

@b
M=-1 //B = -1

@8191
D=M
@i
M=D // i = 8191

(LOOP)
@KBD
D=A
@BLACKEN
D;JNE // IF(KEYPRESSED) GOTO LOOP
@WHITEN    //ELSE GOTO WHITE LABEL
@LOOP        //ELSE GOTO LOOP
@END

(BLACKEN)
@b
D=M
@addr
A=M
M=M-1 //addr = -1

@addr
M=M+1 // addr = addr + 1


@i
M=M-1 // i = 8191 - 1
D=M
@LOOP
D;JGT  //IF(i>0) GOTO LOOP

P.S I have not written the code for the white section of the program.
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm help

WBahn
Administrator
Keep in mind that you don't have to change individual pixels. Each memory address in the SCREEN memory segment controls sixteen pixels. If you set the value to 0 then they will be all white while if you set the value to 32767 (which is all 1s in binary), they will be all black.
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm help

Idrisadeniyi
Yes I got that and I've made some progress. Now I'm getting an error message "Destination is M but A=24577 is illegal memory address."
Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm help

WBahn
Administrator
That's because you have walked past the end of RAM.

The last legal RAM location is the keyboard buffer, located at 24576. So you wrote to that location (which is not a good thing) and then kept going and the simulator cried foul at that point.

So walk through your program, assuming that you have just written to 24575, and see what your program does. Go step by step and do what your program says, not what you wanted it to do.

Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm help

Idrisadeniyi
I made a few changes and I'm still getting the same error message. Since the conditional operators only test against '0' (D;JGT etc) and it's impossible to test against any real number like 24576, I then decided to use the value which is between 16383 and 24576 which is 8193, decrement it, and check that against 0 while incrementing 16383 as well. it worked and the whole screen went black but then I'm still getting that error message "Destination is M but A=24577 is an illegal memory address". May be my logic is incorrect.  

Reply | Threaded
Open this post in threaded view
|

Re: Fill.asm help

WBahn
Administrator
Use a toy screen and run your program by hand. Imagine that the screen memory still starts at 16384 but it only has 32 pixels (two RAM locations), placing the keyboard at 16386 instead of 24576.

By your reasoning, you countdown value would start at 3 (the difference between 16386 and 16383). Follow your program, step by step, and see what the last RAM location you write to would be. Is it 16386?

As for checking one number against another even though you can only test against zero, the key is to recognize that

A > B

is the same as

(A-B) > 0

But maintaining a separate counter like you are doing is perfectly reasonable.