0

I am having a problem getting my Pep/8 assembly program to produce the correct output. The goal is to input a number n followed by n numbers and then have the output place the first number at the end of the array. An example of input and correct output is as follows:

"Three numbers of which 1,2, and 3 are in the array." Input: 3 1 2 3

"The first number in the array, 1, is placed at the end of the array." Correct Output: 2 3 1

My input and output are:

Input: 3 1 2 3 Incorrect Output: 2 2 1 Desired Output: 2 3 1

Input: 4 1 2 3 4 Incorrect Output: 2 3 3 1 Desired Output: 2 3 4 1

Input: 5 1 2 3 4 5 Incorrect Output: 2 3 3 4 1 Desired Output: 2 3 4 5 1

The three parts of my assembly code can be seen at: http://militarystudents.files.wordpress.com/2009/11/pic1of3.png http://militarystudents.files.wordpress.com/2009/11/pic2of3.png http://militarystudents.files.wordpress.com/2009/11/pic3of3.png

The output for n = 1 and n = 2 comes out correctly. For n > 2 the output seems to repeat a portion of my input. I am using a global array list. Any information will be greatly appreciated.

4

1 に答える 1

2

PEP8はわかりませんが、投稿された情報からいくつかわかります。

  1. これはパスカルの三角形ではありません。出力には新しい(より大きい)値がないため、何も追加されていません。これらは、間違った順序とカウントの入力値のコピーにすぎません。

  2. これは、リストローテーションアルゴリズムの実装方法にエラーがあるようです。PEP8がわからないため、エラーが何であるかはわかりませんが、正しいアルゴリズムは次のとおりです。

    A. list(0)をtmpにコピーします

    B. i = 1からN-1の場合:

    (1)list(i)をlist(i-1)にコピーします

    C. tmpをlist(N-1)にコピーします

エラーがあったと推測すると、ステップ「B」にあると言えます。ループが終了する前に終了しているように見えるため、後の値の1つ以上が前方にコピーされていません。

于 2009-11-29T15:44:19.477 に答える