|
||
Title: ASM question Post by vishal_changrani on Feb 15th, 2006, 12:07pm 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 |
||
Title: Re: ASM question Post by vishal_changrani on Feb 15th, 2006, 12:35pm Sorry but i think i found the answer...its just doing a MOD operation :) :-[ sorry for posting it in the first place -vishal |
||
Title: Re: ASM question Post by Grimbal on Feb 16th, 2006, 4:22am No, it does an ABS(AX) In fact, it splits AX into sign and absolute value: DX = sign(AX) AX = abs(AX) |
||
Title: Re: ASM question Post by ruhela_nitk on Jul 28th, 2006, 7:48am Hi If anyone can explain the answer , please let me? |
||
Title: Re: ASM question Post by Grimbal on Jul 29th, 2006, 11:48am 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). |
||
Powered by YaBB 1 Gold - SP 1.4! Forum software copyright © 2000-2004 Yet another Bulletin Board |