??? 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 ENDThis 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 |