test.asm
来自「清华大学计算机系汇编语言课程」· 汇编 代码 · 共 128 行
ASM
128 行
data segmentmess1 db 'Please input the mark!',0ah,0dh,'$'mess2 db 'The average mark is:',0ah,0dh,'$'buf1 db 60db ?db 60 dup(?)buf2 db 30 dup(?)buf3 db 2 dup(0),'$'data endscode segmentassume cs:code,ds:datastart: mov ax,datamov ds,axlea dx,mess1mov ah,9int 21hcall input lea si,buf1 mov cx,[si+1] and cx,0fh shr cx,1 dec cx lea di, buf2 mov al,[di] L2: inc di add ax,[di] loop L2 div cl call output ;===================================================================================== input proc ;该子程序把输入的成绩转换成一字节压缩BCD码存放 pushf push ax push cx push bx push dx push di mov dx,offset buf1 mov ah,0ah int 21h lea si,buf1 mov dl,0 mov bl,0 mov cx,[si+1] and cx,0fh shr cx,1 lea di,buf2 L1: mov dl,[si+2] ;把输入的第一个数字给dl sub dl,30h shl dl,1 shl dl,1 shl dl,1 shl dl,1 mov bl,[si+3] ;把输入的第二个数字给bl sub bl,30h add dl,bl mov [di],dl inc di add si,2 loop L1 pop di pop dx pop bx pop cx pop ax popf ret input endp ;=============================================================================== output proc ;该子程序把BCD码转换成asc码 push bx push cx push dx push si push di mov cl,4 lea si,buf3 mov ah,al mov bl,ah shr bl,cl add bl,30h mov [si],bl and ah,0fh add ah,30h mov [si+1],ah lea dx,mess2 mov ah,9 int 21h mov dx,offset buf3 mov ah,9 int 21h pop di pop si pop dx pop cx pop bx ret output endp code ends end start
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?