Assembly Language: cbw

raphnguyen picture raphnguyen · Nov 1, 2011 · Viewed 9.5k times · Source

I am unsure of what the cbw command actually does. I have a snippet of code:

mov  ax,0FF0h
cbw
idiv ah

How does the value of ax change after cbw?

Answer

user47322 picture user47322 · Nov 1, 2011

The cbw instruction sign-extends a byte into a word. In this case, it'll take the sign bit of AL (which happens to be 1) and copy it into every bit of AH.

This means that the two's-complement value of AX will be the same, but the binary representation will be different.

The value of AX after the cbw instruction will be FFF0h (a 16-bit -16 value, just like AL was originally an 8-bit -16)