The Hack Computer:

A 16-bit machine, with two separate memory modules (instruction memory and 
 data memory) and two memory mapped I/O devices: keyboard and screen. 
The CPU has 

CPU  executes programs in instruction memory (a ROM chip with the program 
burnt-in). Loading a new program is akin to replacing the ROM chip. The data memory is a typical RAM device

Each of the two memories is 2^15 words X 16 bits.
There are two 16-bit registers: A and D available for the programmer and 
the Program Counter (PC) (15-bits). The A and D registers can be manipulated 
by Arithmetic and Logic instructions (A = D-1 or D =! A etc).  D is a DATA register 
while the contents of A can be interpreted as Data value or an Address in Data 
Memory.Instruction sets are char. by the number of memory address that can appear 
in a single instruction.  Since in a 16-bit instruction, there is not enough room for a
 15-bit address and the op-code, memory access in Hack id a form of register-indirect
 addressing:
To access memory, a memory address is loaded into the A register (using an 
A-instruction - see below) followed by a C-instruction  specifying the operation. So, 
each memory access in Hack requires two operations - resulting in a 
"1/2 address machine". To conform to this, hack instructions operate on an implicit
memory location labelled M. M always refers to mem.loc. whose addr. is in  A
Example: To load: (contents of mem. addr. 516) - 1 into D reg.: 
   @516        //load 516 to reg A 
   D=M-1      // D=M[516] - 1
    
Hack Machine Language:
There are two generic instructions: The A-instruction (address instr.- only way to enter
 a constant into the computer) and the C-instruction (compute instr.- which does all 
the work).

The A-instruction:   @value // sets 15-bit value (non-neg. decimal) into A-register.
  Binary:                      0 v v v   v v v v  v v v v  v v v v              
     
The C-instruction:  dest=comp;jump // The instruction specifies (i) the computaion
                                                                    // (ii) the location to store computed value
                                                                   // (iii) the what to do next.
Binary:                       1 1 1 a   c1 c2 c3 c4   c5 c6 d1 d2   d3 J1 J2 J3
The a and c bits encode the computation; (7 bits) 
The d bits encode the destination  - either a memory location or reg. or both (3 bits)
The J bits encode what to do next: Either FETCH next instruction (default) OR 
jump to a different location in memory and FETCH the instr. stored there.

Where:
comp = 0 , 1 , -1 , D , A , !D , !A , -D , -A , D+1 ,        A+1 , D-1, A-1 , D+A , D-A , A-D , D&A ,        D|A , M , !M , -M ,M+1, M-1 , D+M , D-M ,        M-D , D&M , D|M  
dest = M , D , MD , A , AM , AD , AMD, or null
jump = JGT , JEQ , JGE , JLT , JNE , JLE , JMP, or null
All conditional jumps refer to the current value of D.

Write the Hack instructions that implement the following tasks:
Set A to 17                                  @17
Set D to A-1                                 D = A - 1                     
Set both A and D to A + 1
Set D to 19
Set both A and D to A + D
Set RAM[5034] to D - 1
Set RAM[53] to 171
Add 1 to RAM[7], and store the result in D.