/[projet1]/public/pc/tools/osdk/main/Osdk/_final_/lib/div.s
Defence Force logotype

Contents of /public/pc/tools/osdk/main/Osdk/_final_/lib/div.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1151 - (show annotations)
Sun Aug 10 15:45:02 2014 UTC (5 years, 1 month ago) by dbug
File size: 1086 byte(s)


1
2 ;
3 ; op1/op2 (16-bit signed)
4 ;
5 div16i
6 lda op1+1 ;dividend sign
7 eor op2+1
8 pha ;sign of quotient
9 jsr unsign
10 jsr div16u ;unsigned divide
11 pla ;sign of quotient
12 bmi resign
13 lda op1+1
14 rts
15
16 ;
17 ; op1 % op2 (16-bit signed)
18 ;
19 mod16i
20 lda op1+1 ;dividend sign
21 pha ;sign of modulo
22 jsr unsign
23 jsr mod16u ;unsigned modulo
24 pla ;sign of modulo
25 bmi resignmod
26 lda tmp+1
27 rts
28
29 resignmod
30 stx op1
31 lda tmp+1
32 sta op1+1
33 resign
34 sec
35 lda #0
36 sbc op1
37 tax
38 lda #0
39 sbc op1+1
40 rts
41
42 unsign
43 lda op1+1
44 bpl unsign1
45 sec
46 lda #0
47 sbc op1
48 sta op1
49 lda #0
50 sbc op1+1
51 sta op1+1
52 unsign1
53 lda op2+1
54 bpl unsign2
55 sec
56 lda #0
57 sbc op2
58 sta op2
59 lda #0
60 sbc op2+1
61 sta op2+1
62 unsign2
63 rts
64 ;
65 ; op1/op2 (16-bit unsigned)
66 ;
67 div16u
68 lda op2
69 ora op2+1
70 beq zerodiv
71
72 lda #0
73 sta tmp
74 sta tmp+1
75
76 ldx #16
77 asl op1
78 rol op1+1
79 udiv2
80 rol tmp
81 rol tmp+1
82 sec
83 lda tmp
84 sbc op2
85 tay
86 lda tmp+1
87 sbc op2+1
88 bcc udiv3
89 sty tmp
90 sta tmp+1
91 udiv3
92 rol op1
93 rol op1+1
94 dex
95 bne udiv2
96 ldx op1
97 lda op1+1
98 rts
99 ;
100 ; op1%op2 (16-bit unsigned)
101 ;
102 mod16u
103 jsr div16u
104 ldx tmp
105 lda tmp+1
106 rts
107
108 zerodiv
109 ldx #$85
110 jmp $C47E
111

  ViewVC Help
Powered by ViewVC 1.1.26