Mult.asm not working

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

Mult.asm not working

RobertC
Hi all.  Basically I have followed the sum to 100 example on pg.65, multiplication is addition.  Anyone willing to take a look at my .asm file?   CPU sim indicates failure.
Reply | Threaded
Open this post in threaded view
|

Re: Mult.asm not working

RobertC
Just figured it out :)   typed D=D-A but A contained an address and not number.  Replaced with D=D-M where M points to R1
Reply | Threaded
Open this post in threaded view
|

Re: Mult.asm not working

Dallas
Thank you.  I had been stuck on mult.asm for a while now until I saw this post.  Changing A to M was the only thing I was missing.  I still don't fully understand when to use A and when to use M.  Obviously they are not interchangeable.  Anyone have a good explanation why they aren't?
Reply | Threaded
Open this post in threaded view
|

Re: Mult.asm not working

cadet1620
Administrator
Dallas wrote
I still don't fully understand when to use A and when to use M.  Obviously they are not interchangeable.  Anyone have a good explanation why they aren't?
Use A when you want to read or set the value in the A register. For example, to set the D register to 123 you need to use
    @123
    D=A
If you need to triple the value in D, you would start by setting A
    A=D
    D=D+A
    D=D+A

Use M when you want to read or set a value in RAM.  The current value in A is the address of the RAM cell that will be used. To read RAM variable foo into D use
    @foo
    D=M
and to write it back to RAM
    @foo
    M=D
You can do both at the same time. To add 42 to foo
    @42
    D=A
    @foo
    M=M+D

--Mark