0
INCLUDE Irvine32.inc
.data
fullName BYTE "Bob Johnson",0
nameSize = ($ - fullName) - 2
.code
main PROC
    mov ECX,nameSize
    mov ESI,OFFSET fullName
Sum:
    mov EBX,[ESI+ECX]
    add EAX,EBX
    loop Sum
    exit
main ENDP
END main

所以我遇到了一个问题,我只想一次从字符串中读取一个字符并将其存储在 EBX 寄存器中,然后获取该字符的值并在 EAX 中保持运行总和。

使用 8 位无符号算术将字符串字符的所有 ASCII 代码相加。溢出被忽略。最终值是校验和。例如,如果字符串是“Joe”,那么 ASCII 值是 4A、6F、65。总和是 11E。

4

1 回答 1

0
INCLUDE Irvine32.inc
.data

fullName BYTE "Bob Johnson",0       ; String storing name
nameSize = ($ - fullName)   ; Variable storing length of name

.code
main PROC

    mov ECX,nameSize        ; Set counter for loop
    mov ESI,OFFSET fullName ; Set pointer at fullName variable
    mov EAX,0               ; Clear the EAX register
    mov EBX,0               ; Clear the EBX register

Sum:                        ; Loop 

    mov bl,[ESI + ECX - 1]  ; Use the bl (8 bit register) to point at characters in the string.
    add EAX,EBX         ; Add the two registers together

    loop Sum                ; Loop  

    call DumpRegs           ; Display results

    exit
main ENDP

END main

解决了!

于 2013-01-18T20:49:10.640 回答