数字の合計を見つけるためのアセンブラコードを作成するプロジェクトがあります。アセンブラコード。ループと加算のみを使用して乗算なしの平方和を計算する。無限ループ。 ASCII/16進数
は、以下の操作を実行するためのアセンブリ言語プログラムを書く:入力の正の整数Nは、常にユーザー入力N.
= 1 + 4 + 9 +⋯+
に等しい整数の和であろう計算2桁の数字(01〜10)でなければなりません。入力の正確性をチェックする必要はありません。たとえば、ユーザー入力が「10」の場合、プログラムは「385」を出力します。
ユーザ入力03、出力14、すなわち1 + 4 + 9
使用アセンブラモリス真野ブックに基づいているなければならない場合。 ここに使用できるすべてのコードがあります。 私は合計を計算するためにループシステムを思いついたが、それは無限であり、1より大きい任意の数を入力するとクラッシュする。 出力をASCIIに戻す方法もわからない。
/read the first character
CIF1, SKI /skip if input flag is set
BUN CIF1 /loop until input flag is set
INP /read a character from the input reg
ADD NZR /add -30 hex (subtract 30 hex)
STA ASD /store value into MSD
CLA /clear the accumulator
/SZA /only if input is 0, otherwise it is 10
/read the second character
CIF2, SKI
BUN CIF2
INP
ADD NZR
STA BSD /store second number in memory
CLA /clear accumulator
/loop for calculation
BUN ACCU /call subroutine ACCU to find SUM/TOTAL
LOOP,LDA SQR /load the odd value i.e. 1, 4, 9, 16...
ADD TWO /adds two
ADD ODD /adds the odd number
STA SQR /store the square
LDA ODD /load the stored odd number
ADD TWO /adds two current odd value
STA ODD /stores the odd value i.e. 1, 3, 5, 7...
/BUN ACCU /branch to subroutine to find SUM/ANSWER
ACCU,LDA SQR //Accumulate the total SUM
ADD SUM
STA SUM
LDA BSD /Load second input number
ADD SUB /subtract 1 from input number until hits 0?
SZA /skip out of loop
BUN LOOP /loop to top
/output the sum
LDA SUM
ADD PZR
OUT
HLT /end program
/output third character?????
/declared variables
ODD, DEC 1 /first vale(1) and new storage for value when odd+2
TWO, DEC 2 /add 2 to the odd numbers: 1+2=3, 3+5=7 etc.
SQR, DEC 1 /first square(1) and stores the square i.e. 4, 9, 16, 25
SUM, DEC 0/Starts at 1, The ANSWER or sum of numbers
SUB, DEC -1/ Subtract 1 from input #(until 0)u
ASD, DEC 0 /where first character is stored
BSD, DEC 0 /where second character is stored
CSD, DEC 0 /Third character output if needed
NZR, HEX -30 /converts to input
PZR, HEX 30 /converts to output
END
あなたは、いくつかのデバッグを行う必要があります。 –
私のベストを尽くして、すでに複数のコードをトレースしていて、何も考えていない。 – snipshow7