Need help with Fill.asm

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Need help with Fill.asm

nand2tetris999
Hi, I'm trying to do the Fill.asm file but I'm stuck. I can't figure out how to do something that works, especially since there's only D and A and A gets used a lot. (Also, what does "Destination expected" mean?)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with Fill.asm

cadet1620
Administrator
nand2tetris999 wrote
Hi, I'm trying to do the Fill.asm file but I'm stuck. I can't figure out how to do something that works, especially since there's only D and A and A gets used a lot. (Also, what does "Destination expected" mean?)
I don't know about the "destination expected" error, but I'd guess that you had something other than 'A', 'D' or 'M'  to the left of an '='.

It is a bit of a bottleneck having only two CPU registers. That's why there are specific RAM locations reserved with symbol names R0 - R15; they can be used as meta-registers. When you get to the VM, you will find that these RAM registers are used for various things like the stack pointer and object pointers.

Here's an example that fills RAM addresses 100 to 199 with a counting by 3 pattern:
    @100    // addr = 100
    D=A
    @addr
    M=D

    @value  // value = 0
    M=0

(LOOP)
    @value  // RAM[addr] = value
    D=M
    @addr
    A=M
    M=D

    @3      // value = value+3
    D=A
    @value
    M=M+D

    @addr   // addr = addr+1 (with new addr left in D)
    MD=M+1

    @200    // if addr < 200 goto LOOP
    D=D-A
    @LOOP
    D;JLT

    @HALT   // halt (loop forever)
(HALT)
    0;JMP

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Need help with Fill.asm

nand2tetris999
Thanks! I figured it out (the code sample helped). That was a very quick response.
Loading...