60 likes | 359 Views
10. 計算: Σ i. i=0. move #0, GR0 //i move GR0, $i move #0, GR1 //S move GR1, $S L1: move $i, GR0 sub #10, GR0 jpgt L2 move $S, GR1 move $i, GR0 add GR0, GR1 move GR1, $S add #1, GR0 move GR0, $i jump L1 L2: halt // i: ds.1 S: ds.1 //end of program. 漸化式表現:
E N D
10 計算:Σ i i=0 move #0, GR0 //i move GR0, $i move #0, GR1 //S move GR1, $S L1: move $i, GR0 sub #10, GR0 jpgt L2 move $S, GR1 move $i, GR0 add GR0, GR1 move GR1, $S add #1, GR0 move GR0, $i jump L1 L2: halt // i: ds.1 S: ds.1 //end of program 漸化式表現: S(0)=0 S(i)=S(i-1) +i i=0,..,10 変数を簡略: S=0 S=S+i i=0,..,10
メモリ領域の番号 0: move #0, GR0 1: move GR0, $i 2: move #0, GR1 3: move GR1, $S //L1: 4: move $i, GR0 5: sub #10, GR0 6: jpgt L2 7: move $S, GR1 8: move $i, GR0 9: add GR0, GR1 10: move GR1, $S 11: add #1, GR0 12: move GR0, $i 13: jump L1 //L2: 14: halt // //i: 20: ds.1 //S: 21: ds.1 //end of program move #0, GR0 //i move GR0, $i move #0, GR1 //S move GR1, $S L1: move $i, GR0 sub #10, GR0 jpgt L2 move $S, GR1 move $i, GR0 add GR0, GR1 move GR1, $S add #1, GR0 move GR0, $i jump L1 L2: halt // i: ds.1 S: ds.1 //end of program
0: move #0, GR0 1: move GR0, $i 2: move #0, GR1 3: move GR1, $S //L1: 4: move $i, GR0 5: sub #10, GR0 6: jpgt L2 7: move $S, GR1 8: move $i, GR0 9: add GR0, GR1 10: move GR1, $S 11: add #1, GR0 12: move GR0, $i 13: jump L1 //L2: 14: halt // //i: 20: ds.1 //S: 21: ds.1 //end of program 0: move #0, GR0 1: move GR0, 20 //$i 2: move #0, GR1 3: move GR1, 21 //$S //L1: 4: move 20, GR0 //$i, GR0 5: sub #10, GR0 6: jpgt 14 //L2 7: move 21, GR1 //$S, GR1 8: move 20, GR0 //$i, GR0 9: add GR0, GR1 10: move GR1, 21 //$S 11: add #1, GR0 12: move GR0, 20 //$i 13: jump 4 //L1 //L2: 14: halt // //i: 20: ds.1 //S: 21: ds.1 //end of program address resolution L1 -> 4 L2 -> 14 i -> 20 S -> 21
move #0, GR0 //i move GR0, $i move #0, GR1 //S move GR1, $S L1: move $i, GR0 sub #10, GR0 jpgt L2 move $S, GR1 move $i, GR0 add $A(GR0), GR1 move GR1, $S add #1, GR0 move GR0, $i jump L1 L2: halt // i: ds.1 S: ds.1 A: ここからデータが並ぶ 10 計算:Σa(i) i=0 配列 漸化式表現: S(0)=0 S(i)=S(i-1) +a(i) i=0,..,10 違いはここだけ! 変数を簡略: S=0 S=S+a(i) i=0,..,10
move #0, GR0 //i move GR0, $i move #0, GR1 //S move GR1, $S L1: move $i, GR0 sub #10, GR0 jpgt L2 move $S, GR1 move $i, GR0 add $A(GR0), GR1 move GR1, $S add #1, GR0 move GR0, $i jump L1 L2: halt // i: ds.1 S: ds.1 A: ここからデータが並ぶ メモリ領域の番号 配列 0: move #0, GR0 1: move GR0, $i 2: move #0, GR1 3: move GR1, $S //L1: 4: move $i, GR0 5: sub #10, GR0 6: jpgt L2 7: move $S, GR1 8: move $i, GR0 9: add $A(GR0), GR1 10: move GR1, $S 11: add #1, GR0 12: move GR0, $i 13: jump L1 //L2: 14: halt //i: 20: ds.1 //S: 21: ds.1 //A: 22: ここからデータが並ぶ
メモリ領域の番号 0: move #0, GR0 1: move GR0, $i 2: move #0, GR1 3: move GR1, $S //L1: 4: move $i, GR0 5: sub #10, GR0 6: jpgt L2 7: move $S, GR1 8: move $i, GR0 9: add $A(GR0), GR1 10: move GR1, $S 11: add #1, GR0 12: move GR0, $i 13: jump L1 //L2: 14: halt //i: 20: ds.1 //S: 21: ds.1 //A: 22: ここからデータが並ぶ 0: move #0, GR0 1: move GR0, 20 //$i 2: move #0, GR1 3: move GR1, 21 //$S //L1: 4: move 20, GR0 //$i, GR0 5: sub #10, GR0 6: jpgt 14 //L2 7: move 21, GR1 //$S, GR1 8: move 20, GR0 //$i, GR0 9: add 22(GR0), GR1 //Si(GR0) 10: move GR1, 21 //$S 11: add #1, GR0 12: move GR0, 20 //$i 13: jump 4 //L1 //L2: 14: halt //i: 20: ds.1 //S: 21: ds.1 //A: 22: ここからデータが並ぶ インデックスレジスタ修飾アドレス方式 address resolution L1 -> 4 L2 -> 14 i -> 20 S -> 21 A -> 22