Assignment PDF
Assignment PDF
Hack CPU description: it has A and D registers and pseudo-register M which refer to transferring data
between CPU and RAM.
Hack CPU has two types of instructions A-instructions and C-instructions. These two instructions are
going to help us solve the assignment, and here is how we are going to use these instructions.
1. A-instructions description
- A-instructions load A register with a constant value between 0 and 32767 and they don’t
read from RAM.
b. @symbol – instructions will load the address of the code label or RAM variable symbol
into the A register.
NOTE: The A-instruction is used for three different purposes. First, it provides the only way to enter a
constant into the computer under program control. Second, it sets the stage for a subsequent
C-instruction designed to manipulate a certain data memory location, by first setting A to the address of
that location. Third, it sets the stage for a subsequent C-instruction that specifies a jump, by first loading
the address of the jump destination to the A register.
Predefined Symbols
A: Address Register.
D: Data Register.
SCREEN: Base address of the Screen Map in Main Memory, which is equal to 16384.
Binary syntax:
1 1 1 a c1 c2 c3 c4 c5 c6 d1 d2 d3 j1 j2 j3, where:
- a bit: Chooses to load the contents of either A register or M (Main Memory register
addressed by A) into the ALU for computation.
- Bits c1 through c6: Control bits expected by the ALU to perform arithmetic or bit-wise logic
operations.
- Bits d1 through d3: Specify which memory location to store the result of ALU computation
into: A, D or M.
- Bits j1 through j3: Specify which JUMP directive to execute (either conditional or
unconditional).
After describing the A and C-instructions am using the reference image to be able to convert program 1
and 2 to machine language.
Below is the reference image from
nandetetrics.
@2
D=A
@3
D=D+A
@0
M=D
Machine code:
The characters that start with double forward slashes are comments, so in our conversion we ignore
comments and spaces. These are called white spaces.
- The first 3 bits are 111 of which C-instructions start with bits 111
- The computational numeric ‘a’ is 0 when we look at the reference diagram we are setting A
to D of which the computation is 110000.
- The destination of the result of computation is, referencing the diagram again we look at D
and we find its 010.
4. D=D+A - add A-register to D-register and set D-register to incremented value which is
1110000010010000
- Referencing the diagram, this is a C-instruction which in machine code the binary value
starts with bits 111
- Computational numeric a = 0
- Computational value is 001100
Screen shot Image above is program 1 converted to machine language from Assembler software.
@0
D=M
@1
D=D-M
@10
D;JGT
@1
D=M
@12
0;JMP
@0
D=M
@2
M=D
@14
0;JMP
4. D=D-M – subtracts RAM[A] from D-register and sets D-register to the decremented value
5. @10 – the A-register is loaded with the binary equivalent value of 10 in decimal
6. D;JGT – this is C-instruction which says jump to ROM in address A-register if D register is greater
than zero
- It computational numerical a= 0
- It computational numerical a= 0
Finally, I have learnt how physical hardware communicates or interact with software, and also the
under-laying principal of hardware and software interaction.