1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 (* ********************************************************************** *)
16 (* Progetto FreeScale *)
19 (* Cosimo Oliboni, oliboni@cs.unibo.it *)
21 (* Questo materiale fa parte della tesi: *)
22 (* "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale" *)
24 (* data ultima modifica 15/11/2007 *)
25 (* ********************************************************************** *)
27 (* include "freescale/medium_tests_tools.ma" *)
28 include "freescale/medium_tests_tools.ma".
30 (* ************************ *)
31 (* HCS08GB60 String Reverse *)
32 (* ************************ *)
34 (* versione ridotta, in cui non si riazzerano gli elementi di counters *)
35 definition dTest_HCS08_sReverse_source : word16 → (list byte8) ≝
37 let m ≝ HCS08 in source_to_byte8 m (
38 (* BEFORE: A=0x00 H:X=0x0D4B SP=0x0D4A PC=0x18E0 Z=true *)
40 (* static unsigned char dati[3072]={...};
42 void swap(unsigned char *a, unsigned char *b)
43 { unsigned char tmp=*a; *a=*b; *b=tmp; return; } *)
45 (* [0x18C8] allineamento *) (compile m ? NOP maINH I) @
47 (* argomenti: HX e [0x0D49-A], passaggio ibrido reg, stack *)
48 (* [0x18C9] PSHX *) (compile m ? PSHX maINH I) @
49 (* [0x18CA] PSHH *) (compile m ? PSHH maINH I) @
50 (* [0x18CB] LDHX 5,SP *) (compile m ? LDHX (maSP1 〈x0,x5〉) I) @
51 (* [0x18CE] LDA ,X *) (compile m ? LDA maIX0 I) @
52 (* [0x18CF] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
53 (* [0x18D2] PSHA *) (compile m ? PSHA maINH I) @
54 (* [0x18D3] LDA ,X *) (compile m ? LDA maIX0 I) @
55 (* [0x18D4] LDHX 6,SP *) (compile m ? LDHX (maSP1 〈x0,x6〉) I) @
56 (* [0x18D7] STA ,X *) (compile m ? STA maIX0 I) @
57 (* [0x18D8] LDHX 2,SP *) (compile m ? LDHX (maSP1 〈x0,x2〉) I) @
58 (* [0x18DB] PULA *) (compile m ? PULA maINH I) @
59 (* [0x18DC] STA ,X *) (compile m ? STA maIX0 I) @
60 (* [0x18DD] AIS #2 *) (compile m ? AIS (maIMM1 〈x0,x2〉) I) @
61 (* [0x18DF] RTS *) (compile m ? RTS maINH I) @
65 unsigned int pos=0,limit=0;
67 for(limit=3072;pos<(limit/2);pos++)
68 { swap(&dati[pos],&dati[limit-pos-1]); } *)
70 (* [0x18E0] LDHX #elems *) (compile m ? LDHX (maIMM2 elems) I) @
71 (* [0x18E3] STHX 4,SP *) (compile m ? STHX (maSP1 〈x0,x4〉) I) @
72 (* [0x18E6] BRA *+52 ; 191A *) (compile m ? BRA (maIMM1 〈x3,x2〉) I) @
73 (* [0x18E8] TSX *) (compile m ? TSX maINH I) @
74 (* [0x18E9] LDA 2,X *) (compile m ? LDA (maIX1 〈x0,x2〉) I) @
75 (* [0x18EB] ADD #0x00 *) (compile m ? ADD (maIMM1 〈x0,x0〉) I) @
76 (* [0x18ED] PSHA *) (compile m ? PSHA maINH I) @
77 (* [0x18EE] LDA 1,X *) (compile m ? LDA (maIX1 〈x0,x1〉) I) @
78 (* [0x18F0] ADC #0x01 *) (compile m ? ADC (maIMM1 〈x0,x1〉) I) @
79 (* [0x18F2] PSHA *) (compile m ? PSHA maINH I) @
80 (* [0x18F3] LDA 4,X *) (compile m ? LDA (maIX1 〈x0,x4〉) I) @
81 (* [0x18F5] SUB 2,X *) (compile m ? SUB (maIX1 〈x0,x2〉) I) @
82 (* [0x18F7] STA ,X *) (compile m ? STA maIX0 I) @
83 (* [0x18F8] LDA 3,X *) (compile m ? LDA (maIX1 〈x0,x3〉) I) @
84 (* [0x18FA] SBC 1,X *) (compile m ? SBC (maIX1 〈x0,x1〉) I) @
85 (* [0x18FC] PSHA *) (compile m ? PSHA maINH I) @
86 (* [0x18FD] LDX ,X *) (compile m ? LDX maIX0 I) @
87 (* [0x18FE] PULH *) (compile m ? PULH maINH I) @
88 (* [0x18FF] AIX #-1 *) (compile m ? AIX (maIMM1 〈xF,xF〉) I) @
89 (* [0x1901] TXA *) (compile m ? TXA maINH I) @
90 (* [0x1902] ADD #0x00 *) (compile m ? ADD (maIMM1 〈x0,x0〉) I) @
91 (* [0x1904] PSHH *) (compile m ? PSHH maINH I) @
92 (* [0x1905] TSX *) (compile m ? TSX maINH I) @
93 (* [0x1906] STA 3,X *) (compile m ? STA (maIX1 〈x0,x3〉) I) @
94 (* [0x1908] PULA *) (compile m ? PULA maINH I) @
95 (* [0x1909] ADC #0x01 *) (compile m ? ADC (maIMM1 〈x0,x1〉) I) @
96 (* [0x190B] LDX 3,X *) (compile m ? LDX (maIX1 〈x0,x3〉) I) @
97 (* [0x190D] PSHA *) (compile m ? PSHA maINH I) @
98 (* [0x190E] PULH *) (compile m ? PULH maINH I) @
99 (* [0x190F] BSR *-70 ; 18C9 *) (compile m ? BSR (maIMM1 〈xB,x8〉) I) @
100 (* [0x1911] AIS #2 *) (compile m ? AIS (maIMM1 〈x0,x2〉) I) @
101 (* [0x1913] TSX *) (compile m ? TSX maINH I) @
102 (* [0x1914] INC 2,X *) (compile m ? INC (maIX1 〈x0,x2〉) I) @
103 (* [0x1916] BNE *+4 ; 191A *) (compile m ? BNE (maIMM1 〈x0,x2〉) I) @
104 (* [0x1918] INC 1,X *) (compile m ? INC (maIX1 〈x0,x1〉) I) @
105 (* [0x191A] TSX *) (compile m ? TSX maINH I) @
106 (* [0x191B] LDA 3,X *) (compile m ? LDA (maIX1 〈x0,x3〉) I) @
107 (* [0x191D] PSHA *) (compile m ? PSHA maINH I) @
108 (* [0x191E] PULH *) (compile m ? PULH maINH I) @
109 (* [0x191F] LSRA *) (compile m ? LSR maINHA I) @
110 (* [0x1920] TSX *) (compile m ? TSX maINH I) @
111 (* [0x1921] LDX 4,X *) (compile m ? LDX (maIX1 〈x0,x4〉) I) @
112 (* [0x1923] RORX *) (compile m ? ROR maINHX I) @
113 (* [0x1924] PSHA *) (compile m ? PSHA maINH I) @
114 (* [0x1925] PULH *) (compile m ? PULH maINH I) @
115 (* [0x1926] CPHX 2,SP *) (compile m ? CPHX (maSP1 〈x0,x2〉) I) @
116 (* [0x1929] BHI *-65 ; 18E8 *) (compile m ? BHI (maIMM1 〈xB,xD〉) I)
119 attraverso simulazione in CodeWarrior si puo' enunciare che dopo
120 42+79*n+5*(n>>9) ci sara' il reverse di n byte (PARI) e
124 (* creazione del processore+caricamento+impostazione registri *)
125 definition dTest_HCS08_sReverse_status ≝
131 set_acc_8_low_reg HCS08 t (* A<-A_op *)
132 (set_z_flag HCS08 t (* Z<-true *)
133 (setweak_sp_reg HCS08 t (* SP<-0x0D4A *)
134 (setweak_indX_16_reg HCS08 t (* H:X<-HX_op *)
135 (set_pc_reg HCS08 t (* PC<-0x18E0 *)
136 (start_of_mcu_version
138 (load_from_source_at t (* carica data in RAM:dTest_HCS08_RAM *)
139 (load_from_source_at t (zero_memory t) (* carica source in ROM:dTest_HCS08_prog *)
140 (dTest_HCS08_sReverse_source elems) dTest_HCS08_prog)
141 data dTest_HCS08_RAM)
142 (build_memory_type_of_mcu_version MC9S08GB60 t)
143 (mk_byte8 x0 x0) (mk_byte8 x0 x0) (* non deterministici tutti a 0 *)
144 false false false false false false) (* non deterministici tutti a 0 *)
145 (mk_word16 (mk_byte8 x1 x8) (mk_byte8 xE x0)))
147 (mk_word16 (mk_byte8 x0 xD) (mk_byte8 x4 xA)))
151 (* parametrizzazione dell'enunciato del teorema *)
152 (* primo sbozzo: confronto esecuzione con hexdump... *)
153 lemma dTest_HCS08_sReverse_dump_aux ≝
154 λt:memory_impl.λstring:list byte8.
155 (* 1) la stringa deve avere una lunghezza ∈ [0,3072] *)
156 (byte8_bounded_strlen string 〈〈x0,xC〉:〈x0,x0〉〉) ∧
157 (* 2) la stringa deve avere lunghezza pari *)
158 ((and_b8 (w16l (byte8_strlen string)) 〈x0,x1〉) = 〈x0,x0〉) ∧
159 (* 3) match di esecuzione su tempo in forma di tempo esatto *)
160 (match execute HCS08 t
161 (* parametri IN: t,H:X,strlen(string),string *)
162 (TickOK ? (dTest_HCS08_sReverse_status t 〈x0,x0〉 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen string) string))
163 (* tempo di esecuzione 42+79*n+5*(n>>9) *)
164 (42+79*(byte8_strlen string)+5*((byte8_strlen string)/512)) with
165 [ TickERR s _ ⇒ None ?
166 (* azzeramento tutta RAM tranne dati *)
167 | TickSUSP s _ ⇒ None ?
168 | TickOK s ⇒ Some ? (byte8_hexdump t (get_mem_desc HCS08 t s) dTest_HCS08_RAM (byte8_strlen string))
170 Some ? (byte8_reverse string)).
172 (* confronto esecuzione con hexdump... *)
174 lemma dTest_HCS08_sReverse_dump :
175 dTest_HCS08_sReverse_dump_aux MEM_TREE dTest_random_32.
176 unfold dTest_HCS08_sReverse_dump_aux;
178 [ split; [ normalize in ⊢ (%); autobatch ] reflexivity ]
183 (* parametrizzazione dell'enunciato del teorema *)
184 (* dimostrazione senza svolgimento degli stati *)
185 lemma dTest_HCS08_sReverse_aux ≝
186 λt:memory_impl.λstring:list byte8.
187 (* 1) la stringa deve avere una lunghezza ∈ [0,3072] *)
188 (byte8_bounded_strlen string 〈〈x0,xC〉:〈x0,x0〉〉) ∧
189 (* 2) la stringa deve avere lunghezza pari *)
190 ((and_b8 (w16l (byte8_strlen string)) 〈x0,x1〉) = 〈x0,x0〉) ∧
191 (* 3) match di esecuzione su tempo in forma di tempo esatto *)
192 (match execute HCS08 t
193 (* parametri IN: t,H:X,strlen(string),string *)
194 (TickOK ? (dTest_HCS08_sReverse_status t 〈x0,x0〉 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen string) string))
195 (* tempo di esecuzione 42+79*n+5*(n>>9) *)
196 (42+79*(byte8_strlen string)+5*((byte8_strlen string)/512)) with
197 [ TickERR s _ ⇒ None ?
198 (* azzeramento tutta RAM tranne dati *)
199 | TickSUSP s _ ⇒ None ?
200 | TickOK s ⇒ Some ? (set_mem_desc HCS08 t s (load_from_source_at t (get_mem_desc HCS08 t s) dTest_zeros 〈〈x0,xD〉:〈x0,x0〉〉))
202 Some ? (set_pc_reg HCS08 t
203 (dTest_HCS08_sReverse_status t (fst ?? (shr_b8 (w16h (byte8_strlen string)))) (fst ?? (shr_w16 (byte8_strlen string))) (byte8_strlen string) (byte8_reverse string))
204 (mk_word16 (mk_byte8 x1 x9) (mk_byte8 x2 xB)))).
207 lemma dTest_HCS08_sReverse :
208 dTest_HCS08_sReverse_aux MEM_TREE dTest_random_32.
209 unfold dTest_HCS08_sReverse_aux;
211 [ split; [ normalize in ⊢ (%); autobatch ] reflexivity ]
213 rewrite > (breakpoint HCS08 MEM_TREE (TickOK ? (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32)) 3 (39+79*byte8_strlen dTest_random_32+5*(byte8_strlen dTest_random_32/512))) in ⊢ (? ? match % in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?);
214 letin status0 ≝ (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32);
215 change in ⊢ (? ? match ? ? ? (? ? ? % ?) ? in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?) with
217 rewrite > (execute_HCS08_LDHX_maIMM2 MEM_TREE status0 〈x0,x0〉 〈x2,x0〉) in ⊢ (? ? match ? ? ? % ? in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?);
218 [ 2,3,4,5: reflexivity; ]
220 letin status1 ≝ (set_pc_reg HCS08 MEM_TREE (setweak_v_flag HCS08 MEM_TREE (setweak_n_flag HCS08 MEM_TREE (set_z_flag HCS08 MEM_TREE (set_alu HCS08 MEM_TREE (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32) (set_indX_16_reg_HC08 (alu HCS08 MEM_TREE (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32)) 〈〈x0,x0〉:〈x2,x0〉〉)) (eq_w16 〈〈x0,x0〉:〈x2,x0〉〉 〈〈x0,x0〉:〈x0,x0〉〉)) (MSB_w16 〈〈x0,x0〉:〈x2,x0〉〉)) false) (filtered_plus_w16 HCS08 MEM_TREE (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32) (get_pc_reg HCS08 MEM_TREE (dTest_HCS08_sReverse_status MEM_TREE 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen dTest_random_32) dTest_random_32)) 3));
221 change in ⊢ (? ? match ? ? ? % ? in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?) with (TickOK ? status1);
223 rewrite > (breakpoint HCS08 MEM_TREE (TickOK ? status1) 5 (34+79*byte8_strlen dTest_random_32+5*(byte8_strlen dTest_random_32/512))) in ⊢ (? ? match % in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?);
224 change in ⊢ (? ? match ? ? ? (? ? ? % ?) ? in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?) with (TickOK ? status1);
225 rewrite > (execute_HCS08_STHX_maSP1 status1 〈x0,x4〉)
226 in ⊢ (? ? match ? ? ? % ? in tick_result return ? with [TickERR⇒?|TickSUSP⇒?|TickOK⇒?] ?);
227 [ 2,3,4,5,6,7: reflexivity; ]
234 definition sReverseCalc ≝
236 match execute HCS08 MEM_TREE
237 (TickOK ? (dTest_HCS08_sReverse_status MEM_TREE 〈x0,x0〉 〈〈x0,xD〉:〈x4,xB〉〉 (byte8_strlen string) string))
238 (42+79*(byte8_strlen string)+5*((byte8_strlen string)/512)) with
239 [ TickERR s _ ⇒ None ?
240 | TickSUSP s _ ⇒ None ?
241 | TickOK s ⇒ Some ? (set_mem_desc HCS08 MEM_TREE s (load_from_source_at MEM_TREE (get_mem_desc HCS08 MEM_TREE s) dTest_zeros 〈〈x0,xD〉:〈x0,x0〉〉))
244 definition sReverseNoCalc ≝
246 Some ? (set_pc_reg HCS08 MEM_TREE
247 (dTest_HCS08_sReverse_status MEM_TREE (fst ?? (shr_b8 (w16h (byte8_strlen string))))
248 (fst ?? (shr_w16 (byte8_strlen string)))
249 (byte8_strlen string) (byte8_reverse string))
250 (mk_word16 (mk_byte8 x1 x9) (mk_byte8 x2 xB))).
252 definition sReverseCalc32 ≝ sReverseCalc dTest_random_32.
253 definition sReverseCalc64 ≝ sReverseCalc dTest_random_64.
254 definition sReverseCalc128 ≝ sReverseCalc dTest_random_128.
255 definition sReverseCalc256 ≝ sReverseCalc dTest_random_256.
256 definition sReverseCalc512 ≝ sReverseCalc dTest_random_512.
257 definition sReverseCalc1024 ≝ sReverseCalc dTest_random_1024.
258 definition sReverseCalc2048 ≝ sReverseCalc dTest_random_2048.
259 definition sReverseCalc3072 ≝ sReverseCalc dTest_random_3072.
261 definition sReverseNoCalc32 ≝ sReverseNoCalc dTest_random_32.
262 definition sReverseNoCalc64 ≝ sReverseNoCalc dTest_random_64.
263 definition sReverseNoCalc128 ≝ sReverseNoCalc dTest_random_128.
264 definition sReverseNoCalc256 ≝ sReverseNoCalc dTest_random_256.
265 definition sReverseNoCalc512 ≝ sReverseNoCalc dTest_random_512.
266 definition sReverseNoCalc1024 ≝ sReverseNoCalc dTest_random_1024.
267 definition sReverseNoCalc2048 ≝ sReverseNoCalc dTest_random_2048.
268 definition sReverseNoCalc3072 ≝ sReverseNoCalc dTest_random_3072.
270 (* *********************** *)
271 (* HCS08GB60 Counting Sort *)
272 (* *********************** *)
274 (* versione ridotta, in cui non si riazzerano gli elementi di counters *)
275 definition dTest_HCS08_cSort_source : word16 → (list byte8) ≝
277 let m ≝ HCS08 in source_to_byte8 m (
278 (* BEFORE: A=0x00 H:X=0x0F4C SP=0x0F4B PC=0x18C8 Z=true *)
280 (* /* IPOTESI: INIT VARIABILI+ARRAY GIA' ESEGUITO */
281 static unsigned int counters[256]={ campitura di 0 };
282 static unsigned char dati[3072]={ dati random };
284 void CountingSort(void)
286 unsigned int index=0,position=0; *)
288 (* /* TESI: CODICE DA ESEGUIRE
290 /* calcolo del # ripetizioni degli elementi byte */
291 for(;index<3072;index++)
292 { counters[dati[index]]++; } *)
294 (* [0x18C8] BRA *+31;18E7 *) (compile m ? BRA (maIMM1 〈x1,xD〉) I) @
295 (* [0x18CA] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
296 (* [0x18CD] LDA 256,X *) (compile m ? LDA (maIX2 〈〈x0,x1〉:〈x0,x0〉〉) I) @
297 (* [0x18D0] LSLA *) (compile m ? ASL maINHA I) @
298 (* [0x18D1] CLRX *) (compile m ? CLR maINHX I) @
299 (* [0x18D2] ROLX *) (compile m ? ROL maINHX I) @
300 (* [0x18D3] ADD #0x00 *) (compile m ? ADD (maIMM1 〈x0,x0〉) I) @
301 (* [0x18D5] PSHA *) (compile m ? PSHA maINH I) @
302 (* [0x18D6] TXA *) (compile m ? TXA maINH I) @
303 (* [0x18D7] ADC #0x0D *) (compile m ? ADC (maIMM1 〈x0,xD〉) I) @
304 (* [0x18D9] PSHA *) (compile m ? PSHA maINH I) @
305 (* [0x18DA] PULH *) (compile m ? PULH maINH I) @
306 (* [0x18DB] PULX *) (compile m ? PULX maINH I) @
307 (* [0x18DC] INC 1,X *) (compile m ? INC (maIX1 〈x0,x1〉) I) @
308 (* [0x18DE] BNE *+3 *) (compile m ? BNE (maIMM1 〈x0,x1〉) I) @
309 (* [0x18E0] INC ,X *) (compile m ? INC maIX0 I) @
310 (* [0x18E1] TSX *) (compile m ? TSX maINH I) @
311 (* [0x18E2] INC 1,X *) (compile m ? INC (maIX1 〈x0,x1〉) I) @
312 (* [0x18E4] BNE *+3 *) (compile m ? BNE (maIMM1 〈x0,x1〉) I) @
313 (* [0x18E6] INC ,X *) (compile m ? INC maIX0 I) @
314 (* [0x18E7] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
315 (* [0x18EA] CPHX #elems *) (compile m ? CPHX (maIMM2 elems) I) @ (* dimensione dei dati al massimo 0x0C00 *)
316 (* [0x18ED] BCS *-35;18CA *) (compile m ? BCS (maIMM1 〈xD,xB〉) I) @
318 (* /* sovrascrittura di dati per produrre la versione ordinata */
319 for(index=0;index<256;index++)
321 while(counters[index]--)
322 { dati[position++]=index; }
325 (* [0x18EF] TSX *) (compile m ? TSX maINH I) @
326 (* [0x18F0] CLR 1,X *) (compile m ? CLR (maIX1 〈x0,x1〉) I) @
327 (* [0x18F2] CLR ,X *) (compile m ? CLR maIX0 I) @
328 (* [0x18F3] BRA *+16 *) (compile m ? BRA (maIMM1 〈x0,xE〉) I) @
329 (* [0x18F5] TSX *) (compile m ? TSX maINH I) @
330 (* [0x18F6] LDA 1,X *) (compile m ? LDA (maIX1 〈x0,x1〉) I) @
331 (* [0x18F8] LDHX 3,SP *) (compile m ? LDHX (maSP1 〈x0,x3〉) I) @
332 (* [0x18FB] STA 256,X *) (compile m ? STA (maIX2 〈〈x0,x1〉:〈x0,x0〉〉) I) @
333 (* [0x18FE] AIX #1 *) (compile m ? AIX (maIMM1 〈x0,x1〉) I) @
334 (* [0x1900] STHX 3,SP *) (compile m ? STHX (maSP1 〈x0,x3〉) I) @
335 (* [0x1903] TSX *) (compile m ? TSX maINH I) @
336 (* [0x1904] LDX 1,X *) (compile m ? LDX (maIX1 〈x0,x1〉) I) @
337 (* [0x1906] LSLX *) (compile m ? ASL maINHX I) @
338 (* [0x1907] LDA 1,SP *) (compile m ? LDA (maSP1 〈x0,x1〉) I) @
339 (* [0x190A] ROLA *) (compile m ? ROL maINHA I) @
340 (* [0x190B] PSHA *) (compile m ? PSHA maINH I) @
341 (* [0x190C] PULH *) (compile m ? PULH maINH I) @
342 (* [0x190D] PSHX *) (compile m ? PSHX maINH I) @
343 (* [0x190E] LDHX 3328,X *) (compile m ? LDHX (maIX2 〈〈x0,xD〉:〈x0,x0〉〉) I) @
344 (* [0x1912] PSHX *) (compile m ? PSHX maINH I) @
345 (* [0x1913] PSHH *) (compile m ? PSHH maINH I) @
346 (* [0x1914] AIX #-1 *) (compile m ? AIX (maIMM1 〈xF,xF〉) I) @
347 (* [0x1916] PSHH *) (compile m ? PSHH maINH I) @
348 (* [0x1917] PSHA *) (compile m ? PSHA maINH I) @
349 (* [0x1918] PULH *) (compile m ? PULH maINH I) @
350 (* [0x1919] PSHX *) (compile m ? PSHX maINH I) @
351 (* [0x191A] LDX 5,SP *) (compile m ? LDX (maSP1 〈x0,x5〉) I) @
352 (* [0x191D] PULA *) (compile m ? PULA maINH I) @
353 (* [0x191E] STA 3329,X *) (compile m ? STA (maIX2 〈〈x0,xD〉:〈x0,x1〉〉) I) @
354 (* [0x1921] PULA *) (compile m ? PULA maINH I) @
355 (* [0x1922] STA 3328,X *) (compile m ? STA (maIX2 〈〈x0,xD〉:〈x0,x0〉〉) I) @
356 (* [0x1925] PULH *) (compile m ? PULH maINH I) @
357 (* [0x1926] PULX *) (compile m ? PULX maINH I) @
358 (* [0x1927] CPHX #0x0000 *) (compile m ? CPHX (maIMM2 〈〈x0,x0〉:〈x0,x0〉〉) I) @
359 (* [0x192A] PULH *) (compile m ? PULH maINH I) @
360 (* [0x192B] BNE *-54 *) (compile m ? BNE (maIMM1 〈xC,x8〉) I) @
361 (* [0x192D] TSX *) (compile m ? TSX maINH I) @
362 (* [0x192E] INC 1,X *) (compile m ? INC (maIX1 〈x0,x1〉) I) @
363 (* [0x1930] BNE *+3 *) (compile m ? BNE (maIMM1 〈x0,x1〉) I) @
364 (* [0x1932] INC ,X *) (compile m ? INC maIX0 I) @
365 (* [0x1933] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
366 (* [0x1936] CPHX #0x0100 *) (compile m ? CPHX (maIMM2 〈〈x0,x1〉:〈x0,x0〉〉) I) @
367 (* [0x1939] BNE *-54 *) (compile m ? BNE (maIMM1 〈xC,x8〉) I) @
368 (* [0x193B] STOP *) (compile m ? STOP maINH I)
371 attraverso simulazione in CodeWarrior si puo' enunciare che dopo
372 25700+150n si sara' entrati in stato STOP corrispondente con ordinamento
373 di n byte, A=0xFF H:X=0x0100 *)
376 (* creazione del processore+caricamento+impostazione registri *)
377 definition dTest_HCS08_cSort_status ≝
384 setweak_i_flag HCS08 t (* I<-I_op *)
385 (set_acc_8_low_reg HCS08 t (* A<-A_op *)
386 (set_z_flag HCS08 t (* Z<-true *)
387 (setweak_sp_reg HCS08 t (* SP<-0x0F4B *)
388 (setweak_indX_16_reg HCS08 t (* H:X<-HX_op *)
389 (set_pc_reg HCS08 t (* PC<-dTest_HCS08_prog *)
390 (start_of_mcu_version
392 (load_from_source_at t (* carica data in RAM:dTest_HCS08_RAM *)
393 (load_from_source_at t (zero_memory t) (* carica source in ROM:dTest_HCS08_prog *)
394 (dTest_HCS08_cSort_source elems) dTest_HCS08_prog)
395 data dTest_HCS08_RAM)
396 (build_memory_type_of_mcu_version MC9S08GB60 t)
397 (mk_byte8 x0 x0) (mk_byte8 x0 x0) (* non deterministici tutti a 0 *)
398 false false false false false false) (* non deterministici tutti a 0 *)
401 (mk_word16 (mk_byte8 x0 xF) (mk_byte8 x4 xB)))
406 (* parametrizzazione dell'enunciato del teorema parziale *)
407 lemma dTest_HCS08_cSort_aux ≝
408 λt:memory_impl.λstring:list byte8.
409 (* 1) la stringa deve avere una lunghezza ∈ [0,3072] *)
410 (byte8_bounded_strlen string 〈〈x0,xC〉:〈x0,x0〉〉) ∧
411 (* 2) match di esecuzione su tempo in forma di upperbound *)
412 (match execute HCS08 t
413 (* parametri IN: t,A,H:X,strlen(string),string *)
414 (TickOK ? (dTest_HCS08_cSort_status t true 〈x0,x0〉 〈〈x0,xF〉:〈x4,xC〉〉 (byte8_strlen string) string))
415 (* tempo di esecuzione 25700+150*n *)
416 ((nat_of_word16 〈〈x6,x4〉:〈x6,x4〉〉)+(nat_of_byte8 〈x9,x6〉)*(nat_of_word16 (byte8_strlen string))) with
417 [ TickERR s _ ⇒ None ?
418 (* azzeramento tutta RAM tranne dati *)
419 | TickSUSP s _ ⇒ Some ? (set_mem_desc HCS08 t s (load_from_source_at t (get_mem_desc HCS08 t s) dTest_zeros 〈〈x0,xD〉:〈x0,x0〉〉))
422 Some ? (set_pc_reg HCS08 t
423 (dTest_HCS08_cSort_status t false 〈xF,xF〉 〈〈x0,x1〉:〈x0,x0〉〉 (byte8_strlen string) (byte8_list_ordering string))
424 (mk_word16 (mk_byte8 x1 x9) (mk_byte8 x3 xC)))).
426 (* dimostrazione senza svolgimento degli stati *)
428 lemma dTest_HCS08_cSort :
429 dTest_HCS08_cSort_aux MEM_TREE dTest_random_32.
430 unfold dTest_HCS08_cSort_aux;
432 [ normalize in ⊢ (%); autobatch ]
437 definition cSortCalc ≝
439 match execute HCS08 MEM_TREE
440 (TickOK ? (dTest_HCS08_cSort_status MEM_TREE true 〈x0,x0〉 〈〈x0,xF〉:〈x4,xC〉〉 (byte8_strlen string) string))
441 ((nat_of_word16 〈〈x6,x4〉:〈x6,x4〉〉)+(nat_of_byte8 〈x9,x6〉)*(nat_of_word16 (byte8_strlen string))) with
442 [ TickERR s _ ⇒ None ?
443 | TickSUSP s _ ⇒ Some ? (set_mem_desc HCS08 MEM_TREE s (load_from_source_at MEM_TREE (get_mem_desc HCS08 MEM_TREE s) dTest_zeros 〈〈x0,xD〉:〈x0,x0〉〉))
447 definition cSortNoCalc ≝
449 Some ? (set_pc_reg HCS08 MEM_TREE
450 (dTest_HCS08_cSort_status MEM_TREE false 〈xF,xF〉 〈〈x0,x1〉:〈x0,x0〉〉 (byte8_strlen string) (byte8_list_ordering string))
451 (mk_word16 (mk_byte8 x1 x9) (mk_byte8 x3 xC))).
453 definition cSortCalc32 ≝ cSortCalc dTest_random_32.
454 definition cSortCalc64 ≝ cSortCalc dTest_random_64.
455 definition cSortCalc128 ≝ cSortCalc dTest_random_128.
456 definition cSortCalc256 ≝ cSortCalc dTest_random_256.
457 definition cSortCalc512 ≝ cSortCalc dTest_random_512.
458 definition cSortCalc1024 ≝ cSortCalc dTest_random_1024.
459 definition cSortCalc2048 ≝ cSortCalc dTest_random_2048.
460 definition cSortCalc3072 ≝ cSortCalc dTest_random_3072.
462 definition cSortNoCalc32 ≝ cSortNoCalc dTest_random_32.
463 definition cSortNoCalc64 ≝ cSortNoCalc dTest_random_64.
464 definition cSortNoCalc128 ≝ cSortNoCalc dTest_random_128.
465 definition cSortNoCalc256 ≝ cSortNoCalc dTest_random_256.
466 definition cSortNoCalc512 ≝ cSortNoCalc dTest_random_512.
467 definition cSortNoCalc1024 ≝ cSortNoCalc dTest_random_1024.
468 definition cSortNoCalc2048 ≝ cSortNoCalc dTest_random_2048.
469 definition cSortNoCalc3072 ≝ cSortNoCalc dTest_random_3072.
471 (* ********************** *)
472 (* HCS08GB60 numeri aurei *)
473 (* ********************** *)
475 (* versione ridotta, in cui non si riazzerano gli elementi di counters *)
476 definition dTest_HCS08_gNum_source : word16 → (list byte8) ≝
478 let m ≝ HCS08 in source_to_byte8 m (
479 (* BEFORE: A=0x00 HX=0x1A00 PC=0x18BE SP=0x016F Z=1 (I=1) *)
482 static unsigned int result[16]={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
483 word result[16] = 0x0100
485 void goldenNumbers(void)
487 unsigned int res_pos=0,tested_num=0,divisor=0;
488 unsigned long int acc=0;
491 (* [0x18BE] AIS #-10 *) (compile m ? AIS (maIMM1 〈xF,x6〉) I) @
492 (* [0x18C0] TSX *) (compile m ? TSX maINH I) @
493 (* [0x18C1] CLR 9,x *) (compile m ? CLR (maIX1 〈x0,x9〉) I) @
494 (* [0x18C3] CLR 8,X *) (compile m ? CLR (maIX1 〈x0,x8〉) I) @
495 (* [0x18C5] CLR 1,X *) (compile m ? CLR (maIX1 〈x0,x1〉) I) @
496 (* [0x18C7] CLR ,X *) (compile m ? CLR maIX0 I) @
497 (* [0x18C8] CLR 3,X *) (compile m ? CLR (maIX1 〈x0,x3〉) I) @
498 (* [0x18CA] CLR 2,X *) (compile m ? CLR (maIX1 〈x0,x2〉) I) @
499 (* [0x18CC] JSR 0x1951 *) (compile m ? JSR (maIMM2 〈〈x1,x9〉:〈x5,x1〉〉) I) @
502 for(tested_num=1;tested_num<2;tested_num++)
506 (* [0x18CF] STHX 1,SP *) (compile m ? STHX (maSP1 〈x0,x1〉) I) @
507 (* [0x18D2] BRA *+116 ; 0x1946 *) (compile m ? BRA (maIMM1 〈x7,x2〉) I) @
508 (* [0x18D4] BSR *+125 ; 0x1951 *) (compile m ? BSR (maIMM1 〈x7,xB〉) I) @
509 (* [0x18D6] STHX 3,SP *) (compile m ? STHX (maSP1 〈x0,x3〉) I) @
512 for(acc=0,divisor=1;divisor<tested_num;divisor++)
514 if(!(tested_num%divisor))
519 (* [0x18D9] BRA *+61 ; 0x1916 *) (compile m ? BRA (maIMM1 〈x3,xB〉) I) @
520 (* [0x18DB] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
521 (* [0x18DE] PSHX *) (compile m ? PSHX maINH I) @
522 (* [0x18DF] PSHH *) (compile m ? PSHH maINH I) @
523 (* [0x18E0] LDHX 5,SP *) (compile m ? LDHX (maSP1 〈x0,x5〉) I) @
524 (* [0x18E3] JSR 0x1A1A *) (compile m ? JSR (maIMM2 〈〈x1,xA〉:〈x1,xA〉〉) I) @
525 (* [0x18E6] AIS #2 *) (compile m ? AIS (maIMM1 〈x0,x2〉) I) @
526 (* [0x18E8] CPHX #0x0000 *) (compile m ? CPHX (maIMM2 〈〈x0,x0〉:〈x0,x0〉〉) I) @
527 (* [0x18EB] BNE *+33 ; 0x190C *) (compile m ? BNE (maIMM1 〈x1,xF〉) I) @
528 (* [0x18ED] TSX *) (compile m ? TSX maINH I) @
529 (* [0x18EE] LDA 3,X *) (compile m ? LDA (maIX1 〈x0,x3〉) I) @
530 (* [0x18F0] LDX 2,X *) (compile m ? LDX (maIX1 〈x0,x2〉) I) @
531 (* [0x18F2] PSHA *) (compile m ? PSHA maINH I) @
532 (* [0x18F3] PSHX *) (compile m ? PSHX maINH I) @
533 (* [0x18F4] CLRA *) (compile m ? CLR maINHA I) @
534 (* [0x18F5] PSHA *) (compile m ? PSHA maINH I) @
535 (* [0x18F6] PSHA *) (compile m ? PSHA maINH I) @
536 (* [0x18F7] TSX *) (compile m ? TSX maINH I) @
537 (* [0x18F8] PSHX *) (compile m ? PSHX maINH I) @
538 (* [0x19F9] PSHH *) (compile m ? PSHH maINH I) @
539 (* [0x18FA] AIX #8 *) (compile m ? AIX (maIMM1 〈x0,x8〉) I) @
540 (* [0x18FC] PSHX *) (compile m ? PSHX maINH I) @
541 (* [0x18FD] PSHH *) (compile m ? PSHH maINH I) @
542 (* [0x18FE] LDHX 3,SP *) (compile m ? LDHX (maSP1 〈x0,x3〉) I) @
543 (* [0x1901] JSR 0x1A2A *) (compile m ? JSR (maIMM2 〈〈x1,xA〉:〈x2,xA〉〉) I) @
544 (* [0x1904] TSX *) (compile m ? TSX maINH I) @
545 (* [0x1905] AIX #14 *) (compile m ? AIX (maIMM1 〈x0,xE〉) I) @
546 (* [0x1907] JSR 0x1A30 *) (compile m ? JSR (maIMM2 〈〈x1,xA〉:〈x3,x0〉〉) I) @
547 (* [0x190A] AIS #6 *) (compile m ? AIS (maIMM1 〈x0,x6〉) I) @
548 (* [0x190C] STA 0x1800 !COP! *) (compile m ? STA (maDIR2 〈〈x0,xC〉:〈x0,x0〉〉) I) @
549 (* [0x190F] TSX *) (compile m ? TSX maINH I) @
550 (* [0x1910] INC 3,X *) (compile m ? INC (maIX1 〈x0,x3〉) I) @
551 (* [0x1912] BNE *+4 ; 0x1916 *) (compile m ? BNE (maIMM1 〈x0,x2〉) I) @
552 (* [0x1914] INC 2,X *) (compile m ? INC (maIX1 〈x0,x2〉) I) @
553 (* [0x1916] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
554 (* [0x1919] CPHX 3,SP *) (compile m ? CPHX (maSP1 〈x0,x3〉) I) @
555 (* [0x191C] BHI *-65 ; 0x18DB *) (compile m ? BHI (maIMM1 〈xB,xD〉) I) @
559 { result[res_pos++]=tested_num; }
564 (* [0x191E] CPHX 7,SP *) (compile m ? CPHX (maSP1 〈x0,x7〉) I) @
565 (* [0x1921] BNE *+31 ; 0x1940 *) (compile m ? BNE (maIMM1 〈x1,xD〉) I) @
566 (* [0x1923] LDHX 5,SP *) (compile m ? LDHX (maSP1 〈x0,x5〉) I) @
567 (* [0x1926] BNE *+26 ; 0x1940 *) (compile m ? BNE (maIMM1 〈x1,x8〉) I) @
568 (* [0x1928] LDHX 9,SP *) (compile m ? LDHX (maSP1 〈x0,x9〉) I) @
569 (* [0x192B] PSHX *) (compile m ? PSHX maINH I) @
570 (* [0x192C] AIX #1 *) (compile m ? AIX (maIMM1 〈x0,x1〉) I) @
571 (* [0x192E] STHX 10,SP *) (compile m ? STHX (maSP1 〈x0,xA〉) I) @
572 (* [0x1931] PULX *) (compile m ? PULX maINH I) @
573 (* [0x1932] LSLX *) (compile m ? ASL maINHX I) @
574 (* [0x1933] LDA 2,SP *) (compile m ? LDA (maSP1 〈x0,x2〉) I) @
575 (* [0x1936] CLRH *) (compile m ? CLR maINHH I) @
576 (* [0x1937] STA 257,X *) (compile m ? STA (maIX2 〈〈x0,x1〉:〈x0,x1〉〉) I) @
577 (* [0x193A] LDA 1,SP *) (compile m ? LDA (maSP1 〈x0,x1〉) I) @
578 (* [0x193D] STA 256,X *) (compile m ? STA (maIX2 〈〈x0,x1〉:〈x0,x0〉〉) I) @
579 (* [0x1940] TSX *) (compile m ? TSX maINH I) @
580 (* [0x1941] INC 1,X *) (compile m ? INC (maIX1 〈x0,x1〉) I) @
581 (* [0x1943] BNE *+3 ; 0x1946 *) (compile m ? BNE (maIMM1 〈x0,x1〉) I) @
582 (* [0x1945] INC ,X *) (compile m ? INC maIX0 I) @
583 (* [0x1946] LDHX 1,SP *) (compile m ? LDHX (maSP1 〈x0,x1〉) I) @
584 (* [0x1949] CPHX #elems *) (compile m ? CPHX (maIMM2 elems) I) @
585 (* [0x194C] BCS *-120 ; 0x18D4 *) (compile m ? BCS (maIMM1 〈x8,x6〉) I) @
586 (* [0x194E] AIS #10 *) (compile m ? AIS (maIMM1 〈x0,xA〉) I) @
587 (* [0x1950] STOP ->1951 !FINE! *) (compile m ? STOP maINH I) @
588 (* [0x1951] CLRX *) (compile m ? CLR maINHX I) @
589 (* [0x1952] CLRH *) (compile m ? CLR maINHH I) @
590 (* [0x1953] STHX 9,SP *) (compile m ? STHX (maSP1 〈x0,x9〉) I) @
591 (* [0x1956] CLRH *) (compile m ? CLR maINHH I) @
592 (* [0x1957] STHX 7,SP *) (compile m ? STHX (maSP1 〈x0,x7〉) I) @
593 (* [0x195A] INCX *) (compile m ? INC maINHX I) @
594 (* [0x195B] RTS *) (compile m ? RTS maINH I) @
597 static void _PUSH_ARGS_L(void) { ... }
600 (* [0x195C] LDA 3,X *) (compile m ? LDA (maIX1 〈x0,x3〉) I) @
601 (* [0x195E] PSHA *) (compile m ? PSHA maINH I) @
602 (* [0x195F] LDA 2,X *) (compile m ? LDA (maIX1 〈x0,x2〉) I) @
603 (* [0x1961] PSHA *) (compile m ? PSHA maINH I) @
604 (* [0x1962] LDHX ,X *) (compile m ? LDHX maIX0 I) @
605 (* [0x1964] PSHX *) (compile m ? PSHX maINH I) @
606 (* [0x1965] PSHH *) (compile m ? PSHH maINH I) @
607 (* [0x1966] LDHX 7,SP *) (compile m ? LDHX (maSP1 〈x0,x7〉) I) @
608 (* [0x1969] LDA 3,X *) (compile m ? LDA (maIX1 〈x0,x3〉) I) @
609 (* [0x196B] STA 17,SP *) (compile m ? STA (maSP1 〈x1,x1〉) I) @
610 (* [0x196E] LDA 2,X *) (compile m ? LDA (maIX1 〈x0,x2〉) I) @
611 (* [0x1970] STA 16,SP *) (compile m ? STA (maSP1 〈x1,x0〉) I) @
612 (* [0x1973] LDHX ,X *) (compile m ? LDHX maIX0 I) @
613 (* [0x1975] STHX 14,SP *) (compile m ? STHX (maSP1 〈x0,xE〉) I) @
614 (* [0x1978] LDHX 5,SP *) (compile m ? LDHX (maSP1 〈x0,x5〉) I) @
615 (* [0x197B] JMP ,X *) (compile m ? JMP maINHX0ADD I) @
618 static void _ENTER_BINARY_L(void) { ... }
621 (* [0x197C] PSHA *) (compile m ? PSHA maINH I) @
622 (* [0x197D] PSHX *) (compile m ? PSHX maINH I) @
623 (* [0x197E] PSHH *) (compile m ? PSHH maINH I) @
624 (* [0x197F] PSHX *) (compile m ? PSHX maINH I) @
625 (* [0x1980] PSHH *) (compile m ? PSHH maINH I) @
626 (* [0x1981] LDHX 6,SP *) (compile m ? LDHX (maSP1 〈x0,x6〉) I) @
627 (* [0x1984] PSHX *) (compile m ? PSHX maINH I) @
628 (* [0x1985] PSHH *) (compile m ? PSHH maINH I) @
629 (* [0x1986] LDHX 10,SP *) (compile m ? LDHX (maSP1 〈x0,xA〉) I) @
630 (* [0x1989] STHX 8,SP *) (compile m ? STHX (maSP1 〈x0,x8〉) I) @
631 (* [0x198C] LDHX 12,SP *) (compile m ? LDHX (maSP1 〈x0,xC〉) I) @
632 (* [0x198F] JMP 0x195C *) (compile m ? JMP (maIMM2 〈〈x1,x9〉:〈x5,xC〉〉) I) @
635 static void _IDIVMOD (char dummy_sgn, int j, int dummy, int i, ...) { ... }
638 (* [0x1992] TST 4,SP *) (compile m ? TST (maSP1 〈x0,x4〉) I) @
639 (* [0x1995] BNE *+28 ; 0x19B1 *) (compile m ? BNE (maIMM1 〈x1,xA〉) I) @
640 (* [0x1997] TSX *) (compile m ? TSX maINH I) @
641 (* [0x1998] LDA 7,X *) (compile m ? LDA (maIX1 〈x0,x7〉) I) @
642 (* [0x199A] LDX 4,X *) (compile m ? LDX (maIX1 〈x0,x4〉) I) @
643 (* [0x199C] CLRH *) (compile m ? CLR maINHH I) @
644 (* [0x199D] DIV *) (compile m ? DIV maINH I) @
645 (* [0x199E] STA 4,SP *) (compile m ? STA (maSP1 〈x0,x4〉) I) @
646 (* [0x19A1] LDA 9,SP *) (compile m ? LDA (maSP1 〈x0,x9〉) I) @
647 (* [0x19A4] DIV *) (compile m ? DIV maINH I) @
648 (* [0x19A5] STA 5,SP *) (compile m ? STA (maSP1 〈x0,x5〉) I) @
649 (* [0x19A8] CLR 8,SP *) (compile m ? CLR (maSP1 〈x0,x8〉) I) @
650 (* [0x19AB] PSHH *) (compile m ? PSHH maINH I) @
651 (* [0x19AC] PULA *) (compile m ? PULA maINH I) @
652 (* [0x19AD] STA 9,SP *) (compile m ? STA (maSP1 〈x0,x9〉) I) @
653 (* [0x19B0] RTS *) (compile m ? RTS maINH I) @
654 (* [0x19B1] CLRA *) (compile m ? CLR maINHA I) @
655 (* [0x19B2] PSHA *) (compile m ? PSHA maINH I) @
656 (* [0x19B3] LDX #0x08 *) (compile m ? LDX (maIMM1 〈x0,x8〉) I) @
657 (* [0x19B5] CLC *) (compile m ? CLC maINH I) @
658 (* [0x19B6] ROL 10,SP *) (compile m ? ROL (maSP1 〈x0,xA〉) I) @
659 (* [0x19B9] ROL 9,SP *) (compile m ? ROL (maSP1 〈x0,x9〉) I) @
660 (* [0x19BC] ROL 1,SP *) (compile m ? ROL (maSP1 〈x0,x1〉) I) @
661 (* [0x19BF] LDA 5,SP *) (compile m ? LDA (maSP1 〈x0,x5〉) I) @
662 (* [0x19C2] CMP 1,SP *) (compile m ? CMP (maSP1 〈x0,x1〉) I) @
663 (* [0x19C5] BHI *+31 ; 0x19E4 *) (compile m ? BHI (maIMM1 〈x1,xD〉) I) @
664 (* [0x19C7] BNE *+10 ; 0x19D1 *) (compile m ? BNE (maIMM1 〈x0,x8〉) I) @
665 (* [0x19C9] LDA 6,SP *) (compile m ? LDA (maSP1 〈x0,x6〉) I) @
666 (* [0x19CC] CMP 9,SP *) (compile m ? CMP (maSP1 〈x0,x9〉) I) @
667 (* [0x19CF] BHI *+21 ; 0x19E4 *) (compile m ? BHI (maIMM1 〈x1,x3〉) I) @
668 (* [0x19D1] LDA 9,SP *) (compile m ? LDA (maSP1 〈x0,x9〉) I) @
669 (* [0x19D4] SUB 6,SP *) (compile m ? SUB (maSP1 〈x0,x6〉) I) @
670 (* [0x19D7] STA 9,SP *) (compile m ? STA (maSP1 〈x0,x9〉) I) @
671 (* [0x19DA] LDA 1,SP *) (compile m ? LDA (maSP1 〈x0,x1〉) I) @
672 (* [0x19DD] SBC 5,SP *) (compile m ? SBC (maSP1 〈x0,x5〉) I) @
673 (* [0x19E0] STA 1,SP *) (compile m ? STA (maSP1 〈x0,x1〉) I) @
674 (* [0x19E3] SEC *) (compile m ? SEC maINH I) @
675 (* [0x19E4] DBNZX *-46 ; 0x19B6 *) (compile m ? DBNZ (maINHX_and_IMM1 〈xD,x0〉) I) @
676 (* [0x19E6] LDA 10,SP *) (compile m ? LDA (maSP1 〈x0,xA〉) I) @
677 (* [0x19E9] ROLA *) (compile m ? ROL maINHA I) @
678 (* [0x19EA] STA 6,SP *) (compile m ? STA (maSP1 〈x0,x6〉) I) @
679 (* [0x19ED] LDA 9,SP *) (compile m ? LDA (maSP1 〈x0,x9〉) I) @
680 (* [0x19F0] STA 10,SP *) (compile m ? STA (maSP1 〈x0,xA〉) I) @
681 (* [0x19F3] PULA *) (compile m ? PULA maINH I) @
682 (* [0x19F4] STA 8,SP *) (compile m ? STA (maSP1 〈x0,x8〉) I) @
683 (* [0x19F7] CLR 4,SP *) (compile m ? CLR (maSP1 〈x0,x4〉) I) @
684 (* [0x19FA] RTS *) (compile m ? RTS maINH I) @
687 static void _LADD_k_is_k_plus_j(_PARAM_BINARY_L) { ... }
690 (* [0x19FB] TSX *) (compile m ? TSX maINH I) @
691 (* [0x19FC] LDA 18,X *) (compile m ? LDA (maIX1 〈x1,x2〉) I) @
692 (* [0x19FE] ADD 5,X *) (compile m ? ADD (maIX1 〈x0,x5〉) I) @
693 (* [0x1A00] STA 18,X *) (compile m ? STA (maIX1 〈x1,x2〉) I) @
694 (* [0x1A02] LDA 17,X *) (compile m ? LDA (maIX1 〈x1,x1〉) I) @
695 (* [0x1A04] ADC 4,X *) (compile m ? ADC (maIX1 〈x0,x4〉) I) @
696 (* [0x1A06] STA 17,X *) (compile m ? STA (maIX1 〈x1,x1〉) I) @
697 (* [0x1A08] LDA 16,X *) (compile m ? LDA (maIX1 〈x1,x0〉) I) @
698 (* [0x1A0A] ADC 3,X *) (compile m ? ADC (maIX1 〈x0,x3〉) I) @
699 (* [0x1A0C] STA 16,X *) (compile m ? STA (maIX1 〈x1,x0〉) I) @
700 (* [0x1A0E] LDA 15,X *) (compile m ? LDA (maIX1 〈x0,xF〉) I) @
701 (* [0x1A10] ADC 2,X *) (compile m ? ADC (maIX1 〈x0,x2〉) I) @
702 (* [0x1A12] STA 15,X *) (compile m ? STA (maIX1 〈x0,xF〉) I) @
703 (* [0x1A14] AIS #10 *) (compile m ? AIS (maIMM1 〈x0,xA〉) I) @
704 (* [0x1A16] PULH *) (compile m ? PULH maINH I) @
705 (* [0x1A17] PULX *) (compile m ? PULX maINH I) @
706 (* [0x1A18] PULA *) (compile m ? PULA maINH I) @
707 (* [0x1A19] RTS *) (compile m ? RTS maINH I) @
710 void _IMODU_STAR08(int i, ...) { ... }
713 (* [0x1A1A] AIS #-2 *) (compile m ? AIS (maIMM1 〈xF,xE〉) I) @
714 (* [0x1A1C] STHX 1,SP *) (compile m ? STHX (maSP1 〈x0,x1〉) I) @
715 (* [0x1A1F] PSHA *) (compile m ? PSHA maINH I) @
716 (* [0x1A20] JSR 0x1992 *) (compile m ? JSR (maIMM2 〈〈x1,x9〉:〈x9,x2〉〉) I) @
717 (* [0x1A23] PULA *) (compile m ? PULA maINH I) @
718 (* [0x1A24] AIS #2 *) (compile m ? AIS (maIMM1 〈x0,x2〉) I) @
719 (* [0x1A26] LDHX 3,SP *) (compile m ? LDHX (maSP1 〈x0,x3〉) I) @
720 (* [0x1A29] RTS *) (compile m ? RTS maINH I) @
723 void _LADD(void) { ... }
726 (* [0x1A2A] JSR 0x197C *) (compile m ? JSR (maIMM2 〈〈x1,x9〉:〈x7,xC〉〉) I) @
727 (* [0x1A2D] JSR 0x19FB *) (compile m ? JSR (maIMM2 〈〈x1,x9〉:〈xF,xB〉〉) I) @
730 void _POP32(void) { ... }
733 (* [0x1A30] PSHA *) (compile m ? PSHA maINH I) @
734 (* [0x1A31] LDA 4,SP *) (compile m ? LDA (maSP1 〈x0,x4〉) I) @
735 (* [0x1A34] STA ,X *) (compile m ? STA maIX0 I) @
736 (* [0x1A35] LDA 5,SP *) (compile m ? LDA (maSP1 〈x0,x5〉) I) @
737 (* [0x1A38] STA 1,X *) (compile m ? STA (maIX1 〈x0,x1〉) I) @
738 (* [0x1A3A] LDA 6,SP *) (compile m ? LDA (maSP1 〈x0,x6〉) I) @
739 (* [0x1A3D] STA 2,X *) (compile m ? STA (maIX1 〈x0,x2〉) I) @
740 (* [0x1A3F] LDA 7,SP *) (compile m ? LDA (maSP1 〈x0,x7〉) I) @
741 (* [0x1A42] STA 3,X *) (compile m ? STA (maIX1 〈x0,x3〉) I) @
742 (* [0x1A44] PULA *) (compile m ? PULA maINH I) @
743 (* [0x1A45] PULH *) (compile m ? PULH maINH I) @
744 (* [0x1A46] PULX *) (compile m ? PULX maINH I) @
745 (* [0x1A47] AIS #4 *) (compile m ? AIS (maIMM1 〈x0,x4〉) I) @
746 (* [0x1A49] JMP ,X *) (compile m ? JMP maINHX0ADD I)
748 (* attraverso simulazione in CodeWarrior si puo' enunciare che dopo
749 80+(65*n*(n+1)*(n+2))/6 si sara' entrati in stato STOP corrispondente
750 AFTER: HX=num PC=0x1951 I=0 *)
753 (* creazione del processore+caricamento+impostazione registri *)
754 definition dTest_HCS08_gNum_status ≝
763 setweak_i_flag HCS08 t (* I<-I_op *)
764 (set_acc_8_low_reg HCS08 t (* A<-A_op *)
765 (set_z_flag HCS08 t (* Z<-true *)
766 (setweak_sp_reg HCS08 t (* SP<-0x016F *)
767 (setweak_indX_16_reg HCS08 t (* H:X<-HX_op *)
768 (set_pc_reg HCS08 t (* PC<-PC_op *)
769 (start_of_mcu_version
771 (load_from_source_at t (* carica data in RAM:dTest_HCS08_RAM *)
772 (load_from_source_at t (zero_memory t) (* carica source in ROM:addr *)
773 (dTest_HCS08_cSort_source elems) addr)
774 data dTest_HCS08_RAM)
775 (build_memory_type_of_mcu_version MC9S08GB60 t)
776 (mk_byte8 x0 x0) (mk_byte8 x0 x0) (* non deterministici tutti a 0 *)
777 false false false false false false) (* non deterministici tutti a 0 *)
780 (mk_word16 (mk_byte8 x0 x1) (mk_byte8 x6 xF)))
785 (* NUMERI AUREI: Somma divisori(x)=x, fino a 0xFFFF sono 6/28/496/8128 *)
786 definition dTest_HCS08_gNum_aurei ≝
787 λnum:word16.match gt_w16 num 〈〈x1,xF〉:〈xC,x0〉〉 with
788 [ true ⇒ [ 〈x0,x0〉 ; 〈x0,x6〉 ; 〈x0,x0〉 ; 〈x1,xC〉 ; 〈x0,x1〉 ; 〈xF,x0〉 ; 〈x1,xF〉 ; 〈xC,x0〉 ]
789 | false ⇒ match gt_w16 num 〈〈x0,x1〉:〈xF,x0〉〉 with
790 [ true ⇒ [ 〈x0,x0〉 ; 〈x0,x6〉 ; 〈x0,x0〉 ; 〈x1,xC〉 ; 〈x0,x1〉 ; 〈xF,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ]
791 | false ⇒ match gt_w16 num 〈〈x0,x0〉:〈x1,xC〉〉 with
792 [ true ⇒ [ 〈x0,x0〉 ; 〈x0,x6〉 ; 〈x0,x0〉 ; 〈x1,xC〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ]
793 | false ⇒ match gt_w16 num 〈〈x0,x0〉:〈x0,x6〉〉 with
794 [ true ⇒ [ 〈x0,x0〉 ; 〈x0,x6〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ]
795 | false ⇒ [ 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ]
799 ] @ [ 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉
800 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉
801 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ; 〈x0,x0〉 ].
803 (* esecuzione execute k*(n+2) *)
804 let rec dTest_HCS08_gNum_execute1 (m:mcu_type) (t:memory_impl) (s:tick_result (any_status m t)) (n,ntot:nat) on n ≝
806 [ TickERR s' error ⇒ TickERR ? s' error
807 | TickSUSP s' susp ⇒ TickSUSP ? s' susp
808 | TickOK s' ⇒ match n with
810 | S n' ⇒ dTest_HCS08_gNum_execute1 m t (execute m t (TickOK ? s') (ntot+2)) n' ntot ]
813 (* esecuzione execute k*(n+1)*(n+2) *)
814 let rec dTest_HCS08_gNum_execute2 (m:mcu_type) (t:memory_impl) (s:tick_result (any_status m t)) (n,ntot:nat) on n ≝
816 [ TickERR s' error ⇒ TickERR ? s' error
817 | TickSUSP s' susp ⇒ TickSUSP ? s' susp
818 | TickOK s' ⇒ match n with
820 | S n' ⇒ dTest_HCS08_gNum_execute2 m t (dTest_HCS08_gNum_execute1 m t (TickOK ? s') (ntot+1) ntot) n' ntot ]
823 (* esecuzione execute k*n*(n+1)*(n+2) *)
824 let rec dTest_HCS08_gNum_execute3 (m:mcu_type) (t:memory_impl) (s:tick_result (any_status m t)) (n,ntot:nat) on n ≝
826 [ TickERR s' error ⇒ TickERR ? s' error
827 | TickSUSP s' susp ⇒ TickSUSP ? s' susp
828 | TickOK s' ⇒ match n with
830 | S n' ⇒ dTest_HCS08_gNum_execute3 m t (dTest_HCS08_gNum_execute2 m t (TickOK ? s') ntot ntot) n' ntot ]
833 (* esecuzione execute 80+11*n*(n+1)*(n+2) *)
834 definition dTest_HCS08_gNum_execute4 ≝
835 λm:mcu_type.λt:memory_impl.λs:tick_result (any_status m t).λntot:nat.
837 [ TickERR s' error ⇒ TickERR ? s' error
838 | TickSUSP s' susp ⇒ TickSUSP ? s' susp
839 | TickOK s' ⇒ execute m t (dTest_HCS08_gNum_execute3 m t (TickOK ? s') 11 ntot) 80
842 (* parametrizzazione dell'enunciato del teorema parziale *)
843 lemma dTest_HCS08_gNum_aux ≝
844 λt:memory_impl.λnum:word16.
845 (* 2) match di esecuzione su tempo in forma di upperbound *)
846 match dTest_HCS08_gNum_execute4 HCS08 t
847 (TickOK ? (dTest_HCS08_gNum_status t true 〈x0,x0〉 〈〈x1,xA〉:〈x0,x0〉〉 〈〈x1,x8〉:〈xB,xE〉〉 〈〈x1,x8〉:〈xB,xE〉〉 num dTest_zeros))
848 (* tempo di esecuzione 80+11*n*(n+1)*(n+2) *)
850 [ TickERR s _ ⇒ None ?
851 (* azzeramento tutta RAM tranne dati *)
852 | TickSUSP s _ ⇒ Some ? (set_mem_desc HCS08 t s (load_from_source_at t (get_mem_desc HCS08 t s) dTest_zeros3K 〈〈x0,x1〉:〈x2,x0〉〉))
855 Some ? (dTest_HCS08_gNum_status t false 〈x0,x0〉 num 〈〈x1,x9〉:〈x5,x1〉〉 〈〈x1,x8〉:〈xB,xE〉〉 num (dTest_HCS08_gNum_aurei num)).
857 definition gNumCalc ≝
859 match dTest_HCS08_gNum_execute4 HCS08 MEM_TREE
860 (TickOK ? (dTest_HCS08_gNum_status MEM_TREE true 〈x0,x0〉 〈〈x1,xA〉:〈x0,x0〉〉 〈〈x1,x8〉:〈xB,xE〉〉 〈〈x1,x8〉:〈xB,xE〉〉 num dTest_zeros))
862 [ TickERR s _ ⇒ None ?
863 | TickSUSP s _ ⇒ Some ? (set_mem_desc HCS08 MEM_TREE s (load_from_source_at MEM_TREE (get_mem_desc HCS08 MEM_TREE s) dTest_zeros3K 〈〈x0,x1〉:〈x2,x0〉〉))
867 definition gNumNoCalc ≝
869 Some ? (dTest_HCS08_gNum_status MEM_TREE false 〈x0,x0〉 num 〈〈x1,x9〉:〈x5,x1〉〉 〈〈x1,x8〉:〈xB,xE〉〉 num (dTest_HCS08_gNum_aurei num)).
871 definition gNumCalc1 ≝ gNumCalc 〈〈x0,x0〉:〈x0,x1〉〉.
872 definition gNumCalc2 ≝ gNumCalc 〈〈x0,x0〉:〈x0,x2〉〉.
873 definition gNumCalc5 ≝ gNumCalc 〈〈x0,x0〉:〈x0,x5〉〉.
874 definition gNumCalc10 ≝ gNumCalc 〈〈x0,x0〉:〈x0,xA〉〉.
875 definition gNumCalc20 ≝ gNumCalc 〈〈x0,x0〉:〈x1,x4〉〉.
876 definition gNumCalc50 ≝ gNumCalc 〈〈x0,x0〉:〈x3,x2〉〉.
877 definition gNumCalc100 ≝ gNumCalc 〈〈x0,x0〉:〈x6,x4〉〉.
878 definition gNumCalc250 ≝ gNumCalc 〈〈x0,x0〉:〈xF,xA〉〉.
879 definition gNumCalc500 ≝ gNumCalc 〈〈x0,x1〉:〈xF,x4〉〉.
880 definition gNumCalc1000 ≝ gNumCalc 〈〈x0,x3〉:〈xE,x8〉〉.
882 definition gNumNoCalc1 ≝ gNumNoCalc 〈〈x0,x0〉:〈x0,x1〉〉.
883 definition gNumNoCalc2 ≝ gNumNoCalc 〈〈x0,x0〉:〈x0,x2〉〉.
884 definition gNumNoCalc5 ≝ gNumNoCalc 〈〈x0,x0〉:〈x0,x5〉〉.
885 definition gNumNoCalc10 ≝ gNumNoCalc 〈〈x0,x0〉:〈x0,xA〉〉.
886 definition gNumNoCalc20 ≝ gNumNoCalc 〈〈x0,x0〉:〈x1,x4〉〉.
887 definition gNumNoCalc50 ≝ gNumNoCalc 〈〈x0,x0〉:〈x3,x2〉〉.
888 definition gNumNoCalc100 ≝ gNumNoCalc 〈〈x0,x0〉:〈x6,x4〉〉.
889 definition gNumNoCalc250 ≝ gNumNoCalc 〈〈x0,x0〉:〈xF,xA〉〉.
890 definition gNumNoCalc500 ≝ gNumNoCalc 〈〈x0,x1〉:〈xF,x4〉〉.
891 definition gNumNoCalc1000 ≝ gNumNoCalc 〈〈x0,x3〉:〈xE,x8〉〉.