MASM 除法导致浮点数

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

我需要除以两个数组的总和,但结果是一个浮点数 (0.73)。我将如何除以两个变量并将浮点数存储在寄存器中。然后将浮点数乘以 100 将其变成整数 (73)。下面的结果在 EAX = 00000000

.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 dl, [esi]
        adc dh, 0
        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

    mov eax, AR1_SUM 
    mov ebx, AR2_SUM 
    xor edx, edx
    div ebx

    INVOKE ExitProcess, 0

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