在首地址为buf的内存中,连续存放者20个单字节无符号数,将它们相加,得到16位的结果,并将它存到首址为res的单元。请自行设计数据,比如设计它们为0~9及90~99,那么求和后的结果应为990(03DEH),继续求这批数据的平均值,最后将运算结果——和、商、余数分别存放到res1(字)和res2(字节)res3(字节)等3处
DATAS SEGMENT
buf db 0,1,2,3,4,5,6,7,8,9,90,91,92,93,94,95,96,97,98,99
res1 dw ?
res2 db ?
res3 db ?
DATAS ENDS
STACKS SEGMENT
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
dispchar macro char
mov ah,2
mov dl,char
int 21h
endm
dispmsg macro message
mov ah,9
lea dx,message
int 21h
endm
disphex macro hexdata
local disphex1
push ax
push bx
push cx
push dx
mov bx,hexdata
mov cx,0404h
disphex1: rol bx,cl
mov al,bl
and al,0fh
call htoasc
dispchar al
dec ch
jnz disphex1
pop dx
pop cx
pop bx
pop ax
endm
mov cx,lengthof buf
mov bx,0h
lea si,buf
again:
mov al,byte ptr [si]
cbw
adc bx,ax
inc si
loop again
mov word ptr res1,bx
disphex bx
mov ax,bx
mov cl,lengthof buf
div cl
mov res2,al
mov res3,ah
disphex ax
MOV AH,4CH
INT 21H
HTOASC proc
push bx
mov bx,offset ASCII
and al,0fh
xlat ASCII
pop bx
ret
ASCII db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h
db 41h,42h,43h,44h,45h,46h
HTOASC endp
CODES ENDS
END START