Код: Выделить всё
mov.w #0x4000, R4 ; number to invert
mov.w #0x443F, R5 ; 765.0
invert:
mov.w R5, R15 ; R15=order
add.w #0x4100, R15 ; extract the order
xor.w #0x3F80, R15 ; adjust the order
and.w #0x7F80, R15 ; clear the sign bit
incd.w R15 ; R15[1:0] is the loop counter
and.b #0x7F, R5 ; leave only mantissa bits
mov.w R4, R6 ; R7:R6 = copy of original mantissa d
mov.w R5, R7
bis.b #0x80, R7 ; add hidden 1
mov.b rev(R5), R5 ; get table entry in eax
clr.w R4 ; R5:R4 = x_0
nrl: mov.w R4, &MPY32L ; N-R iteration: compute d*x_n
mov.w R5, &MPY32H
mov.w R6, &OP2L
mov.w R7, &OP2H
nop ; needed for the MPY32
mov.w &RES1, R8 ; R9:R8 = d*x_n
mov.w &RES2, R9
add.w #0x80, R8 ; rounding off
addc.w #0, R9
swpb R8 ; shift R9:R8 8 bits right
mov.b R8, R8 ; clear MSB
mov.b R9, R10
swpb R9
mov.b R9, R9
swpb R10
add.w R10, R8 ; leave only 24 bits of the result
inv.w R8 ; subtract the result from 2.0
inv.w R9
inc.w R8 ; rounding off
addc.b #0, R9 ; R9:R8 = 2.0 - d*x_n
mov.w R8, &OP2L ; compute x_n*(2.0 - d*x_n)
mov.w R9, &OP2H
nop ; needed for the MPY32
mov.w &RES1, R4 ; R5:R4 = x_n*(2.0 - d*x_n)
mov.w &RES2, R5
add.w #0x40, R4 ; rounding off
addc.w #0, R5
rlc R4 ; aligning R5:R4
rlc R5
swpb R4 ; shift R5:R4 8 bits right
mov.b R4, R4 ; clear MSB
mov.b R5, R10
swpb R5
mov.b R5, R5
swpb R10
add.w R10, R4 ; R5:R4 = x_(n+1)
dec.w R15 ; update the counter
bit.b #1, R15 ; to perform 2 iterations of
jnz nrl ; Newton - Raphson
and.b #0x7F, R5 ; get rid of hidden 1
jnz $+6 ; jump over the next line
add.w #0x80, R15 ; correction for a power of 2
add.w R15, R5 ; add the order; R5:R4 = 1/d
ret
rev:
db 11111111b, 11111101b, 11111011b, 11111001b, 11110111b, 11110101b, 11110100b, 11110010b
db 11110000b, 11101110b, 11101101b, 11101011b, 11101001b, 11101000b, 11100110b, 11100100b
db 11100011b, 11100001b, 11100000b, 11011110b, 11011101b, 11011011b, 11011010b, 11011000b
db 11010111b, 11010101b, 11010100b, 11010011b, 11010001b, 11010000b, 11001111b, 11001101b
db 11001100b, 11001011b, 11001010b, 11001000b, 11000111b, 11000110b, 11000101b, 11000100b
db 11000010b, 11000001b, 11000000b, 10111111b, 10111110b, 10111101b, 10111100b, 10111011b
db 10111010b, 10111001b, 10111000b, 10110111b, 10110110b, 10110101b, 10110100b, 10110011b
db 10110010b, 10110001b, 10110000b, 10101111b, 10101110b, 10101101b, 10101100b, 10101011b
db 10101010b, 10101001b, 10101000b, 10101000b, 10100111b, 10100110b, 10100101b, 10100100b
db 10100011b, 10100011b, 10100010b, 10100001b, 10100000b, 10011111b, 10011111b, 10011110b
db 10011101b, 10011100b, 10011100b, 10011011b, 10011010b, 10011001b, 10011001b, 10011000b
db 10010111b, 10010111b, 10010110b, 10010101b, 10010101b, 10010100b, 10010011b, 10010011b
db 10010010b, 10010001b, 10010001b, 10010000b, 10001111b, 10001111b, 10001110b, 10001110b
db 10001101b, 10001100b, 10001100b, 10001011b, 10001011b, 10001010b, 10001001b, 10001001b
db 10001000b, 10001000b, 10000111b, 10000111b, 10000110b, 10000101b, 10000101b, 10000100b
db 10000100b, 10000011b, 10000011b, 10000010b, 10000010b, 10000001b, 10000001b, 10000000b