Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/11/08 08:25
Read: times


 
#149299 - DA A test program
Responding to: ???'s previous message
Jan said:
Russ, can you share your test code please?

Certainly. There's no magic. Here are the interesting parts:
/* ////////////////////////////////////////////////////////////////////////////
                                    main()
//////////////////////////////////////////////////////////////////////////// */

#if 0
char NewPSW(char PSW, char ACC) {               /* Compile these to create */
    return PSW + ACC;                           /*  templates for similar */
    }                                           /*  ASM functions */

char NewACC(char PSW, char ACC) {
    return PSW - ACC;
    }
#else
char NewPSW(char, char);                        /* Function prototypes for */
char NewACC(char, char);                        /*  functions written in ASM */
#endif

void main() {

    char         ACC,  PSW;
    int         iACC, iPSW;

    hw_init();                                  /* Go set up the hardware */
    printf("DA A test\n\n");                    /* Sign on */

    for (iPSW = 0x00; iPSW <= 0xC0; iPSW += 0x40)
    for (iACC = 0x00; iACC <= 0xFF; iACC += 0x01) {
        ACC = (char) iACC;
        PSW = (char) iPSW;

        printf("Old PSW: %02X, Old ACC: %02X, New PSW: %02X, New ACC: %02X\n",
            PSW, ACC, NewPSW(PSW, ACC), NewACC(PSW, ACC));

        }
    printf("\nTest complete\n");

    while (1) {                                 /* Spin here forever */
        }                                       /* End 'spin here forever' */
    }                                           /* End main() */

-----------------------------------------------------------------

          PUBLIC    NewACC
          PUBLIC    NewPSW

          RSEG      CODE

          IF 0

NewPSW:
          MOV       PSW,R7                  ; Get PSW
          MOV       R0,#$LOCBI NewPSW+1     ; Get address of ACC
          MOV       A,@R0                   ; Get ACC
          DA        A                       ; Do decimal adjust
          MOV       R7,PSW                  ; Return PSW in R7
          RET

NewACC:
          MOV       PSW,R7                  ; Get PSW
          MOV       R0,#$LOCBI NewPSW+1     ; Get address of ACC
          MOV       A,@R0                   ; Get ACC
          DA        A                       ; Do decimal adjust
          MOV       R7,A                    ; Return ACC in R7
          RET

          END
This code exercises all combinations of CY, AC, and ACC, not just those that could result from a valid BCD addition. So according to what we learned on 10 January, some goofiness in the output is to be expected, as seen in the results that I posted for the C8051F120.

Of course you need a bunch of boilerplate initialization stuff that will depend on the particular hardware you are using. Surely you can grab such from an existing project.

Note also that the little assembly language subroutines will probably need adjustment to match the calling convention of whatever compiler you are using.

-- Russ


List of 34 messages in thread
TopicAuthorDate
DAA Misunderstanding            01/01/70 00:00      
   could this be it?            01/01/70 00:00      
      Maybe ... nope            01/01/70 00:00      
   a double negative ???            01/01/70 00:00      
      ... or an exclusive OR            01/01/70 00:00      
      Case 4            01/01/70 00:00      
         Are there don't-care situations?            01/01/70 00:00      
            I think this is the case            01/01/70 00:00      
               Not quite ...            01/01/70 00:00      
                  no            01/01/70 00:00      
            True to bible            01/01/70 00:00      
   e-mail to SILabs sent just now            01/01/70 00:00      
   Operands must consist of two packed BCD digits!            01/01/70 00:00      
      OK, but what does a packed 07 look like            01/01/70 00:00      
         Correct            01/01/70 00:00      
            if case 4 is a biblical catastrophe            01/01/70 00:00      
               Not true            01/01/70 00:00      
                  more to this            01/01/70 00:00      
                     Same as Case 1            01/01/70 00:00      
   reply from SILabs            01/01/70 00:00      
      I'm happy now            01/01/70 00:00      
      I am willing to try...            01/01/70 00:00      
         DA A test program            01/01/70 00:00      
            the results...            01/01/70 00:00      
               DS89C450 is strictly "biblical", too...            01/01/70 00:00      
                  The DAA instruction is so specific...            01/01/70 00:00      
                     point of view            01/01/70 00:00      
                        Agreed!            01/01/70 00:00      
               the last hope gone... XC866 is DAA-biblical too            01/01/70 00:00      
                  no "pick and choose" eitherThe Bible or "the bible            01/01/70 00:00      
                     don't take it too literally, please...            01/01/70 00:00      
      DAA on other Architectures            01/01/70 00:00      
         this is how it happened            01/01/70 00:00      
         Thanks for the link!            01/01/70 00:00      

Back to Subject List