Computer Systems Organization I - Prof. Grishman

Assignment #7

Binary Coded Decimal Addition

Binary-coded decimal is a representation of numbers where each decimal digit is separately represented by 4 bits (a 'nibble').  Within the 4-bit field, the digit is represented as a binary integer.  For example, the decimal number 7235 would be represented in 16 bits by

0111 0010 0011 0101

BCD can be useful for numbers which are mostly read in and written out, with relatively little computation.  Some older architectures include instructions to support BCD arithmetic.  For example, the x86 has instructions DAA (decimal adjust for addition) and DAS (decimal adjust for subtraction);  an ADD followed by a DAA performs a BCD addition.

For this assignment, you are to write an x86 assembly language program which will compute the sum of two 4-digit (16 bit) BCD numbers without benefit of the DAA instruction.  Your program should have three variables,

A     DW   1234H
B     DW   4281H
SUM   DW   0

and place in SUM the BCD sum of A and B.  Basically, addition should be performed the way you would by hand, one digit at a time, starting at the right.  For each digit, you compute the sum of the digits of A and B and the carry in;  if the sum exceeds 10, you set a carry out and reduce the sum by 10.  Carries out of the high digit can be ignored.

Submit your program (.asm file) by email, as an attachment,  to me <> and to the e-tutor, Andrew Montalenti <>, by one minute before midnight on Tuesday, December 6th. (Late assignments will be penalized 1/2 point for each day late, out of a total of 4 points.) Label your email "CSO Asgn 7".