Line 1... |
Line 1... |
; Copyright 2012, Sinclair R.F., Inc.
|
; Copyright 2014, Sinclair R.F., Inc.
|
;
|
;
|
; Multi-byte arithmetic
|
; Unsigned arithmetic operations.
|
|
|
; Notation: Multi-byte values on the stack are xx[n] where n=0 is the least
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
; significant byte of the value
|
;
|
|
; Add two unsigned 8-bit values to produce an unsigned 16-bit value.
|
.function add_u16_u8__u16 ; ( u0[0] u0[1] u1[0] - us[0] us[1] )
|
; Method: Calculate the sum of the msb of the two raw values and the msb of the
|
swap >r +uu r> +
|
; sums of the 7 lsbs of the two values to get the msb of the sum and
|
.return
|
; the lsb of the MSB of the 16-bit sum.
|
|
; 36 instructions
|
.function add_u16_u8__u24 ; ( u0[0] u0[1] u1[0] - us[0] us[1] us[2] )
|
;
|
swap >r +uu r> +uu
|
; ( u1 u2 - (u1+u2)_LSB (u1+u2)_MSB )
|
.return
|
.function math__add_u8_u8_u16
|
|
; and the two 7 lsbs and put the 7 lsb of that sum on the return stack
|
.function add_u16_u16__u16 ; ( u0[0] u0[1] u1[0] u1[1] - us[0] us[1] )
|
over 0x7F & over 0x7F & + dup 0x7F & >r
|
>r .call(add_u16_u8__u16) r> +
|
; add the msb of the sum of the 7 lsbs and the two inputs
|
.return
|
0x80 & <<msb swap 0x80 & <<msb + swap 0x80 & <<msb +
|
|
; construct the MSB of the sum as bit 1 of the sums of the msbs
|
.function add_u16_u16__u24 ; ( u0[0] u0[1] u1[0] u1[1] - us[0] us[1] us[2] )
|
dup 0>> swap
|
>r .call(add_u16_u8__u24) r> .call(add_u16_u8__u16)
|
; set the msb of the LSB if the lsb of the sum of the msbs is non-zero
|
.return
|
0x01 & 0<> 0x80 & r> or
|
|
; swap the orders so that the MSB is on the top of the data stack
|
.function add_u24_u8__u24 ; ( u0[0] u0[1] u0[2] u1[0] - us[0] us[1] us[2] )
|
.return(swap)
|
swap >r .call(add_u16_u8__u24) r> +
|
|
.return
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
; miscellaneous unsigned addition operations
|
.function add_u24_u8__u32 ; ( u0[0] u0[1] u0[2] u1[0] - us[0] us[1] us[2] u[3] )
|
|
swap >r .call(add_u16_u8__u24) r> +uu
|
.function math__add_u16_u8_u16
|
.return
|
swap >r .call(math__add_u8_u8_u16) r> .return(+)
|
|
|
.function add_u24_u16__u24 ; ( u0[0] u0[1] u0[2] u1[0] u1[1] - us[0] us[1] us[2] )
|
.function math__add_u16_u8_u24
|
>r .call(add_u24_u8__u24) r> .call(add_u16_u8__u16)
|
swap >r .call(math__add_u8_u8_u16) r> .call(math__add_u8_u8_u16) .return
|
.return
|
|
|
.function math__add_u24_u8_u24
|
.function add_u24_u16__u32 ; ( u0[0] u0[1] u0[2] u1[0] u1[1] - us[0] us[1] us[2] us[3] )
|
swap >r .call(math__add_u16_u8_u24)
|
>r .call(add_u24_u8__u32) r> .call(add_u24_u8__u24)
|
r> .return(+)
|
.return
|
|
|
.function math__add_u24_u8_u32
|
.function add_u24_u24__u24 ; ( u0[0] u0[1] u0[2] u1[0] u1[1] u1[2] - us[0] us[1] us[2] )
|
swap >r .call(math__add_u16_u8_u24)
|
>r .call(add_u24_u16__u24) r> +
|
r> .call(math__add_u8_u8_u16)
|
.return
|
.return
|
|
|
.function add_u24_u24__u32 ; ( u0[0] u0[1] u0[2] u1[0] u1[1] u1[2] - us[0] us[1] us[2] us[3] )
|
.function math__add_u32_u8_u32
|
>r .call(add_u24_u16__u32) r> .call(add_u16_u8__u16)
|
swap >r .call(math__add_u24_u8_u32)
|
.return
|
r> .return(+)
|
|
|
.function add_u32_u8__u32 ; ( u0[0] u0[1] u0[2] u0[3] u1[0] - us[0] us[1] us[2] us[3] )
|
.function math__add_u32_u16_u32
|
swap >r .call(add_u24_u8__u32) r> +
|
>r .call(math__add_u32_u8_u32)
|
.return
|
r> .call(math__add_u24_u8_u24)
|
|
.return
|
.function add_u32_u16__u32 ; ( u0[0] u0[1] u0[2] u0[3] u1[0] u1[1] - us[0] us[1] us[2] us[3] )
|
|
>r .call(add_u32_u8__u32) r> .call(add_u24_u8__u24)
|
.function math__add_u32_u24_u32
|
.return
|
>r .call(math__add_u32_u16_u32)
|
|
r> .call(math__add_u16_u8_u16)
|
.function add_u32_u24__u32 ; ( u0[0] u0[1] u0[2] u0[3] u1[0] u1[1] u1[2] - us[0] us[1] us[2] us[3] )
|
.return
|
>r .call(add_u32_u16__u32) r> .call(add_u16_u8__u16)
|
|
.return
|
.function math__add_u32_u32_u32
|
|
>r .call(math__add_u32_u24_u32)
|
.function add_u32_u32__u32 ; ( u0[0] u0[1] u0[2] u0[3] u1[0] u1[1] u1[2] u1[3] - us[0] us[1] us[2] us[3] )
|
r> .return(+)
|
>r .call(add_u32_u24__u32) r> +
|
|
.return
|
|
|
|
No newline at end of file
|
No newline at end of file
|