Machine Code and Assembly language Understanding of the relationship between assembly language and machine code Machine code or machine language is a set of instructions executed directly by a computer's central processing unit(CPU). Each instruction performs a very specific task, such as a load, a jump, or an ALU operation on a unit of data in a CPU register or memory. Every program directly executed by a CPU is made up of a series of such instructions. Machine languages consist entirely of numbers and are almost impossible for humans to read and write. Assembly languages have the same structure and set of commands as machine languages, but they enable a programmer to use Mnemonics instead of numbers. Consider a program in binary and the equivalent program using mnemonics: Opcodes and Operands In computing, an opcode (abbreviated from operation code) is the portion of a machine language instruction that specifies the operation to be performed. Beside the opcode itself, instructions usually specify the data they will process, in form of operands. An opcode is short for 'Operation Code'. An opcode is a single instruction that can be executed by the CPU. In machine language it is a binary or hexadecimal value such as 'B6' loaded into the instruction register. In assembly language mnemonic form an opcode is a command such as MOV or ADD or JMP. For example: MOV, AL, 34h The opcode is the MOV instruction. The other parts are called the 'operands'. Operands are manipulated by the opcode. In this example, the operands are the register named AL and the value 34 hex. Modes of addressing Immediate: Apply a constant to the accumulator. No need to access main memory. Direct: This is a very simple way of addressing memory – the code refers directly to a location in memory. Indirect: Looks to another location in memory for an address and then fetches the data that is located at that address. Indexed: Take a base address and applies an offset to it and fetches the data at that address. Relative: Tells the CPU to jump to an instruction that is a relative number of locations away from the current one. Very efficient way of handling program jumps and branching. Addressing mode Operand Immediate The value to be used in the instruction Direct An address which holds the value to be used in the instruction Indirect An address which holds the address which holds the value to be used in the instruction Indexed An address to which must be added what is currently in the index register (IX) to get the address which holds the value in the instruction Assembly language instructions Data movement: These types of instructions involve loading data into a register or storing data in memory. Instruction opcode Instruction operand Explanation LDM #n Immediate addressing loading n to ACC LDR #n Immediate addressing loading n to IX LDD <address> Direct addressing, loading to ACC LDI <address> Indirect addressing, loading to ACC LDX <address> Indexed addressing, loading to ACC STO <address> Storing the contents of ACC Arithmetic operations: These are few examples of instruction formats used for arithmetic operations. Instruction opcode Instruction operand Explanation ADD <address> Add the address content to the content in the ACC INC <register> Add 1 to the value stored in the specified register DEC <register> Subtract 1 from the value stored in the specified register Comparisons and jumps: A program might require an unconditional jump or might only need only need a jump if a condition is met. Instruction opcode Instruction operand Explanation JMP <address> Jump to the address specified CMP <address> Compare the ACC content with the address content CMP #n Compare the ACC content with n JPE <address> Jump to the address if the result of the previous comparison was true JPN <address> Jump to the address if the result of the previous comparison was false Question: