Technical discussions about Freescale Microcontrollers: M68HC11. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Hi, I am trying to add accumulator a and b together (aba) with two large numbers ($FF) and divide the result by 2. I am unsure how the carry works so I can add it to the result. ACCA just adds 1 bit to the result. |
|
|
|
----- Original Message ----- From: "bal_gill21" <> To: <> > I am trying to add accumulator a and b together (aba) with two large > numbers ($FF) and divide the result by 2. I am unsure how the carry > works so I can add it to the result. ACCA just adds 1 bit to the > result. Normally, when exceeding a byte you'd need a second byte to hold the most significant part of the number. But in your particular example, you can just use the carry as follows to achieve the desired division by 2 (after an addition): LDAA FIRST_NUMBER ADDA SECOND_NUMBER RORA STAA AVERAGE Because RORA will use whatever carry is there, it's like turning A into a 9-bit register, temporarily. (Note: This will only work for addition and then division by 2.) |
|
|
|
Hi all, The carry is as the name implies, the overflow of the addition. It is set if the result is larger than 255d ($FF). If you follow ABA with RORA and RORB the B register will contain the average of the initial values of A and B. Good luck, Scott bal_gill21 <> wrote: Hi, I am trying to add accumulator a and b together (aba) with two large numbers ($FF) and divide the result by 2. I am unsure how the carry works so I can add it to the result. ACCA just adds 1 bit to the result. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |
|
|
|
I don't know what I was thinking, Tony (another post) is right. Just RORA after ABA
and A contains the average. Scott Scott Grodevant <> wrote: Hi all, The carry is as the name implies, the overflow of the addition. It is set if the result is larger than 255d ($FF). If you follow ABA with RORA and RORB the B register will contain the average of the initial values of A and B. Good luck, Scott bal_gill21 wrote: Hi, I am trying to add accumulator a and b together (aba) with two large numbers ($FF) and divide the result by 2. I am unsure how the carry works so I can add it to the result. ACCA just adds 1 bit to the result. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- Yahoo! Groups Links --------------------------------- |
|
Thanks for your help, its the perfect solution for the problem. Bal --- In , "Tony Papadimitriou" <tonyp@m...> wrote: > ----- Original Message ----- > From: "bal_gill21" <bal_gill21@y...> > To: <> > > > I am trying to add accumulator a and b together (aba) with two large > > numbers ($FF) and divide the result by 2. I am unsure how the carry > > works so I can add it to the result. ACCA just adds 1 bit to the > > result. > > Normally, when exceeding a byte you'd need a second byte to hold the most > significant part of the number. But in your particular example, you can just > use the carry as follows to achieve the desired division by 2 (after an > addition): > > LDAA FIRST_NUMBER > ADDA SECOND_NUMBER > RORA > STAA AVERAGE > > Because RORA will use whatever carry is there, it's like turning A into a 9-bit > register, temporarily. (Note: This will only work for addition and then > division by 2.) > > tonyp@a... |
|
Hello, After addition using ABA you can use RORA. which includes Carry bit while shifting , you need to take care of the access nibble bit values which may cause large values. All the best Regards Nadaf bal_gill21 <> wrote: Hi, I am trying to add accumulator a and b together (aba) with two large numbers ($FF) and divide the result by 2. I am unsure how the carry works so I can add it to the result. ACCA just adds 1 bit to the result. Yahoo! Groups SponsorADVERTISEMENT --------------------------------- Yahoo! Groups Links To --------------------------------- |