# cx register in 8086

#### cssc

Joined Oct 19, 2014
26
what is the largest number that cx register can have?

#### djsfantasi

Joined Apr 11, 2010
7,749
The cx register is 16 bits wide. The maximum value (decimal) it can hold is 65,536, which is FFFF in hex.

#### cssc

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

#### djsfantasi

Joined Apr 11, 2010
7,749
Yes. Representing hex must follow a specific syntax sorry if I confused you by using shorthand.

#### cssc

Joined Oct 19, 2014
26
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...

#### MrChips

Joined Oct 2, 2009
23,849
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

Joined Oct 19, 2014
26
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...

#### NorthGuy

Joined Jun 28, 2014
611
A typical way to put 0xffff into CX is:

Code:
xor CX,CX
dec CX

#### cssc

Joined Oct 19, 2014
26
thats not working either... :-/

#### jjw

Joined Dec 24, 2013
650
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...
How long delay you need?
In your example the delay may be very short depending on the clock frequency.

#### cssc

Joined Oct 19, 2014
26
but what ever the delay is...
my cx would have the maximum of ffffh only right.?

#### MrChips

Joined Oct 2, 2009
23,849
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?

#### cssc

Joined Oct 19, 2014
26
no.. i did it in masm software...

i am just a beginner and i am not yet exposed to any any real mcu's

Last edited:

#### MrChips

Joined Oct 2, 2009
23,849
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?

#### joeyd999

Joined Jun 6, 2011
4,477
here are a few lines of my code

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...
Where are the decrement and test for zero instruction(s)?

#### Papabravo

Joined Feb 24, 2006
16,459
Where are the decrement and test for zero instruction(s)?
They are inherent in the "loop" instruction. Take a trip to the 21st century of complex instructions set machines.
--Grin!

#### NorthGuy

Joined Jun 28, 2014
611
Take a trip to the 21st century of complex instructions set machines.
--Grin!
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.

#### joeyd999

Joined Jun 6, 2011
4,477
They are inherent in the "loop" instruction. Take a trip to the 21st century of complex instructions set machines.
--Grin!
Never coded x86 in asm! I save that for PIC. PC stuff I do C and C++.

#### shteii01

Joined Feb 19, 2010
4,644
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

#### MrChips

Joined Oct 2, 2009
23,849
OP is not getting any errors with his code. Any of these lines should assemble without error:

Code:
mov cx, 0ffffh

MOV CX,0FFFFH

MOV CX, 65535
There is nothing wrong with his code. He just doesn't have a way to measure millisecond delay times.