typedef struct { int quot; int rem; } idiv_return;これらの宣言をしておけば後は使うだけ。
typedef struct { unsigned quot; unsigned rem; } uidiv_return;
typedef struct {
int (*sidiv) (int numerator, int denominator);
unsigned (*uidiv) (unsigned numerator, unsigned denominator);
idiv_return (*sidivmod) (int numerator, int denominator);
uidiv_return (*uidivmod) (unsigned numerator, unsigned denominator);
} TLPC_ROM_DIV_STRUCT;
typedef TLPC_ROM_DIV_STRUCT *pTLPC_ROM_DIV_STRUCT;
typedef struct {
const uint32_t p_dev1;
const uint32_t p_dev2;
const uint32_t p_dev3;
const uint32_t p_dev4;
pTLPC_ROM_DIV_STRUCT pROMDiv;
const uint32_t p_dev6;
const uint32_t p_dev7;
const uint32_t p_dev8;
} TROMAPIs;
#define LPCAPI (*(TROMAPIs **)(0x1FFF1FF8UL))
#define LPC_DIV_API ((LPCAPI)->pROMDiv)
int ans, numerator, denominator;余りが欲しければ、
ans = LPC_DIV_API->sidiv (numerator, denominator);
// ans = numerator / denominator;
int ans, numerator, denominator;それすらも野暮ったかったら、gccであれば
ans = LPC_DIV_API->sidivmod (numerator, denominator).rem;
// ans = numerator % denominator;
int __aeabi_idiv (int numerator, int denominator) {としておけば、「/」やら「%」を使用するとリンクされる除算のライブラリ自体を置き換える素地となる。
return LPC_DIV_API->sidiv (numerator, denominator);
}
unsigned __aeabi_uidiv (unsigned numerator, unsigned denominator) {
return LPC_DIV_API->uidiv (numerator, denominator);
}
idiv_return __aeabi_idivmod (int numerator, int denominator) {
return LPC_DIV_API->sidivmod (numerator, denominator);
}
uidiv_return __aeabi_uidivmod (unsigned numerator, unsigned denominator) {
return LPC_DIV_API->uidivmod (numerator, denominator);
}