我写了一个汇编代码来总结五个数字。然后将最终值存储在内存中。
dtseg segment
data dw 27345,28521,29533,30105,32375
sum dw ?
MSG1 DB "The sum is : $"
dtseg ends
;---------------------
cdseg segment
main proc far
assume cs:cdseg,ds:dtseg,ss:stseg
mov ax,dtseg
mov ds,ax
clc ; clear the carry
mov si,offset data ; first location of data
mov cx,04 ; setting the counter
mov ax,0 ; clear ax
mov bx,ax ; clear bx
back:add ax,[si] ; the first round: 0+27345
adc bx,0 ; if there is a carry, add that to bx
inc si ; two inc because traversing words
inc si
dec cx ; count down
jnz back ; do that for other numbers
mov sum,ax ; the final value
mov sum+2,bx ; the carries are stored in bx
lea dx,MSG1 ; trying to display the result
mov ah,09h
int 21h
mov ah, 4cH ; return to DOS
int 21h
main endp
cdseg ends
end main
我遵循了基于this topic的示例,但是它在emu8086中不起作用