Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 列MASM中的数组输出_Assembly_Masm_Irvine32 - Fatal编程技术网

Assembly 列MASM中的数组输出

Assembly 列MASM中的数组输出,assembly,masm,irvine32,Assembly,Masm,Irvine32,我正在运行一个程序,要求用户输入要显示的复合数字的数量。例如,如果用户输入10,程序将显示前10个复合数字 我遇到的问题是,我的程序在一个长列中打印所有值,我需要让输出以每行10个复合数字显示,每行之间至少有3个空格。代码如下: INCLUDE Irvine32.inc .data userInt1 DWORD ? ;integer to be entered by user userInt2 DWORD ? ;integer t

我正在运行一个程序,要求用户输入要显示的复合数字的数量。例如,如果用户输入10,程序将显示前10个复合数字

我遇到的问题是,我的程序在一个长列中打印所有值,我需要让输出以每行10个复合数字显示,每行之间至少有3个空格。代码如下:

INCLUDE Irvine32.inc


.data

userInt1    DWORD   ?           ;integer to be entered by user
userInt2    DWORD   ?           ;integer to be entered by user
compNums DWORD 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30 
          DWORD 32, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46, 48, 49, 50, 51, 52, 54 
          DWORD 55, 56, 57, 58, 60, 62, 63, 64, 65, 66, 68, 69, 70, 72, 74, 75, 76, 77 
          DWORD 78, 80, 81, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 98, 99 
          DWORD 100, 102, 104, 105, 106, 108, 110, 111, 112, 114, 115, 116, 117, 118, 119 
          DWORD 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 132, 133, 134, 135, 136 
          DWORD 138, 140, 141, 142, 143, 144, 145, 146, 147, 148, 150, 152, 153, 154, 155, 156 
          DWORD 158, 159, 160, 161, 162, 164, 165, 166, 168, 169, 170, 171, 172, 174, 175
          DWORD  176, 177, 178, 180, 182, 183, 184, 185, 186, 187, 188, 189, 190, 192, 194 
          DWORD  195, 196, 198, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 212 
          DWORD  213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 224, 225, 226, 228, 230 
          DWORD  231, 232, 234, 235, 236, 237, 238, 240, 242, 243, 244, 245, 246, 247, 248
          DWORD   249, 250, 252, 253, 254, 255, 256, 258, 259, 260, 261, 262, 264, 265, 266 
          DWORD   267, 268, 270, 272, 273, 274, 275, 276, 278, 279, 280, 282, 284, 285, 286, 287 
          DWORD   288, 289, 290, 291, 292, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304 
          DWORD   305, 306, 308, 309, 310, 312, 314, 315, 316, 318, 319, 320, 321, 322, 323, 324 
          DWORD   325, 326, 327, 328, 329, 330, 332, 333, 334, 335, 336, 338, 339, 340, 341, 342 
          DWORD   343, 344, 345, 346, 348, 350, 351, 352, 354, 355, 356, 357, 358, 360, 361, 362, 363 
          DWORD   364, 365, 366, 368, 369, 370, 371, 372, 374, 375, 376, 377, 378, 380, 381, 382, 384 
          DWORD   385, 386, 387, 388, 390, 391, 392, 393, 394, 395, 396, 398, 399, 400, 402, 403
          DWORD   404, 405, 406, 407, 408, 410, 411, 412, 413, 414, 415, 416, 417, 418, 420, 422
          DWORD   423, 424, 425, 426, 427, 428, 429, 430, 432, 434, 435, 436, 437, 438, 440, 441
          DWORD   442, 444, 445, 446, 447, 448, 450, 451, 452, 453, 454, 455, 456, 458, 459, 460
          DWORD   462, 464, 465, 466, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 480
          DWORD   481, 482, 483, 484, 485, 486, 488, 489, 490, 492, 493, 494, 495
intro_1     BYTE    "Composite Numbers  by. Eric Walters" , 0
prompt_1    BYTE    "Enter the number of composite numbers you would like to see. ", 0
prompt_2    BYTE    "I'll accept orders for up to 400 composites. ", 0
prompt_3    BYTE    "Enter the number of composites to display [1 .. 400]: ", 0
prompt_4    BYTE    "Test", 0
prompt_6    BYTE    "Results certified by Eric Walters.",0
prompt_7    BYTE    "Goodbye, ", 0
outOfRange  BYTE    "Out of range. Try again.",0
goodBye     BYTE    "Impressed? Bye! ", 0
upperLevel  DWORD   400         ;the largest integer allowed
lowerLevel  DWORD   1           ;the smallest integer allowed
newArray    DWORD   400 DUP(?)


