# Machine language ###### tags: `computerArchitecture` `machineLanguage` https://www.youtube.com/watch?v=lavxkeFlRI4&list=PLu6SHDdOToSdD4-c9nZX2Qu3ZXnNFocOH&index=10 We create the logic gate build sequential circuits and even construct an ALU an arithmetic logic unit, but put those together in the useful way. We need to understand how we're going to communicate our intention to our CPU through the machine code. ## Addhack This is going to add two numbers together. Now, we have to disassemble it by hand into hack assemble code ``` 0000000000000010 1110110000010000 0000000000000011 1110000010010000 0000000000000000 1110001100001000 ``` the most significant bit of each instruction tells us if it is an A instruction or a C instruction An a instruction just say put this number to in the a register. ![](https://i.imgur.com/t00ZpmR.png) The first instruction here begins with a 0 which means it's an A instruction --- C Instruction ![](https://i.imgur.com/2RQs3ww.png) >Bit 2 and bit 3 are unused bit >Bit 4 indicate whether the alu will treat the a register as a direct register or an index in the memory >Bit 5 through 10 are used tell the ALU what computation to do >bit 11~13 indicate what combinations of the A,M and d registers the result of the operation is to be stored in >bit 14~16 tell the CPU under what conditions it should jump. that is change the program counter to a new destination More deep here the bit(0101) 11~13 is tell the cup D register is the destination and bit 4 ~ 10(0110000)tell the ALU to emit a register value ``` 0000000000000010 //@2 1110110000010000 //D=A 0000000000000011 //@=3 1110000010010000 //D=D+A 0000000000000000 //@=0 1110001100001000 //M=D ``` M register in this case's location 0 in memory A word about the m register, we can think of it as a virtual register