asm.basics || [ MATHS ] || [Notation] || [Copyright] || [Contents] || [Source Text] || [Dictionary]
Last updated: Tue Nov 18 15:34:22 PST 2014

Contents (index)


    Assembly Language Basics

    Motivation

    Discuss the basics to an assembly language program and machine language instructions.

    Introduction

    Assembly language programs can have three different types of statements such as directives, instructions, and macros are three types of statements in Assembly Language. Since we are working with a low level programming language that does not have anything close to self-documentation like a high level language, it is strongly advised to comment the assembly language source code adequately! The following are skeleton_source_code_files for masm_source_32bit, masm_source_64bit, nasm_source_32bit, and nasm_source_64bit.

  1. directives::= a statement that tells the assembler to take some form of action, masm will require masm_directives for 32 bit code, as far as 64 bit code with masm, most directives are not allowed. Using nasm, most directives are not needed in either 32 or 64 bit code.

  2. instructions::= a machine language instruction that tells the CPU to perform some type of action. There are several types of instructions: data_movement, arithmetic, bit_manipulation, and branching.

  3. data_movement::= mov, push, pop

  4. mov::= mov_reg_reg, mov_mem_reg, mov_reg_mem, mov_mem_imm, mov_reg_imm, mov_mem_acc, mov_acc_mem, mov_seg_reg, mov_seg_mem, mov_reg_seg, mov_mem_seg

    For examples of using data movement instructions (masm32, masm64, nasm32, nasm64):

    masm32_mov.asm

    masm64_mov.asm

    nasm32_mov.asm

    nasm64_mov.asm

    For examples of using push and pop instructions (masm32, masm64, nasm32, nasm64):

    masm32_push_pop.asm

    masm64_push_pop.asm

    nasm32_push_pop.asm

    nasm64_push_pop.asm

  5. mov_reg_reg::= moves data from one register to another register.

  6. mov_mem_reg::= moves data from a register to a memory location value.

  7. mov_reg_mem::= moves data from a memory location value to a register.

  8. mov_mem_imm::= moves data from an immediate value to a memory location.

  9. mov_reg_imm::= moves data from an immediate value to a register.

  10. mov_mem_acc::= moves accumulator data value to a memory location.

  11. mov_acc_mem::= moves a memory location value to the accumulator.

  12. mov_seg_reg::= moves a register value into a segment register.

  13. mov_seg_mem::= moves a memory location value into a segment register.

  14. mov_reg_seg::= moves a segment register value into a non-segment register.

  15. mov_mem_seg::= moves a segment register value into a memory location value.

  16. push::= push_reg, push_mem, push_seg, push_all, push_flags

  17. push_reg::= pushes content of a register onto the stack.

  18. push_mem::= pushes content of a memory location onto the stack.

  19. push_seg::= pushes content of a segment register onto the stack.

  20. push_all::= pushes content of all registers onto the stack.

  21. push_flags::= pushes flags onto stack.

  22. pop::= pop_reg, pop_mem, pop_seg, pop_all, pop_flags

  23. pop_reg::= pops top element of the stack and places value in register.

  24. pop_mem::= pops top element of the stack and places value in memory location.

  25. pop_seg::= pops top element of the stack and places value in segment register.

  26. pop_all::= pops top elements for all registers off the stack and place in respective registers.

  27. pop_flags::= pops flags off the stack.

  28. arithmetic::= addition, subtraction, multiplication, division, increment, decrement, negation

  29. addition::= add destination, source - adds the content of source to destination, destination = destination + source

  30. subtraction::= sub destination, source - subracts the content of source from destination, destination = destination - source

  31. multiplication::= mul_source, imul_source, imul_destination_source, imul_destintation_source_immediate

  32. mul_source::= multiplies the accumulator by source, which can be a register or memory location. Accumulator is AL if source is byte, AX if source is word, EAX if source is dword, and RAX if source is a qword, DX, EDX, RDX can contain the high order of the result if needed.

     Example:  mul bx <- ax = ax * bx, since this is 16 bits times 16 bits, result could be 32 bits and is stored in DX:AX, where DX is high word.

  33. imul_source::= signed multiplication of accumulator and source, see mul_source as they are similar.

     Example:  imul bx <- ax = ax * bx, since this is 16 bits times 16 bits, result could be 32 bits and is stored in DX:AX, where DX is high word.

  34. imul_destination_source::= signed multiplication of destination register and source; destination = destination * source

     Example:  imul bx, cx <- bx = bx * cx, since this is 16 bits times 16 bits, result could be 32 bits and is stored in DX:AX, where DX is high word.

  35. imul_destintation_source_immediate::= signed multiplication of destination register, source, and immediate value, destination = source * immediate

     Example:  imul bx, cx, 4 <- bx = cx * 4, since this is 16 bits times 16 bits, result could be 32 bits and is stored in DX:AX, where DX is high word.

  36. division::= div_source, idiv_source

  37. div_source::= divides implicit_operand (dividend) by source, where source is the divisor.

  38. implicit_operand::= if source is a byte, dividend is AX, with AL containing quotient, AH containing remainder; if source is word, dividend is DX:AX, with AX containing quotient, DX containing remainder; if source is doubleword, dividend is EDX:EAX, with EAX containing quotient, EDX containing remainder; if source is quadword, dividend is RDX:RAX, with RAX containing quotient, RDX containing remainder. Division is defined by: dividend = quotient * divisor + remainder.

  39. idiv_source::= signed division, see div_source as they are similar.

  40. increment::= inc destination - increments the destination by one, destination can be a register or memory location.

  41. decrement::= dec destination - decrements the destination by one, destination can be a register or memory location.

  42. negation::= neg destination - negates the destination, destination can be a register or memory location.

  43. bit_manipulation::= logical_operations, shift, rotate

  44. logical_operations::= and, or, xor, not

  45. and::= and destination, source - destination = destination AND source, destination and source can be registers and/or memory locations

  46. or::= or destination, source - destination = destination OR source, destination and source can be registers and/or memory locations

  47. xor::= xor destination, source - destination = destination XOR source, destination and source can be registers and/or memory locations

  48. not::= not destination, not all (or one's complement) of the bits in the destination, destination can be a register or memory location

  49. shift::= shl, shr, sal, sar

  50. shl::= shl source_reg/mem, reg/imm, logically shift left source_reg/mem the number of bits specified in reg/imm. Most significant bit goes into carry flag, and least significant bit is zeroed.

  51. shr::= shr source_reg/mem, reg/imm, logically shift right source_reg/mem the number of bits specified in reg/imm. Least significant bit goes into carry flag, and most significant bit is zeroed.

  52. sal::= sal source_reg/mem, reg/imm, arithmetically shift left source_reg/mem the number of bits specified in reg/imm. Most significant bit goes into carry flag, and least significant bit is zeroed.

  53. sar::= sar source_reg/mem, reg/imm, arithmetically shift right source_reg/mem the number of bits specified in reg/imm. Least significant bit goes into carry flag, and most significant bit remains unchanged!

  54. rotate::= rol, ror, rcl, rcr

  55. rol::= rol source_reg/mem, reg/imm, rotate left source_reg/mem the number of bits specified in reg/imm. Most significant bit goes into carry flag AND moved into the least significant bit.

  56. ror::= ror source_reg/mem, reg/imm, rotate right source_reg/mem the number of bits specified in reg/imm. Least significant bit goes into carry flag AND moved into the most significant bit.

  57. rcl::= rcl source_reg/mem, reg/imm, rotate carry left source_reg/mem the number of bits specified in reg/imm. Most significant bit goes into carry flag AND old carry flag value is moved into the least significant bit.

  58. rcr::= rcr source_reg/mem, reg/imm, rotate carry right source_reg/mem the number of bits specified in reg/imm. Least significant bit goes into carry flag AND old carry flag value is moved into the most significant bit.

  59. branching::= jmp and j_cc (jump on condition code) - More at: asm.control.flow.html

  60. macros::= a shorthand sequence of directives, instructions, and even other macros used as a statement.

  61. comments::= most assemblers use the ; character to designate a comment.

  62. skeleton_source_code_files::= a skeleton source code files are bare bones minimum files for creating a program.

  63. masm_directives::=

  64. masm_source_32bit::= the following is a skeleton source code file for 32 bit programs written for masm: masm_skel_32.asm

  65. masm_source_64bit::= the following is a skeleton source code file for 64 bit programs written for masm: masm_skel_64.asm

  66. nasm_source_32bit::= the following is a skeleton source code file for 32 bit programs written for nasm: nasm_skel_32.asm

  67. nasm_source_64bit::= the following is a skeleton source code file for 64 bit programs written for nasm: nasm_skel_64.asm

  68. masm::= Microsoft ASseMbler, found incorporated with Visual Studio.

  69. nasm::= Netwide ASseMbler, used for both Windows and Linux operating systems.

  70. byte::= 8 bits

  71. word::= 16 bits, two byte

  72. doubleword::= 32 bits, four byte, two word, same as dword
  73. dword::= 32 bits, four byte, two word ( doubleword )

  74. quadword::= 64 bits, eight byte, four word, two dword, same as qword
  75. qword::= 64 bits, eight byte, four word, two dword ( quadword )

    . . . . . . . . . ( end of section Assembly Language Basics) <<Contents | Index>>


Formulae and Definitions in Alphabetical Order