source: xtideuniversalbios/trunk/Assembly_Library/Inc/Math.inc@ 196

Last change on this file since 196 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 1.8 KB
Line 
1; Project name : Assembly Library
2; Description : Math related macros.
3%ifndef MATH_INC
4%define MATH_INC
5
6FALSE EQU 0
7TRUE EQU 1
8
9
10;--------------------------------------------------------------------
11; MIN_U Unsigned comparison
12; MIN_S Signed comparison
13; Parameters:
14; %1: Operand 1
15; %2: Operand 2
16; Returns:
17; %1: Lesser operand
18; Corrupts registers:
19; Nothing
20;--------------------------------------------------------------------
21%macro MIN_U 2
22 cmp %1, %2 ; Is %1 smaller?
23 jb %%Return ; If so, return
24 mov %1, %2 ; Copy %2 to %1
25ALIGN JUMP_ALIGN
26%%Return:
27%endmacro
28
29%macro MIN_S 2
30 cmp %1, %2 ; Is %1 smaller?
31 jl %%Return ; If so, return
32 mov %1, %2 ; Copy %2 to %1
33ALIGN JUMP_ALIGN
34%%Return:
35%endmacro
36
37
38;--------------------------------------------------------------------
39; MAX_U Unsigned comparison
40; MAX_S Signed comparison
41; Parameters:
42; %1: Operand 1
43; %2: Operand 2
44; Returns:
45; %1: Greater operand
46; Corrupts registers:
47; Nothing
48;--------------------------------------------------------------------
49%macro MAX_U 2
50 cmp %1, %2 ; Is %1 greater?
51 ja %%Return ; If so, return
52 mov %1, %2 ; Copy %2 to %1
53ALIGN JUMP_ALIGN
54%%Return:
55%endmacro
56
57%macro MAX_S 2
58 cmp %1, %2 ; Is %1 greater?
59 jg %%Return ; If so, return
60 mov %1, %2 ; Copy %2 to %1
61ALIGN JUMP_ALIGN
62%%Return:
63%endmacro
64
65
66;--------------------------------------------------------------------
67; SHR_DXAX
68; Parameters:
69; %1: Number of bits to shift
70; Returns:
71; DX:AX Shifted value
72; Corrupts registers:
73; CX
74;--------------------------------------------------------------------
75%macro SHR_DXAX 1
76 %ifnidni %1, cx
77 mov cx, %1
78 %endif
79ALIGN JUMP_ALIGN
80.ShiftNextBit:
81 shr dx, 1
82 rcr ax, 1
83 loop .ShiftNextBit
84%endmacro
85
86
87%endif ; MATH_INC
Note: See TracBrowser for help on using the repository browser.