对矢量集合中的元素求和

Sum elements in vector assembly

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

.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