25.3 Example Routines
C Language code
;Operating frequency for test is 11.0592MHz
#include "reg51.h"
#include "intrins.h"
#define MD3U32 (*(unsigned long volatile xdata *)0xfcf0)
#define MD3U16 (*(unsigned int volatile xdata *)0xfcf0)
#define MD1U16 (*(unsigned int volatile xdata *)0xfcf2)
#define MD5U16 (*(unsigned int volatile xdata *)0xfcf4)
#define MD3 (*(unsigned char volatile xdata *)0xfcf0)
#define MD2 (*(unsigned char volatile xdata *)0xfcf1)
#define MD1 (*(unsigned char volatile xdata *)0xfcf2)
#define MD0 (*(unsigned char volatile xdata *)0xfcf3)
#define MD5 (*(unsigned char volatile xdata *)0xfcf4)
#define MD4 (*(unsigned char volatile xdata *)0xfcf5)
#define ARCON (*(unsigned char volatile xdata *)0xfcf6)
#define OPCON (*(unsigned char volatile xdata *)0xfcf7)
sfr P_SW2 = 0xBA;
////////////////////////////////////////////////////////////////////////////////
//16 bits by 16 bits
////////////////////////////////////////////////////////////////////////////////
unsigned long res;
unsigned int dat1, dat2;
P_SW2 |= 0x80; // Access the extension register xsfr
MD1U16 = dat1; //dat1 User given
MD5U16 = dat2; //dat2 User given
ARCON = 4 << 5; //16 bits*16 bits, multiplication mode
OPCON = 1; // Start calculation
while((OPCON & 1) != 0); // Wait for the calculation to complete
res = MD3U32; //32-bit result
////////////////////////////////////////////////////////////////////////////////
//32 bits divided by 16 bits
////////////////////////////////////////////////////////////////////////////////
unsigned long res;
unsigned long dat1;
unsigned int dat2;
P_SW2 |= 0x80; // Access the extension register xsfr
MD3U32 = dat1; //dat1 User given
MD5U16 = data2; //dat2 User given
ARCON = 6 << 5; //32-bit/16-bit, division mode
OPCON = 1; // Start calculation
while((OPCON & 1) != 0); // Wait for the calculation to complete
res = MD3U32; //32-bit quotient, 16-bit remainder in MD5U16
unsigned long res;
unsigned long dat1;
unsigned char num; // The number of bits to shift, User given
MD3U32 = dat1; //dat1 User given
ARCON = (2 << 5) + num; //32-bit left shift mode
//ARCON = (1 << 5) + num; //32-bit right shift mode
OPCON = 1; // Start calculation
while((OPCON & 1) != 0); // Wait for the calculation to complete
res = MD3U32; //32-bit result