.code
main PROC

MOV eax, 0 
MOV ebx, 0
MOV ecx, 0
MOV edx, 0


; Introduction  
    Introduction:   
        mov     edx, OFFSET intro_1
        call    WriteString
        call    CrLf
        call    CrLf
        mov     edx, OFFSET prompt_1
        call    WriteString
        call    CrLf
        mov     edx, OFFSET prompt_2
        call    WriteString
        call    CrLf
        call    CrLf

; getUserData
    getUserData:
        mov     edx, OFFSET prompt_3
        call    WriteString
        call    ReadInt
        mov     userInt1, eax
        mov     ebx, OFFSET compNums

    ;validate   
        cmp     eax, upperLevel
        ja      option1
        cmp     eax, lowerLevel
        jb      option1
        jmp     showComposites

    option1 :
        mov     edx, OFFSET outOfRange
        call    WriteString
        call    crlf
        jmp     getUserData

    showComposites :
        mov ecx, userInt1
        cmp ecx, 0

        isComposite:
            mov eax, [ebx]
            call WriteDec
            call crlf
            add ebx, 4
            loop isComposite

farewell :
        mov     edx, OFFSET prompt_6
        call    WriteString
        call    crlf
        mov     edx, OFFSET prompt_7
        call    WriteString
        call    crlf


    exit        ; exit to operating system
main ENDP

END main
关于如何在每行之间用3个空格打印10个元素,有什么建议吗

我实现了以下代码:

showComposites :
        mov ecx, userInt1
        jecxz   farewell
        mov edx, 10

    isComposite:
        mov eax, [ebx]
        call WriteDec
        dec edx
        jnz Spaces
    linebreak:
        call crlf
        mov edx, 10
        jmp Next

    Spaces:
        cmp ecx, 1
        je  linebreak
        mov edx, OFFSET space3
        call WriteString

    Next:
        add ebx, 4
        loop isComposite
输出直到第17个元素(而不是第10个元素)才换行

我一定错过了什么,因为换行符在10个元素之后没有发生

更新:修复了这个问题。我将计数器寄存器从edx更改为esi,它工作正常。

您可以

半伪码:

Divide UserInt1 by 10
If Quotient > 0 OuterLoopCount=Quotient
   OutterLoop:
   Save OuterLoopCount
   Initialize InnnerLoopCount=10
   InnerLoop:
   WriteDec & 3 Spaces
   Add Array, TYPE
   Loop InnerLoop
   CRLF
   Restore OuterLoopCount
   Loop OuterLoop
Else Here   
Move Remainder = Loop Count
ZeroQuotient:
WriteDec & 3 Spaces
Add array, TYPE
Loop ZeroQuotient
CRLF
...
你似乎对这个比较的结果一无所知

要解决您遇到的问题,您可以引入一个计数器,并使用值10进行初始化。每次输出CRLF时,将计数器重置为10

showComposites :
    mov ecx, userInt1
    jecxz farewell
    mov edx, 10
isComposite:
    mov eax, [ebx]
    call WriteDec
    dec edx
    jnz Spaces
CRLF:
    call crlf
    mov edx, 10
    jmp Next
Spaces:
    cmp ecx, 1  ;No 3 spaces needed behind the last number!
    je CRLF
    ... Ouput 3 spaces here
Next:
     add ebx, 4
     loop isComposite

farewell :

使用两个计数器
showComposites :
    mov ecx, userInt1
    jecxz farewell
    mov edx, 10
isComposite:
    mov eax, [ebx]
    call WriteDec
    dec edx
    jnz Spaces
CRLF:
    call crlf
    mov edx, 10
    jmp Next
Spaces:
    cmp ecx, 1  ;No 3 spaces needed behind the last number!
    je CRLF
    ... Ouput 3 spaces here
Next:
     add ebx, 4
     loop isComposite

farewell :