在MASM Assembly中的对齐列中显示整数

时间:2016-07-09 06:39:27

标签: masm irvine32

我一直在努力让这个工作几天,并且没有运气让它发挥作用。我真的很感激帮助搞清楚这一点。

(这是在MASM Assembly中,唯一允许的库是Irvine库)

该程序是一个基本的Fibonacci数字生成器。它从1-46( n )获取用户输入,然后将Fibonacci序列打印到 nth 项。

输出应为每行5个术语,中间至少有5个空格。这部分有效。

编辑* 我遇到问题的部分是当整数长度大于7位时,输出在列中排列。

我试图通过将TAB传递给控制台来实现这一点,该控制台可以工作,但最多只能有7位长的整数。我明白为什么会这样,但我无法找到解决办法。我尝试打印不同长度的空间无济于事。我的猜测是,我需要计算整数的长度,并根据第7行之后的长度打印正确的空格数,或者使用来自Irvine库的Gotoxy(),但是我无法正确地理解如何。 / p>

这是输出 -

1               1               2               3               5

8               13              21              34              55

89              144             233             377             610

987             1597            2584            4181            6765

10946           17711           28657           46368           75025

121393          196418          317811          514229          832040

1346269         2178309         3524578         5702887         9227465

14930352                24157817                39088169                  63245986                102334155
165580141               267914296               433494437               701408733               1134903170
1836311903              Press any key to continue . . .

以下是相关代码......

mov     rowPosition,1           ;assign initial row positon 
mov     currentTerm, 0          ;makes first two terms 1
mov     previousTerm, 1
mov     ecx, nthTerm            ;set counter to nth term 

printFib:       
            mov     eax,currentTerm
            mov     ebx,currentTerm     ;mov current term to ebx to hold  value
            add     eax,previousTerm    ; = currentTerm + previousTerm
            call    WriteDec            ;writes new term
            mov     currentTerm,eax     ;set newly calculated term to currentTerm
            mov     previousTerm,ebx    ;set previousTerm to equal current Term

            mov     al, 9               ; ASCII CHAR 9 =  TAB
            call    WriteChar           ;writes tab to align text
            call    WriteChar

            cmp     rowPosition, 5      ;checks postion in row
            jge     newRow              ;jump if rowPostion greater than or equal to 5
            inc     rowPosition         ;else increment rowPosition
            loop    printFib            ;If ECX!=0 Loop to printFib 
            jmp     goodbye

newRow:     call        crlf            ; move to next row
            mov         rowPosition, 1  ;reset row postion to 1
            loop        printFib        ;If ECX!=0 Loop to printFib 

任何人都可以指出我正确的方向吗?

0 个答案:

没有答案