2016-10-14 49 views
2

我能夠遍歷數組並打印出值。但是,我還想打印出「我的數組長度爲7」的字符串,其中7是數組中元素的長度。但是,我無法將字符串連接到數組的長度。請幫忙。謝謝。在Assembly x86中連接一個字符串和一個數組的大小MASM

INCLUDE Irvine32.inc 
.data 
    myarray byte 23, 2, 3, 40, 5, 16, 7 
    x byte 5 
    l dword lengthof myarray 
    msg1 byte "The length of my array is ",0 
    msg2 byte "-------------------------------",0 
    i byte 0 
    .code 
    main PROC 

     mov eax, 0 
     mov esi, offset myarray; 
     mov ecx, l 



     myloop: 
     mov al, [esi] 
     call writedec 
     call crlf 
     inc esi 
     mov edx, OFFSET msg1 
     mov edx, l 

     loop myloop 

     call writestring 
     call crlf 
     call crlf 

     exit 

     main ENDP 
     end main 

我得到的結果如下:

23 
2 
3 
40 
5 
16 
7 

"esimovarray.asm has stopped working" 

請幫助。謝謝。

+1

通過在調試器的代碼步驟。觀看寄存器值。暫時使用較短的陣列以加快調試速度。 –

回答

1

我認爲我們只需要改變的幾行代碼的順序:

INCLUDE Irvine32.inc 
.data 
    myarray byte 23, 2, 3, 40, 5, 16, 7 
    x byte 5 
    l dword lengthof myarray 
    msg1 byte "The length of my array is ",0 
    msg2 byte "-------------------------------",0 
    i byte 0 
    .code 
    main PROC 

     mov eax, 0 
     mov esi, offset myarray; 
     mov ecx, l 

     myloop: 
     mov al, [esi] 
     call writedec 
     call crlf 
     inc esi 
     ;mov edx, OFFSET msg1   ;◄■■■ NOT HERE. 
     ;mov edx, l     ;◄■■■ NOT HERE. 
     loop myloop 

     mov edx, OFFSET msg1   ;◄■■■ RIGHT HERE! 
     call writestring 

     mov eax, l     ;◄■■■ RIGHT HERE! MUST BE EAX. 
     call writedec 

     exit 

     main ENDP 
     end main 
相關問題