Oh really now … I was always taught that to subtract you change the sign
and add. Infact … most of the CPU architectures I have dealt with never
had “SUB” … we always
changed the sign of the subtractor and added.
Has Math 101 changed THAT much!?!?!?
Gary G. Little
“Mark Lobo” wrote in message news:xxxxx@ntdev…
>
>
> Yeah, but NT doesnt have an InterlockedExchangeSub.
> Would the only difference be using a subl instead of
> xadd?
>
>
> — Nick Ryan wrote:
> > Ntddk.h has assembly implementations of all of these
> > functions defined
> > as inlines. I suppose you can borrow them. I don’t
> > see any reason why
> > they wouldn’t work on other x86 operating systems
> > as-is.
> >
> > - Nick Ryan
> >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com] On
> > Behalf Of Mark Lobo
> > > Sent: Sunday, June 15, 2003 6:51 PM
> > > To: NT Developers Interest List
> > > Subject: [ntdev] InterlockedExhangeAdd
> > >
> > >
> > > Guys,
> > > Working on a Sunday evening and just need the
> > assembly
> > > implementation for InterlockedExchangeAdd and an
> > equivalent
> > > function for substraction. Just porting some stuff
> > and
> > > changing some at the same time, so need an OS
> > independent x86
> > > way of doing these things. Im no asembly expert,
> > so need some help.
> > >
> > > For InterlockedExchangeAdd I have:
> > > long InterlockedExchangeAdd(long * p_plValue, long
> > > p_lAdd)
> > > {
> > > long l_lResult;
> > > asm volatile (
> > > “push %%EBX;”
> > > “movl %1, %%EBX;”
> > > “movl %2, %%EAX;”
> > > “lock; xadd %%EAX, (%%EBX);”
> > > “inc %%EAX;”
> > > “mov %%EAX, %0;”
> > > “pop %%EBX”
> > > : “=g”(l_lResult) : “g”(p_plValue),
> > “g”(p_lAdd) );
> > > return l_lResult;
> > > }
> > >
> > > is that correct? Will it work on Linux correctly
> > as in
> > > it will add the new value and return the old
> > value?
> > >
> > > Also I need the substract equivalent of the above
> > in
> > > assembly, that will substract a value from the
> > > variable atomically and return the old value. Can
> > > someone please give me the asm source for that?
> > >
> > > Thanks in advance folks,
> > > Mark
> > >
> > >
> > > Do you Yahoo!?
> > > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as:
> > xxxxx@nryan.com
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
>
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>
>