Search code examples
assemblyx86-16tasm

How to store CS and IP addresses (Intel 8086)?


I would like to store CS (code segment) and IP (instruction pointer) addresses to any of available registers AX, BX, CX or DX. Is it possible somehow to access current CS or IP values?


Solution

  • Yes, CS is directly accessible. IP, however, isn't. The usual trick is to do a CALL instruction which will place it on the stack:

        mov dx, cs ; save cs into dx
        call next
    next:
        pop ax ; place ip of "next" into ax, adjust as necessary
    

    Of course this is only needed if the load address is not known.