2つの数の比較
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/08/16 13:57 UTC 版)
単に2つの数を比較するだけでどれだけのコードが必要となるかを示したコード断片。 /Compare numbers in memory at OPD1 and OPD2 CLA CLL /Must start with 0 in AC and link TAD OPD1 /Load first operand into AC (by adding it to 0); link is still clear CIA /Complement, then increment AC, negating it TAD OPD2 /AC now has OPD2-OPD1; if OPD2≥OPD1, sum overflows and link is set SZL /Skip if link is clear JMP OP2GT /Jump somewhere in the case that OPD2≥OPD1; /Otherwise, fall through to code below. 見ての通り、PDP-8の典型的なプログラムは作者が意図したアルゴリズムよりも低レベルな機構に集中する傾向がある。また、可読性を損なうもう1つの問題として、条件分岐部分のコーディングがある。上の例で判るとおり条件判断命令(JMP命令をスキップしている命令)は、注目している条件とは反対の条件判断をしなければならない。
※この「2つの数の比較」の解説は、「PDP-8」の解説の一部です。
「2つの数の比較」を含む「PDP-8」の記事については、「PDP-8」の概要を参照ください。
- 2つの数の比較のページへのリンク