cx register in 8086

Discussion in 'Programmer's Corner' started by cssc, Oct 22, 2014.

  1. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    what is the largest number that cx register can have?
     
  2. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,815
    835
    The cx register is 16 bits wide. The maximum value (decimal) it can hold is 65,536, which is FFFF in hex.
     
    cssc likes this.
  3. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    yea...but
    when i give that number.,its displaying an error...
    i had to give it as:
    mov cx,0ffffh
    is this ok..?
     
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,815
    835
    Yes. Representing hex must follow a specific syntax sorry if I confused you by using shorthand.
     
  5. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    okk...
    actually.,
    i wanted to use that for initiating a loop which would cause a time delay for a few seconds...
    but i am unable to make it... :(
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    That will depend on the size of the CX register and the number representation you are using.
    Typically the CX register is 16 bits long.
    There are two commonly used integer representations, unsigned integer and 2's complement integers.

    If the representation is straight binary, unsigned integers, then the maximum value is 2^n - 1 = 65535.

    If the representation is 2's complement integer, then the maximum value is 2^(n-1) - 1 = 32767,

    where n is the number of bits in the CX register.
     
    cssc likes this.
  7. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    here are a few lines of my code

    mov cx,0ffffh
    time:
    nop
    nop
    nop
    loop time


    i wrote them for creating some time delay...but dont know why its not working... i didn't get any errors even...
     
  8. NorthGuy

    Active Member

    Jun 28, 2014
    605
    121
    A typical way to put 0xffff into CX is:

    Code (Text):
    1. xor CX,CX
    2. dec CX
     
  9. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    thats not working either... :-/
     
  10. jjw

    Member

    Dec 24, 2013
    173
    31
    How long delay you need?
    In your example the delay may be very short depending on the clock frequency.
     
  11. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    yes.. i had that doubt...
    but what ever the delay is...
    my cx would have the maximum of ffffh only right.?
     
  12. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    Your delay will be in milliseconds, not seconds.
    Is this a simulation or on a real MCU?
    What is the clock frequency of the MCU?
    How are you measuring (determining) your delay?
     
  13. cssc

    Thread Starter New Member

    Oct 19, 2014
    26
    1
    no.. i did it in masm software...
    :confused:
    i am just a beginner and i am not yet exposed to any any real mcu's
     
    Last edited: Oct 22, 2014
  14. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    So you are using masm on a PC?
    Is the masm actually executing the code on a chip or is it running in simulation mode?
    How do you determine how long is the actual delay?
     
  15. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,764
    Where are the decrement and test for zero instruction(s)?
     
  16. Papabravo

    Expert

    Feb 24, 2006
    10,179
    1,800
    They are inherent in the "loop" instruction. Take a trip to the 21st century of complex instructions set machines.
    --Grin!
     
    cssc likes this.
  17. NorthGuy

    Active Member

    Jun 28, 2014
    605
    121
    I would rather say these instructions are obsolete. They only support them for compatibility. In early Pentiums these instructions used to run slower than the same thing coded with "regular" instructions. I don't know if they made them any faster by now. I suppose they should've because not that many things they can still squeeze.
     
  18. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,693
    2,764
    Never coded x86 in asm! I save that for PIC. PC stuff I do C and C++. :)
     
    cssc likes this.
  19. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,399
    497
    Just checked my microprocessor textbook (we did intel), CX in 8086 is 16 bits so the largest value you can load in CX is FFFFH.

    I think your error is the low case h. I think your code should be:
    MOV CX, 0FFFFH
     
  20. MrChips

    Moderator

    Oct 2, 2009
    12,452
    3,371
    OP is not getting any errors with his code. Any of these lines should assemble without error:

    Code (Text):
    1.  
    2. mov cx, 0ffffh
    3.  
    4. MOV CX,0FFFFH
    5.  
    6. MOV CX, 65535
    7.  
    There is nothing wrong with his code. He just doesn't have a way to measure millisecond delay times.
     
    cssc likes this.
Loading...