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

7 messages
Open this post in threaded view
|

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

 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!
Open this post in threaded view
|

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

 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.
Open this post in threaded view
|

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

 I thought that the ALU was for arithmetic operations only, not for accessing memory registers?   From: WBahn [via Nand2Tetris Questions and Answers Forum] 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. If you reply to this email, your message will be added to the discussion below: To unsubscribe from Clarity needed about which numbers can be directly loaded into A/M/D, click here. NAML
Open this post in threaded view
|

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

 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.
Open this post in threaded view
|

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

 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] 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. If you reply to this email, your message will be added to the discussion below: To unsubscribe from Clarity needed about which numbers can be directly loaded into A/M/D, click here. NAML