CBW, CWD, CDQ...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Peter_Vigren

CBW, CWD, CDQ...

Post by Peter_Vigren »

What is the usage of them??
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:CBW, CWD, CDQ...

Post by df »

conversions for signed + unsigned. they are very handy indeed!
-- Stu --
Peter_Vigren

Re:CBW, CWD, CDQ...

Post by Peter_Vigren »

df wrote: conversions for signed + unsigned. they are very handy indeed!
Yeah... so far I have understood... but an example perhaps?
sriko

Re:CBW, CWD,......

Post by sriko »

as far as CBW... is concerned they are useful to convert 8 bit to 16 bit values.
as i know , it applies only to the ax or accumulator register.it is also used during DIV instruction and MUL .
suppose we want to div 8bit/8bit then usually it gives an error, so
we first put the 8 bit dividend into the ax reg. then write CBW which puts zeroes into AH reg .Then we use DIV operand.
op1 db 40
op2 db 10
..
mov al,op1 ; ;we can't write mov ax,op1
cbw
div op2.
result = 4 in al, ah=0;
During multiplication of 8bit x 8 bit there is all possibility that the result will be 16 bit. so CBW is used before MUL.
similarly for 32 bit/16bit or 32bit x 16 bit, result is obttained in dx:ax pair.here CWD is used

kindly tell me if i am wrong
Post Reply