The following code implements the binary method to calculate x^n (mod CORESIZE) in Redcode. For calculations with n > 13, the binary method out-performs a simple loop.
power mov #1, _powerr _powloop mov.b _powern, temp mod #2, temp seq.b temp, #0 mul.b _powerx, _powerr mul.b _powerx, _powerx div #2, _powern jmn _powloop, _powern
No comments:
Post a Comment