计算数组程序集中元素的出现次数 MASM

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

嗨,我在这个装配项目中遇到了很多麻烦。这就是我必须做的:生成一个数组 counts,它保存 [LO, HI] 范围内的每个值的次数([15, 50] 对于默认常量值)在 randArray(随机数组)中出现,即使如果看到某个值的次数为零。 例如,当 LO=15 时,counts[0] 应该等于数组中值

15
的实例数。 counts[14] 应该等于 randArray 中值
29
的实例数。请注意,某些值可能出现零次,应报告为零个实例。

感谢任何帮助,谢谢

这就是我所拥有的:

;constants:
HI = 50
LO = 15
ARRAYSIZE = 20
LINE_LIMIT = 5

....
countList PROC

    push ebp
    mov ebp, esp
    mov edx, 1
    mov ecx, ARRAYSIZE
    mov edi, [ebp+12]
    mov ebx, [edi]

    countLoop:
    sub ebx, LO
    mov esi, [ebp+8]
    add esi, ebx
    add [esi], edx
    mov eax, [esi]
    call WriteDec
    add edi, 4
    mov ebx, [edi]
    loop countLoop

    pop ebp
    ret 8
countList ENDP


displayCounts PROC

    push ebp
    mov ebp, esp
    mov esi, [ebp+12]
    mov ecx, 20
    mov edx, [ebp+8]
    call CrLf
    call WriteString
    call CrLf
    mov ebx, 0 ;to keep track of the elements per line

    displayElement:
    mov eax, [esi]
    call WriteDec
    mov edx, OFFSET twoSpace
    call WriteString
    inc ebx

    ;To check if the maximum limit of integers per line is reached
    cmp ebx, LINE_LIMIT
    jl skipNextLine
    call CrLf
    mov ebx, 0 ;the counter is refreshed

    skipNextLine:
    add esi, 4 ;move to next element of the array
    loop displayElement

    pop ebp
    ret 8

displayCounts ENDP

....

assembly masm
© www.soinside.com 2019 - 2024. All rights reserved.