we were asked to make a program that adds two digit numbers. I was ableto scan and add the input numbers but I have trouble doing the 'carry' part. i can't divide the sum of the ones place integers by ten.

what's wrong with this code? :

``````mov al,bl;move bl to al to make it the dividend, the sum is stored in bl
sub al,30h;subtract 30h to make it number
mov bl,10;move 10 to bl.

div bl;divide to get the remainder/``````

we were asked to make a program that adds two digit numbers. I was ableto scan and add the input numbers but I have trouble doing the 'carry' part. i can't divide the sum of the ones place integers by ten.

what's wrong with this code? :

``````mov al,bl;move bl to al to make it the dividend, the sum is stored in bl
sub al,30h;subtract 30h to make it number
mov bl,10;move 10 to bl.

div bl;divide to get the remainder/``````

Hi, you need to make use of AX and BX for your DIV needs 16 bit regs.

``````mov ax, 100
mov bx, 10
div bx
; result in ax:dx, quotient in ax, remainder in dx``````

; You may also look at my assembly code, lines 20-22 . There i make division too.

-- tesu

we were asked to make a program that adds two digit numbers. I was ableto scan and add the input numbers but I have trouble doing the 'carry' part. i can't divide the sum of the ones place integers by ten.

what's wrong with this code? :

``````mov al,bl;move bl to al to make it the dividend, the sum is stored in bl
sub al,30h;subtract 30h to make it number
mov bl,10;move 10 to bl.

div bl;divide to get the remainder/``````

30h....39h + 30h....39h 0...9 + 0...9 = 0...18
There is no carry!
If you have a two ASCII digits
'1','9' so 31h, 39h
They are already grouped as 1's, 10's
Tens = '1'-'0' = 1
Ones = '9'-'0' = 9

If you truly want the divide!
# = (Tens * 10) + Ones
or
# = (Tens << 3) + Tens + Tens + Ones

You can use the div (unsigned) or idiv (signed) instructions to break the Dividend into its Quotient and Remainder.

Actually an 8-bit divisor divides against the 16-bit dividend in
AX, AH=remainder AL=quotient, so he must clear AH before the division:

``````xor ah, ah
mov al, bl
mov bl, 10
div bl``````

And a 16-bit divisor divides against the dividend in DX:AX
, remainder is stored in DX, quotient in AX

if you are adding two unpacked BCDs in the range 0-9,
and wan't to know when there is a decimal carry:

``````mov al, 39h
mov bl, 31h
sub al, 30h
sub bl, 30h
; now al=9 bl=1
cmp ah, 0 ; if AH non-zero there was carry
jnz carry
...
carry: