Author |
Topic: ASM question (Read 7594 times) |
|
vishal_changrani
Newbie
Posts: 4
|
|
ASM question
« on: Feb 15th, 2006, 12:07pm » |
Quote 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 Modify
|
Sorry but i think i found the answer...its just doing a MOD operation sorry for posting it in the first place -vishal
|
|
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: ASM question
« Reply #2 on: Feb 16th, 2006, 4:22am » |
Quote 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
Gender:
Posts: 1
|
|
Re: ASM question
« Reply #3 on: Jul 28th, 2006, 7:48am » |
Quote Modify
|
Hi If anyone can explain the answer , please let me?
|
|
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: ASM question
« Reply #4 on: Jul 29th, 2006, 11:48am » |
Quote 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 |
|
|
|
|