wu :: forums
« wu :: forums - ASM question »

Welcome, Guest. Please Login or Register.
May 3rd, 2024, 7:34am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   microsoft
(Moderators: ThudnBlunder, Grimbal, william wu, SMQ, Icarus, towr, Eigenray)
   ASM question
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: ASM question  (Read 7581 times)
vishal_changrani
Newbie
*





   


Posts: 4
ASM question  
« on: Feb 15th, 2006, 12:07pm »
Quote Quote Modify Modify

Hi,
I am back with one more question.....supposedly asked  in an MS interview...
 
Q. The following asm block performs a common math function, what is it?
CWD XOR AX,DX
SUB AX,DX
 
My guess earlier was it is exchangin AX and DX but doesnt seemt to be that.
Also is CWD carried out first or XOR? in the first line
 
any and all replies would be appreciated.
Thank u
Vishal
IP Logged
vishal_changrani
Newbie
*





   


Posts: 4
Re: ASM question  
« Reply #1 on: Feb 15th, 2006, 12:35pm »
Quote Quote Modify Modify

Sorry but i think i found the  answer...its just doing a MOD operation Smiley
 Embarassed sorry for posting it in the first place
-vishal
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: ASM question  
« Reply #2 on: Feb 16th, 2006, 4:22am »
Quote Quote Modify Modify

No, it does an ABS(AX)
 
In fact, it splits AX into sign and absolute value:
 
DX = sign(AX)
AX = abs(AX)
IP Logged
ruhela_nitk
Newbie
*





  ruhela_nik@yahoo.com  
Email

Gender: male
Posts: 1
Re: ASM question  
« Reply #3 on: Jul 28th, 2006, 7:48am »
Quote Quote Modify Modify

Hi  
If anyone  can explain the answer , please let me?
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: ASM question  
« Reply #4 on: Jul 29th, 2006, 11:48am »
Quote Quote Modify Modify

CWD converts a word to double.  It does so by extending the sign of AX into DX.  Practically, it means it does DX=0 if AX is >=0 or DX=-1 (all bits set) if AX<0.
 
The XOR and SUB do nothing if DX=0.
If DX=-1, the XOR reverses all bits of AX and the SUB adds 1 to AX.  Together, it does  
  AX = (not AX) + 1
which is exactly how you compute AX=-1 in the 2's complement binary representation of integers.
 
So, the effect is to set DX=0 or -1 depending on AX's sign, and to set AX = abs(AX).
« Last Edit: Jul 29th, 2006, 11:50am by Grimbal » IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board