在 Assembly x86 MASM 中连接字符串和数组的大小

Concatenating a string and the size of an array in Assembly x86 MASM

我能够遍历数组并打印出值。但是,我还想打印出字符串 "The length of my array is 7",其中 7 是数组中(元素数)的长度。但是,我无法将字符串与数组的长度连接起来。请帮忙。谢谢。

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"

请帮忙。谢谢。

我想我们只需要改变几行代码的顺序:

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