MOV BX,10
ADD BX,4
MOV AX,15
MOV BL,5 <<<< This overwrite the sum 10 + 4 in BX
DIV BL
ADD AX,BX <<<< Luckily remainder was zero
MOV BX, 7
MUL BX <<<< Needlessly clobbers DX
Apart from some other imperfections, this calculation does not even follow normal algebraic rules.
You've calculated 7 * ( (4 + 10) + (15 / 5) ) when the task asked for ( 7 * (4 + 10) ) + (15 / 5)
- On 8086 both division and multiplication use the accumulator, so inevitably you'll have to move the result from whichever of these you choose to do first in an extra register.
- The byte sized division yields a quotient in
AL
but also a remainder in AH
. This task asks you to continu with the quotient disregarding the remainder. Your code does not explicitely zero AH
and that's not good enough for a generalized solution! Luckily 15 / 5 gave a remainder = 0.
Solution with division before multiplication:
mov ax, 15
mov bl, 5 ;Divider in BL
div bl ;AX/BL -> AL=3 (remainder in AH=0)
mov bl, al ;Move to an extra register
mov al, 4
add al, 10 ;AL=14
mov ah, 7
mul ah ;AL*AH -> AX=98
add al, bl
Solution with multiplication before division:
mov al, 4
add al, 10 ;AL=14
mov ah, 7
mul ah ;AL*AH -> AX=98
mov bh, al ;Move to an extra register
mov ax, 15
mov bl, 5 ;Divider in BL
div bl ;AX/BL -> AL=3 (remainder in AH=0)
add al, bh
Both solutions produce the same result (101) and use just 2 registers (AX
and BX
).