MASM 16 位数组加法

问题描述 投票:0回答:0

我需要对 2 个单独的数组求和。一个数组总计为 243,添加它并将其存储在一个值中没有问题。但是第二个数组总计 330,并且由于它是一个 16 位数字,我认为我必须使用 dx 寄存器而不是 dl。但是现在当我添加数字时,寄存器设置为 0000204A,这不是十进制格式的 330。我究竟做错了什么?我该如何解决这个问题?

.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode: DWORD

.data
    AR1 DB 25, 89, 49, 80
    AR2 DB 30, 100, 50, 150
    AR1_SUM DWORD 0   ; variable to store the sum of AR1 elements
    AR2_SUM DWORD 0   ; variable to store the sum of AR2 elements


.code
_main PROC
    
    mov esi, offset AR1 ; set ESI to point to the first element of AR1
    mov ecx, 4 ; reset the loop counter
    xor edx, edx ;

    addloop1:
        add dl, [esi] ; add the current byte to the sum
        add esi, 1 ; move to the next byte in AR1
        loop addloop1 ; repeat until all elements in AR1 have been added
    mov AR1_SUM, edx
    
        mov esi, offset AR2 ; set ESI to point to the first element of AR2
        mov ecx, 4 ; reset the loop counter
        xor edx, edx ; reset the sum register for AR2

        addloop2:
                add dx, [esi] ; add the current byte to the sum
                add esi, 1 ; move to the next byte in AR2
                loop addloop2 ; repeat until all elements in AR2 have been added
        mov AR2_SUM, edx ; store the sum of AR2 in AR2_SUM
    INVOKE ExitProcess, 0

_main ENDP
END _main
assembly x86 masm
© www.soinside.com 2019 - 2024. All rights reserved.