且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

组装8086 |数组的总和,输出多位数字

更新时间:2023-02-09 22:29:49

如您的注释中所述,将add的更正内容替换为mov(请注意,以下行:add al,[ bx]实际上是动态的,[bx] )在标签 EndLoop 上只有函数调用是错误的!

With the correction for the add to be replaced by mov as noted in your comment (Note that the line: add al, [bx] is actually mov al, [bx]) there's just the function call at the label EndLoop that's wrong!

您要显示总和,并且正在使用DOS打印功能.此功能09h期望您没有提供DS:DX中的指针!
即使您这样做了,您仍然必须将 sum 数字转换为其文本表示形式.

You want to display the sum, and are using the DOS print function. This function 09h expects a pointer in DS:DX that you are not providing!
Even if you did, you would still have to convert the sum number in its text representation.

这里的一种快速解决方案是让自己满意,并仅以单个ASCII字符的形式显示结果.硬编码的总和为52,因此它是一个可显示的字符:

A quick solution here would be to content yourself and just display the result in the form of a single ASCII character. The hardcoded sum is 52 and so it is a displayable character:

EndLoop:
    mov dl, [sum]
    mov ah, 02h    ;Single character output
    int 21h

; --------------------------

exit:
    mov ax, 4c00h
    int 21h

再迈一步,我们可以显示"52":

One step further and we can display "52":

mov al,[sum]
mov ah,0
mov dl,10
div dl        ---> AL=5   AH=2
add ax,3030h  ---> AL="5" AH="2"
mov dh,ah     ;preserve AH
mov dl,al
mov ah,02h
int 21h
mov dl,dh     ;restore
int 21h