Write an ATmega32-compatible program that adds two 10-digit ASCII numbers (which
ID: 3856743 • Letter: W
Question
Write an ATmega32-compatible program that adds two 10-digit ASCII numbers (which are located in code ROM), that is, DATA1 + DATA2. The result should be saved to RESULT in ASCII located in data RAM (accounting for the possibility of carry-out). They can be defined as follows: CSEG ORG 0x100 DATA1: .DB "2468101214" DATA2: .DB "1357911130" DSEG ORG 0x100 RESULT: .BYTE 11 Note that there are many ways you can approach solving this problem: Convert the ASCII representation to a 36-bit binary number and then add the two 5-byte representations. Add the corresponding ASCII digits 10 times, and write code to handling carry out d conversions to ensure the result looks correct. Convert to a BCD representation (or packed BCD) and adding that way, then converting back.Explanation / Answer
Take number and divide with 2 each time until we hit 1 or 0.Note the remainder values.
Basic additon rules in binary format
Simple two 4 bit numebrs addtion:
1011(11),1101(13)
output is :11000(24).Addition is performed from LSB to MSB side.
Above table calcualtion.Considering values from right to left in the aboive table.i.e from right side column LSB to MSB.
Add 1+1 that is 2.Convert 2 into binary number 10.Take 0 as sum and 1 as carry.(For first LSB bit Carry is zero by defualt)
now add 1(carry)+1+0 that is 2 . so sum is 0 and carry is 1 note:We should take carry also to add numbers.
Now add 1+0+1 that is 2 ,so sum is 0 and carry is 1
Now add 1+1+1 that is 3 in decimal.Write 3 in binary format 11.so Sum is LSB bit 1 and carry is MSB bit 1.
2 2468101214 Remainder 1234050607 0 617025303 1 308512651 1 154256325 1 77128162 1 38564081 0 19282040 1 9641020 0 4820510 0 2410255 0 1205127 1 602563 1 301281 1 150640 1 75320 0 37660 0 18830 0 9415 0 4707 1 2353 1 1176 1 588 0 294 0 147 0 73 1 36 1 18 0 9 0 4 1 2 0 1 0 0 1Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.