Search code examples
assemblyx86-16memory-segmentation

What does CS:IP mean in assembly and how it works?


I cant understand what cs:ip means. What is the role of :?


Solution

  • What is the role of :?

    This colon that separates two registers has different meaning depending on the registers used.

    • If the first register is a segment register (one of CS, DS, ES, FS, GS, or SS) then the whole "segment register : offset register" notation represents a pointer to a location in the addressable memory (1MB + HMA). To calculate the linear address you would first multiply the value in the segment register by 16 and then add the value in the offset register.
      Examples include CS:IP, SS:SP, DS:SI, ES:DI, ...

    • If the first register is not a segment register then a combination of two 16-bit general purpose registers (GPRs) is used to represent a 32-bit number. In the case of an 8086 simply because its architecture has no 32-bit registers.
      A notation that you'll see a lot is DX:AX. The value that this represents is calculated from first multiplying what is in DX by 65536 and then adding what is in AX.

    I can't understand what cs:ip means.

    Given that cs means "code segment" and that ip means "instruction pointer" (this is not a general purpose register!) the combination cs:ip represents the location where the CPU is currently fetching instructions to execute.