-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsp_addsub.s43
78 lines (59 loc) · 1.45 KB
/
msp_addsub.s43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "msp430.h"
NAME msp_addsub
EXTERN mp_freeze
PUBLIC mp_add
RSEG CODE
; Adds two 256-bit numbers A and B and stores the result in C.
; B is pointed by R14, A is pointed by R13
; The result C is pointed by R12
mp_add
PUSHM.W #2,R6 ; Save R5-R6
MOV R14,R6
ADD #32,R6
CLRC ; Need to reset carry bit for the first ADDC to be equivalent to ADD
inadd
MOV @R13+,0(R12)
ADDC @R14+,0(R12)
MOV SR,R5
INCD R12
CMP R14,R6
JZ finadd
MOV R5,SR
JMP inadd
finadd
SUB #32,R12 ; Rewind R12
POPM.W #2,R6
CLR R13
CALLA #mp_freeze
RETA
PUBLIC mp_subb
RSEG CODE
; Subtracts B from A where A and B are 256-bit numbers and stores the result in C.
; B is pointed by R14, A is pointed by R13
; The result C is pointed by R12.
; If R15 is set no conditional addition of 2^255-19 is done.
mp_subb
PUSHM.W #3,R6 ; Save R4 - R6
MOV R14,R6
ADD #32,R6
SETC ; Need to set carry bit for the first SUBC to be equivalent to SUB
insub
MOV @R14+,R4 ; Small workaround allowing to perform A = B-A
MOV @R13+,0(R12)
SUBC R4,0(R12)
MOV SR,R5
INCD R12
CMP R14,R6
JZ finsub
MOV R5,SR
JMP insub
finsub
SUB #32,R12 ; Rewind R12
POPM.W #3,R6 ; Restore R4 - R6
TST R15
JZ subret ; Skip the freezing if R15 is not set
MOV #1,R13
CALLA #mp_freeze
subret
RETA
END