Please USE AVR ASSEMBLY LANGUAGE FOR Atmeag32....... Thank you very much!!!! Wri
ID: 3856741 • Letter: P
Question
Please USE AVR ASSEMBLY LANGUAGE FOR Atmeag32....... Thank you very much!!!!
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
facbcd ldx #s_pfac-1 ;primary accumulator size -1 ; facbcd01 lda pfac,x ;value to be converted pha ;protect dex bpl facbcd01 ;next ; lda #0 ldx #s_wrkspc-1 ;workspace size ; facbcd02 sta wrkspc01,x ;clear final result sta wrkspc02,x ;clear scratchpad dex bpl facbcd02 ; inc wrkspc02+s_wrkspc-1 ;php ;!!! uncomment for NMOS MPU !!! ;sei ;!!! uncomment for NMOS MPU !!! sed ;select decimal mode ldy #m_bits-1 ;bits to convert -1 ; facbcd03 ldx #s_pfac-1 ;operand size clc ;no carry at start ; facbcd04 ror pfac,x ;grab LS bit in operand dex bpl facbcd04 ; bcc facbcd06 ;LS bit clear ; clc ldx #s_wrkspc-1 ; facbcd05 lda wrkspc01,x ;partial result adc wrkspc02,x ;scratchpad sta wrkspc01,x ;new partial result dex bpl facbcd05 ; clc ; facbcd06 ldx #s_wrkspc-1 ; facbcd07 lda wrkspc02,x ;scratchpad adc wrkspc02,x ;double &... sta wrkspc02,x ;save dex bpl facbcd07 ; dey bpl facbcd03 ;next operand bit ; ;plp ;!!! uncomment for NMOS MPU !!! ldx #0 ; facbcd08 pla ;operand sta pfac,x ;restore inx cpx #s_pfac bne facbcd08 ;next ; rts ; ;================================================================================ ; ;PER RADIX CONVERSION TABLES ; bitstab .byte 4,1,3,4 ;bits per numeral lzsttab .byte 2,9,2,3 ;leading zero suppression thresholds numstab .byte 12,48,16,12 ;maximum numerals radxtab .byte 0,"%@$" ;recognized symbols ; ;================================================================================ ; ;STATIC STORAGE
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.