`.data`

arr1 DB 4 dup (0),9

arr2 DB 4 dup (0),9

arr3 DB 5 dup (0)

notice that, now, the 9's are the 5th element in arrays 1 and 2

since the days of the 8008, intel has provided special instructions to help handle simple BCD math

AAA ASCII adjust after addition

AAS ASCII adjust after subtraction

AAM ASCII adjust after multiplication

AAD ASCII adjust before division

DAA decimal adjust after addition

DAS decimal adjust after subtraction

even though the "ASCII" names imply the numbers are ASCII, they aren't :P

they are unpacked BCD numbers that may easily be converted to ASCII when done

these instructions generally work on 2 digits at a time, one in AL, one in AH

the "decimal" instructions are used with packed BCD values

packed BCD has 2 digits in each byte, one in the lower 4 bits, one in the upper 4 bits

there are no DAM or DAD instructions

so, to answer the addition question

` mov al,arr1[4] ;the 5th element of array 1`

mov ah,0

add al,arr2[4]

aaa

the "ones" digit is in AL, the "tens" digit is in AH

there is a shortcut you can use to load bytes and clear higher-order bytes in a register

` movzx eax,byte ptr arr1[4] ;zero-extend a byte into EAX`

add al,add2[4]

aaa

the AAA instruction also works for ADC

you can replace the array indexes with a register that holds a variable index

` mov edx,4`

movzx eax,byte ptr arr1[edx]

add al,arr2[edx]

aaa

you can create a loop, you just have to move AH into AL after storing each result digit, and adding it into the next digit

you can use google to find descriptions of all the BCD instructions