cx register in 8086

Thread Starter

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..?
 

Thread Starter

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,221
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.
 

Thread Starter

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...
 

jjw

Joined Dec 24, 2013
602
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.
 

Thread Starter

cssc

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

MrChips

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

Thread Starter

cssc

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

MrChips

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

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.
 

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,221
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.
 
Top