MASM - :0xC0000005:访问冲突写入位置

时间:2018-03-07 01:43:18

标签: assembly x86 masm32 irvine32

我正在处理与20 Random Strings containing all capital letters

相同的作业
  

我需要创建一个生成长度为L的随机字符串的过程,其中包含所有大写字母。在调用过程时,我需要在EAX中传递L的值,并将指针传递给将保存随机字符串的byte数组。然后我需要编写一个测试程序,调用你的程序20次,并在控制台窗口中显示字符串。

我相信由于那里的答案,我已经更接近解决方案,但仍然有一个(我希望)问题。 Microsoft Visual Studio 2017引发以下错误:

Project.exe中0x004036BE处抛出异常:0xC0000005:访问冲突写入位置0x0080C036。发生

错误发生在第41行:mov arr1[EBX], AL

所以我最好的猜测是我错误估算了阵列的目标地址,但我不知道怎么做? 我在该循环的第一次运行时收到错误。

; Random Strings.

INCLUDE Irvine32.inc
TAB = 9                   ;ASCII code for Tab
strLen = 10               ;length of the string
numberStrings = 20

.data
str1 BYTE "The 20 random strings are:", 0
arr1 BYTE numberStrings DUP(?)


.code
main PROC
    mov EDX, OFFSET str1      ;"The c20 random strings are:"
    call WriteString          ;Writes string
    call Randomize
    call Crlf                 ;Writes an end - of - line sequence to the console window.
    mov ECX, numberStrings    ;Main Loop Counter Create 20 strings
    mov ESI, OFFSET arr1      ;ESI: array address

L1 : 
    mov EAX, strLen            ;EAX: string length
    call RandomString          ;generates the random string
    call Display               ;displays the random string to console
    mov AL, TAB                ;moves tab to register to be passed to WriteChar
    call WriteChar             ;leaves a tab space
    exit
main ENDP

RandomString PROC USES EAX ESI
    mov ECX, EAX               ;ECX = string length
    mov EBX, ESI               ;store array address

    FillStringWithRandomCharacters : 
        mov EAX, 26            ;set upper boundry for RandomRange call
        call RandomRange       ;called with 26 so range will be 0 - 25
        add EAX, 65            ;EAX gets ASCII value of a capital letter
        mov arr1[EBX], AL      ;pass 8 bits of EAX to array
        inc EBX                ;move array target address
    loop FillStringWithRandomCharacters

    ret
RandomString ENDP

Display PROC USES EAX ESI      ;Displays the generated random string
    mov ECX, EAX               ;ECX = string length
    mov EBX, ESI               ;store array address

    DisplayRandomString : 
        mov AL, arr1[EBX]      ;retrieve char from array
        call WriteChar         ;writes the char to console
        inc EBX                ;move array target address
    loop DisplayRandomString

    ret
    Display ENDP

    call dumpregs

INVOKE ExitProcess, 0
END main

0 个答案:

没有答案