|
Course Index Dr. Margush's page |
A ripple carry adder is a simple circuit to perform addition that might be found in an ALU.
http://tams-www.informatik.uni-hamburg.de/applets/hades/webdemos/20-arithmetic/10-adders/ripple.html
You will write a program to simulate the logical actions of this circuit. Consider the following pseudocode. Each variable represents a byte.
newcarry = 0
do {
oldcarry = newcarry
cf = oldcarry << 1
sum = a xor b xor cf
newcarry = ((a and b) or ((a xor b) and cf)
}while(newcarry xor oldcarry)
This loop will terminate when the carry flags stabilize (new carry == oldcarry). This is essentially how a ripple carry adder operates. Your ripple carry simulator will implement this algorithm. Notice that there are no add instructions and no compare instructions. You may use only the logical (and shift) operations indicated in the pseudocode. Consult the datasheet for the ATmega16A for details on the operations that are available.
Your program will look like this:
.def a = r16 ;input values
.def b = r17
.def sum = r0 ;will contain the sum when finished
.def status = r1 ;will contain 6 flags 0b00hsvnzc
;read inputs
;ripple carry add
;show answers on LED
The input values are determined by 6 switch presses. Pressing switches in this order, 1, 7, 3, 0, 5, 3, will set input a to 0173 and b to 0053 (octal numerals). Switch press feedback is given on the LED's: Pressing the first switch will illuminate LED1, the second switch, LED2, and so forth. When the last switch press occurs, a delay of 1 second will occur before the sum is shown on the LED's. At this point, pressing any switch will toggle the display back and forth between the sum and the flag values. The processor may be reset to start the process again.
Use well named symbols for all of the registers you use in the program. Provide adequate documentation. Design the program to run using the internal 1 MHz clock. The switches should connect to PORTD and the LED's to PORTB..
A printed copy of the nicely formatted program is due in class. Be sure to document the program, including the elimination of switch bounce. If working on a team, submit only one program for the team.Use the homework submission server to upload the single assembly language source file.