mov Ax,260
mov Al,19
The AL
register is the lowest half of the AX
register.
AX
/-----------------\
MSB xxxx xxxx xxxx xxxx LSB
\-------/ \-------/
AH AL
The 2nd instruction mov al, 19
thus erroneously overwrites your 1st number.
Mul Ax
The byte-sized mul
instruction multiplies the AL
register by the specified byte-sized operand.
The word-sized mul
instruction multiplies the AX
register by the specified word-sized operand.
Using mul ax
then would calculate AX * AX
, which is not what you wanted. You want to multiply different numbers.
Using AX
together with another register like BX
solves both problems.
What to do with that cbw
depends on how we look at the code.
If you work with the numbers as immediates (260, 19), then just use a word-sized register even for the small number 19:
mov bx, 260
mov ax, 19
mul bx ; Product AX * BX is in DX:AX but here DX=0
PutInt ax
or even let the assembler do the multiplication:
mov ax, 260 * 19
PutInt ax
If the numbers come from memory (different sized variables) then you need to extend the smaller one.
Unsigned numbers, use mul
for unsigned multiply
mov bx, wNum ; [0,65535]
mov al, bNum ; [0,255]
mov ah, 0
mul bx ; Product AX * BX is in DX:AX
PutInt ax
I advice against using cbw
in this case! Using cbw
would criple all numbers from 128 upwards.
Signed numbers, use imul
for signed multiply
mov bx, wNum ; [-32768,32767]
mov al, bNum ; [-128,127]
cbw
imul bx ; Product AX * BX is in DX:AX
PutInt ax
cbw
is the right choice to extend the signed byte from AL
.