1、实验四 汇编程序编写和提高(编写程序和画程序流程图)1、 编写一个汇编程序,先键盘输入的多个小写字母,回车后用大写字母显示出来。程序:DATAS SEGMENT buf db 100 dup(?) DATAS ENDSSTACKS SEGMENT ;此处输入堆栈段代码STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX lea si,buf convert: mov ah,1 int 21h cmp al,13 jz finish cmp al,a jb next cmp
2、 al,z ja next sub al,20h jmp next next: mov si,al inc si jmp convertfinish: mov dl,13 mov ah,2 int 21h mov dl,10 int 21h mov byte ptr si,$ lea dx,buf mov ah,9 int 21h MOV AH,4CH INT 21HCODES ENDS END START运行情况:流程图:2、 将键盘上输入的十六进制数转换成十进制数,并在屏幕上显示。程序:DATA SEGMENT DATA1 DB 6 DUP(?),$ DATA ENDSCODE SEGME
3、NT ASSUME CS:CODE,DS:DATASTART: MOV AX,DATA MOV DS,AX MOV DI,OFFSET DATA1+5 MOV BX,0 MOV CH,4 MOV CL,4 MOV SI,0AH JUDGE: MOV AH,01H INT 21H CMP AL,13 JE TRANSPORT CMP AL,30H JB EXIT CMP AL,39H JBE LAB CMP AL,41H JB EXIT CMP AL,46H JBE LAB1 CMP AL,61H JB EXIT CMP AL,66H JA EXIT SUB AL,57H JMP LAB2LAB
4、:SUB AL,30H JMP LAB2LAB1: SUB AL,37H LAB2: SHL BX,CL ADD BL,AL DEC CH JNZ JUDGETRANSPORT: MOV AX,BX DISPLAY: XOR DX,DX DIV SI ADD DL,30H MOV DI,DL DEC DI CMP AX,0 JNZ DISPLAY XOR DX,DX MOV AH,09H INT 21H EXIT: MOV AH,4CH INT 21HCODE ENDS END START运行情况:流程图:3、 利用中断调用,在屏幕上显示19之间随机数。中断号86H程序如下:DATAS SEG
5、MENT ;此处输入数据段代码 DATAS ENDSSTACKS SEGMENT ;此处输入堆栈段代码STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX call setInt86 int 86h MOV AH,4CH INT 21H setInt86 proc mov ax,cs mov ds,ax mov si,offset do0 mov ax,0 mov es,ax mov di,200h mov cx,offset do0end-offset do0 cld
6、rep movsb mov ax,0 mov es,ax mov word ptr es:86h*4,200h mov word ptr es:86h*4+2,0 retsetInt86 endp do0: MOV AH,0 INT 1AH ;读取当前时间CH:CL=时:分 MOV AL,DL ;DH:DL=秒:1/100 秒 MOV AH,0 MOV BL,9 DIV BL INC AH MOV DL,AH ADD DL,30H MOV AH,2 INT 21H do0end:nop CODES ENDSEND START运行情况:流程图:4、 键盘输入10个学生的成绩,编写一个程序统计60
7、-69分,70-79分,80-89分,90-99分及100分的人数,分别存放在Score6,Score7,Score8,Score9和Score10单元中。【输入10个学生的成绩如下】65 98 78 82 88 95 72 62 90 100程序如下:datas segment sentence db 0DH,0AH,the result $ grade dw 76,69,84,90,73,88,99,63,100,80 score6 db 0 score7 db 0 score8 db 0 score9 db 0 score10 db 0 datas ends stacks segment
8、stacks endscodes segment assume cs:codes,ds:datas start: mov ax,datas mov ds,ax mov cx,10 call count call disp mov ah,4ch int 21hcount proc near mov si,0 next:mov ax,gradesi mov bl,10 div bl mov bl,al mov bh,0 sub bx,6 cmp bx,0 jae next1 next1: inc score6bx add si,2 loop next ret count endp disp proc near lea si,score6 mov cx,5 loop1: mov dx,OFFSET sentence mov ah,9 int 21h mov dl,si add dl,30h mov ah,2 int 21h inc si loop loop1 ret disp endp codes ends end start效果如下:流程图: