如何使用 x86 程序集打印空白区域



我是x86汇编的新手。我的输出目前如下所示:

1|*
2|** ...
8|********
9|*********
10|**********
11|***********

我希望在 1-9 中有一个空格,以便它形成一条直线。喜欢这个:

 9|
10|
11|

我不知道该怎么做。我在想也许使用 printChar(我希望它在 x86 程序集中)

我打印星星和线条的代码:

beginLoop:   dec numItems
         push numItems
         call printInt //Prints 'numItems' number
         mov al,'|'
         push al
         call printChar //Prints bar line next to number  
  starLoop:    mov al, '*'
               push al
               call printChar //Prints a single star
         mov [numStars], 0 
         inc numStars  //numStars increases by 1
         mov ecx, [esi] //ebx knows inputted value 
         cmp [numStars], ecx //numStars must equal value inputted 
         jne starLoop
nextValue : call printNewLine
            add esi, 4 //Move to next number
            cmp[esi], [items]
            jne beginLoop

你的代码现在将有这样的内容:

mov     eax, [number]
call    YourPrintRoutine

要对这些数字引入右对齐,请将数字与 10 进行比较,并且仅当数字小于 10 时,您才首先打印单个空格字符。

    mov     eax, [number]
    push    eax
    cmp     eax, 10
    jnb     NotBelow10
    push    " "
    call    PrintChar
NotBelow10:
    call    PrintInt

您确定这是产生上述结果的代码吗?

  • mov [numStars], 0在你的星圈中间,它能显示适量的星星是一个奇迹!
  • 随着dec numItems递减一个值,奇怪的是你在屏幕上看到一个递增的数字序列!

最新更新