gpt4 book ai didi

assembly - 向量汇编中的元素求和

转载 作者:行者123 更新时间:2023-12-02 14:41:52 25 4
gpt4 key购买 nike

有人可以向我解释一下为什么下面的程序不会在屏幕上显示任何内容吗?所以我试图做的是计算向量的总和,如下所示:

.model small
.stack 100h
.data
vector db 1,2,3,4,5,6,7,8,9
suma db 0
count db 9
msg db 10,13,"Sum is:$"

.code
mov ax,@data
mov ds,ax

mov si,0
xor si,si
xor cx,cx
mov cl,count
repeta:
mov al,vector[si]
add suma,al
inc si
loop repeta

mov bx,ax
mov ah,09
lea dx,msg
int 21h
mov ah,2
mov dl,bl
int 21h
mov ah,2
mov dl,bl
int 21h

mov ah,4ch
int 21h
end

最佳答案

mov bx,ax

此时程序中的 AX 没有任何意义。您要查找的值位于 suma 变量中。

下一个代码将显示总和低于 100 的结果。

mov ah, 09h
lea dx, msg
int 21h

mov al, suma ;Result happens to be 55
aam ;Tens go to AH, units go to AL
or ax, "00" ;Make ASCII characters
mov bx, ax ;Move to safe place

mov ah, 02h
mov dl, BH ;Display tens
int 21h
mov ah, 02h
mov dl, BL ;Display units
int 21h

mov ah, 00h
int 16h ;Wait for a key

关于assembly - 向量汇编中的元素求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50555323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com