現在アセンブリ言語を勉強中です。2 つの数値を最小から最大に交換する簡単な短い関数を作成できました。3 つの数値でこれを行うために同じ基本的な基盤を適用していますが、比較を実行するたびに無限ループに入ります。を使用してこの関数を宣言してい*60
ます。3 つの数値を最小から最大に正しく並べ替えるにはどうすればよいですか? また、追加の変更を加えずに、同じ関数で 2 と 3 の数字の並べ替えを実行する方法はありますか?
いくつかのアセンブリ プログラムでは、構文がわずかに変更されています。HEREは、私が現在使用している教育アセンブリーのリトルマン コンピューター シミュレーターのリンクです。
2 つの数値を使用したワーキング スワップ:
INP //Input x number
STO 99 //Store x number
INP //Input y number
STO 98 //Store y number
BR 60 //Jump to function *60
HLT //End run
*60 //Number SWAP function
LDA 99 //Load x
STO 87 //Move x to mailbox 87
LDA 98 //Load y
STO 86 //Move y to mailbox 86
SUB 87 //Subtract y - x
BRP 71 //Branch to line 71 if result is positive
LDA 86 //SUB 87 gives a negative result- then y is smallest number. Load y
OUT //Display y
LDA 87 //Load x- the greater number.
OUT //Display x
HLT //End here since y > x
LDA 87 //BRP 71 branches here- then x is smallest number
OUT //Display x
LDA 86 //y is the greater number
OUT * //display y