OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [lib/] [9x8/] [math.s] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sinclairrf
; Copyright 2014, Sinclair R.F., Inc.
2 2 sinclairrf
;
3 4 sinclairrf
; Unsigned arithmetic operations.
4 2 sinclairrf
 
5 4 sinclairrf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;
7
; Add two unsigned 8-bit values to produce an unsigned 16-bit value.
8
; Method:  Calculate the sum of the msb of the two raw values and the msb of the
9
;          sums of the 7 lsbs of the two values to get the msb of the sum and
10
;          the lsb of the MSB of the 16-bit sum.
11
; 36 instructions
12
;
13
; ( u1 u2 - (u1+u2)_LSB (u1+u2)_MSB )
14
.function math__add_u8_u8_u16
15
  ; and the two 7 lsbs and put the 7 lsb of that sum on the return stack
16
  over 0x7F & over 0x7F & + dup 0x7F & >r
17
  ; add the msb of the sum of the 7 lsbs and the two inputs
18
  0x80 & <<msb swap 0x80 & <<msb + swap 0x80 & <<msb +
19
  ; construct the MSB of the sum as bit 1 of the sums of the msbs
20
  dup 0>> swap
21
  ; set the msb of the LSB if the lsb of the sum of the msbs is non-zero
22
  0x01 & 0<> 0x80 & r> or
23
  ; swap the orders so that the MSB is on the top of the data stack
24
  .return(swap)
25 2 sinclairrf
 
26 4 sinclairrf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
; miscellaneous unsigned addition operations
28 2 sinclairrf
 
29 4 sinclairrf
.function math__add_u16_u8_u16
30
  swap >r .call(math__add_u8_u8_u16) r> .return(+)
31 2 sinclairrf
 
32 4 sinclairrf
.function math__add_u16_u8_u24
33
  swap >r .call(math__add_u8_u8_u16) r> .call(math__add_u8_u8_u16) .return
34 2 sinclairrf
 
35 4 sinclairrf
.function math__add_u24_u8_u24
36
  swap >r .call(math__add_u16_u8_u24)
37
  r> .return(+)
38 2 sinclairrf
 
39 4 sinclairrf
.function math__add_u24_u8_u32
40
  swap >r .call(math__add_u16_u8_u24)
41
  r> .call(math__add_u8_u8_u16)
42
  .return
43 2 sinclairrf
 
44 4 sinclairrf
.function math__add_u32_u8_u32
45
  swap >r .call(math__add_u24_u8_u32)
46
  r> .return(+)
47 2 sinclairrf
 
48 4 sinclairrf
.function math__add_u32_u16_u32
49
  >r .call(math__add_u32_u8_u32)
50
  r> .call(math__add_u24_u8_u24)
51
  .return
52 2 sinclairrf
 
53 4 sinclairrf
.function math__add_u32_u24_u32
54
  >r .call(math__add_u32_u16_u32)
55
  r> .call(math__add_u16_u8_u16)
56
  .return
57 2 sinclairrf
 
58 4 sinclairrf
.function math__add_u32_u32_u32
59
  >r .call(math__add_u32_u24_u32)
60
  r> .return(+)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.