1 / 12

MACHINE CODE

MACHINE CODE. What is Machine Code?. Machine code - simple instructions that are executed directly by the CPU. Computers can only understand binary, 1s and 0s. We are now going to look at the simplest instructions that we can give a computer. This is called machine code.

Download Presentation

MACHINE CODE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MACHINE CODE

  2. What is Machine Code? • Machine code - simple instructions that are executed directly by the CPU

  3. Computers can only understand binary, 1s and 0s. We are now going to look at the simplest instructions that we can give a computer. This is called machine code. • Machine code allows computers to perform the most basic, but essential tasks. • For this section we are going to use the Accumulatorto store the intermediate results of all our calculations.

  4. INSTRUCTIONS Amongst others, the following instructions are important for all processors: • LDA - Loads the contents of the memory address or integer into the accumulator • ADD - Adds the contents of the memory address or integer to the accumulator • STO - Stores the contents of the accumulator into the addressed location

  5. Assembly code is the easy to read interpretation of machine code, there is a one to one matching, one line of assembly equals one line of machine code:

  6. A quick coding example using assembly code. LDA #23 ;loads the number 23 into the accumulator ADD #42 ;adds the number 42 to the contents of the accumulator = 65 STO 34 ;save the accumulator result to the memory address 34 The code above is the equivalent of saying x = 23 + 42 in VB.NET.

  7. Instruction set • Instruction set - the range of instructions that a CPU can execute There are many different instructions that we can use in machine code, you have already met three (LDA, ADD, STO), but some processors will be capable of understanding many more. The selection of instructions that a machine can understand is called the instruction set.

  8. You'll notice that in general instructions have two main parts:

  9. Addressing modes • You might notice that some instructions use a # and others don't, why? • # = number [no hash] = address

  10. Depending on the word size, there will be different numbers of bits available for the opcode and for the operand. There are two different philosophies at play, with some processors choosing to have lots of different instructions and a smaller operand (Intel, AMD) and others choosing to have less instructions and more space for the operand (ARM).

  11. Below is a list of some other instructions that might be used: ADD ; add one number to another number SUB ; subtract one number from another number INC ; increment a number by 1 DEC ; decrement a number by 1 MUL ; multiply numbers together OR ; booleanalgebra function AND ; booleanalgebra function NOT ; booleanalgebra function XOR ; booleanalgebra function JNZ ; jump to another section of code if a number is not zero (used for loops and ifs) JZ ; jump to another section of code if a number is zero (used for loops and ifs) JMP ; jump to another section of code (used for loops and ifs)

  12. Let us look at a more complex example of assembly code instructions:

More Related