Clarity needed about which numbers can be directly loaded into A/M/D

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

Clarity needed about which numbers can be directly loaded into A/M/D

motty
I've observed that the instructions M=1, M=0 and M=-1 are all correct; but M=(any number > 1) will throw an error. If M would only be able to accept 0 or 1, that makes sense, but if it can accept -1, which flips all bits to 1, why can it not accept say M=2, which would flip bit 2 to 1? Any help would be appreciated, because I feel that my lack of understanding does not allow me to continue properly. Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Clarity needed about which numbers can be directly loaded into A/M/D

WBahn
Administrator
There are 18 defined ALU operations. That's it. Three of them are -1, 0, and 1.

If you want to get any other number into a register, you need to do it using an A-type instruction.

@42
D=A

ASIDE: It turns out that one of the undefined ALU operations is -2, but that's only because -2 is the 1's complement of +1.
Reply | Threaded
Open this post in threaded view
|

RE: Clarity needed about which numbers can be directly loaded into A/M/D

motty

I thought that the ALU was for arithmetic operations only, not for accessing memory registers?

 

From: WBahn [via Nand2Tetris Questions and Answers Forum] <ml+[hidden email]>
Sent: Monday, March 08, 2021 12:53 PM
To: Motty Waldner <[hidden email]>
Subject: Re: Clarity needed about which numbers can be directly loaded into A/M/D

 

There are 18 defined ALU operations. That's it. Three of them are -1, 0, and 1.

If you want to get any other number into a register, you need to do it using an A-type instruction.

@42
D=A

ASIDE: It turns out that one of the undefined ALU operations is -2, but that's only because -2 is the 1's complement of +1.


To unsubscribe from Clarity needed about which numbers can be directly loaded into A/M/D, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

RE: Clarity needed about which numbers can be directly loaded into A/M/D

WBahn
Administrator
It is? What makes you think it's not.

A C-type instruction is of the form:

[dest=]comp[;jump]

with the following fields:

dest: determines where the output of the ALU will get stored (optional)
comp: determines what operation the ALU will perform (required)
jump: determines whether or not a jump will occur based on the output of the ALU (optional)

There are 28 defined mnemonics for the 'comp' field. These are for the 18 basic ALU operations, but the ten ALU operation involving the Y inputs have two options, one in which the A register is used and one in which the M "register" is used.

Reply | Threaded
Open this post in threaded view
|

RE: Clarity needed about which numbers can be directly loaded into A/M/D

motty

OK. So if the only possible instructions are 1/0/-1, when doing something like @5, for instance, how is that actually set to memory?

 

From: WBahn [via Nand2Tetris Questions and Answers Forum] <ml+[hidden email]>
Sent: Monday, March 08, 2021 1:57 PM
To: Motty Waldner <[hidden email]>
Subject: RE: Clarity needed about which numbers can be directly loaded into A/M/D

 

It is? What makes you think it's not.

A C-type instruction is of the form:

[dest=]comp[;jump]

with the following fields:

dest: determines where the output of the ALU will get stored (optional)
comp: determines what operation the ALU will perform (required)
jump: determines whether or not a jump will occur based on the output of the ALU (optional)

There are 28 defined mnemonics for the 'comp' field. These are for the 18 basic ALU operations, but the ten ALU operation involving the Y inputs have two options, one in which the A register is used and one in which the M "register" is used.



To unsubscribe from Clarity needed about which numbers can be directly loaded into A/M/D, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

RE: Clarity needed about which numbers can be directly loaded into A/M/D

WBahn
Administrator
motty wrote
OK. So if the only possible instructions are 1/0/-1, when doing something like @5, for instance, how is that actually set to memory?
Don't confuse A-type and C-type instructions.

@5

is an A-type instruction.

An A-type instruction does one thing and one thing only. It loads a 15-bit unsigned integer into the A-register. It has NOTHING to do with the ALU, or RAM, or performing a jump.
Reply | Threaded
Open this post in threaded view
|

RE: Clarity needed about which numbers can be directly loaded into A/M/D

motty

Thanks for clarifying! I’m still not sue I get it 100%, but I hope it will become clearer in the coming chapters….?

 

From: WBahn [via Nand2Tetris Questions and Answers Forum] <ml+[hidden email]>
Sent: Monday, March 08, 2021 2:30 PM
To: Motty Waldner <[hidden email]>
Subject: RE: Clarity needed about which numbers can be directly loaded into A/M/D

 

motty wrote

OK. So if the only possible instructions are 1/0/-1, when doing something like @5, for instance, how is that actually set to memory?

Don't confuse A-type and C-type instructions.

@5

is an A-type instruction.

An A-type instruction does one thing and one thing only. It loads a 15-bit unsigned integer into the A-register. It has NOTHING to do with the ALU, or RAM, or performing a jump.


To unsubscribe from Clarity needed about which numbers can be directly loaded into A/M/D, click here.
NAML