Saturday, May 28, 2011

Assembly Language

Assembly can be seen as machine language but in symbols/mnemonics instead of 0s or 1s. So one can make use of any aspect of computer's power if writing programs in assembly.

Assembly is specific to machine architecture. IA32 (also called x86, i386) is the most popular architecture for PC.
  1. Register
    Can be classified in 4 types:
    - general purpose (eax, ebx, ecx, edx)
    - pointer/index (esp, ebp, esi, edi)
    - instruction pointer (eip)
    - flags (eflags)

    These are all 32 bits. Each register contains 8-bit and 16-bit parts. Ex: eax (32 bits), ax (16 bits), ah (8 bits), al (8bits).

  2. Instruction
    - arithmetic/logic: add, sub, and, or,...
    - control: jmp,..
    - data movement: mov,..

  3. Operand
    - register: operand value is contained in register
    - immediate: operand value is a constant
    - memory: operand value is in memory

  4. Addressing mode
    Addressing mode is the way to specify a memory address.
    - absolute:
      address = a value
    - register:
      address = register content
    - displacement:
      address = register content + a value
    - indexed:
      address = register content + a value + another register content (index) * another value (scale)

  5. Subroutine
    - subroutine is a set of instructions
    - parameters passed to subroutine are usually pushed on stack

No comments: