You are on page 1of 2

Technolocus: CBW/CWD Instructions

http://technolocus.blogspot.com/2010/05/cbwcwd-instructions.html January 16, 2011

Home|Assembly Language Programming|Instruction Set|

The CBW instruction fill upper-byte or word with copies of sign bit of
lower bit. This operation is called sign extension of byte to word. No flag is affected by this
instruction. This operation is done with AL register and the result is stored in AX register,
so no operand is required. In the demonstration given below we've first cleared AX and
then enter 9Bh in AL. The signed number is negative. That means most significant bit is 1.

-A 100
448A:0100 MOV AX,0
448A:0103 MOV AL,9B
448A:0105 CBW
448A:0106
-R IP
IP 0103
:100
-P

AX=0000 BX=0000 CX=0000 DX=002B SP=FFEE BP=0000 SI=0000


DI=0000
DS=3000 ES=8000 SS=6000 CS=448A IP=0103 NV UP EI PL NZ AC PO
NC
448A:0103 B09B MOV AL,9B
-P

AX=009B BX=0000 CX=0000 DX=002B SP=FFEE BP=0000 SI=0000


DI=0000
DS=3000 ES=8000 SS=6000 CS=448A IP=0105 NV UP EI PL NZ AC PO
NC
448A:0105 98 CBW
-P

AX=FF9B BX=0000 CX=0000 DX=002B SP=FFEE BP=0000 SI=0000


DI=0000
DS=3000 ES=8000 SS=6000 CS=448A IP=0106 NV UP EI PL NZ AC PO
NC
448A:0106 0101 ADD [BX+DI],AX DS:0000=3400

Now, after we execute the instruction CBW, AH is filled up with the most significant bit of
the content of AL and that makes the content of AH register FFh, all 1s.

The instruction CWD fills upper word or double word with sign bit of lower word. This
instruction is just an extended form of the CBW instruction.This instruction results in sign
extension of AX register to DX:AX. To demonstrate it we first clear both AX and DX and
then move a number F01Ah to register AX. Then we execute CWD.

-A 100
448A:0100 MOV AX,0
448A:0103 MOV DX,0
448A:0106 MOV AX,F01A
448A:0109 CWD
448A:010A
-R IP
IP 0109
:100
-G 10A

AX=F01A BX=0000 CX=0000 DX=FFFF SP=FFEE BP=0000 SI=0000


DI=0000
DS=3000 ES=8000 SS=6000 CS=448A IP=010A OV UP EI PL NZ AC PE
CY
448A:010A 0000 ADD [BX+SI],AL DS:0000=55

The right most bit of the content of AX, i.e. the sign bit is 1 signifying a negative number.
Thus the DX register is totally filled up with 1s and that makes it FFFFh.

You might also like