1、汇编实验10汇编实验10暨南大学本科实验报告专用纸课程名称 汇编语言程序设计 成绩评定 实验项目名称 字符串程序设计 指导教师 一、实验目的和要求实验目的 1)掌握串操作指令的使用方法。2)掌握串处理程序的设计方法。 3)熟练使用各种程序结构。实验内容1)编写程序把从键盘输入的以回车为结束符的字符串中的空格去掉并按相反的顺序输出。2)编写程序在字符串STRING1中指定位置插入字符串STRING2。3)编写程序在字符串STRING1中指定位置删除子串。4)输入一个字符串(以回车符作为结束),将其排序后输出到屏幕上。二、程序流程图(每题分开写)三、源程序(每题分开写)DSEG SEGMENT D
2、ATAbuffer db 50 db 0 db 50 dup($)STRING db Please enter the string.,0dh,0ah,$DSEG ENDSSSEG SEGMENT STACK STACK db 256 DUP(0)SSEG ENDSCSEG SEGMENT CODE START PROC FAR ; set segment registers: MOV AX, DSEG MOV DS, AX MOV ES, AX mov ah,09h mov dx,offset STRING int 21h mov ah,0ah mov dx,offset buffer in
3、t 21h mov si,offset buffer+2 mov cx,0outlp: cmp byte ptr si,0dh jz done cmp byte ptr si, jnz next mov di,siinlp: inc di mov al,di mov di-1,al cmp byte ptr di,0dh jnz inlp jmp outlpnext: inc si inc cx jmp outlpdone: mov si,offset buffer+2 add si,cx inc cx mov dl,0dh mov ah,02h int 21h mov ah,02h mov
4、dl,0ah int 21hlop: mov dx,si mov ah,02h int 21h dec si loop lop MOV AX, 4C00h ; exit to operating system. INT 21h START ENDPCSEG ENDSEND START ; set entry point.2. DSEG SEGMENT DATASTRING1 db 50 db 0 db 50 dup($) db $STRING2 db 50 db 0 db 50 dup($) db $STRING3 db Please enter the STRING1. db 0dh,0ah
5、,$STRING4 db 0dh,0ah,Please enter the STRING2. db 0dh,0ah,$STRING5 db 0dh,0ah,Please enter the location in the STRING1 you want. db 0dh,0ah,$STRING6 db 50 dup($)DSEG ENDSSSEG SEGMENT STACK STACK db 256 DUP(0)SSEG ENDSCSEG SEGMENT CODE START PROC FAR ; set segment registers: MOV AX, DSEG MOV DS, AX M
6、OV ES, AX mov dx,offset STRING3 mov ah,09h int 21h mov ah,0ah mov dx,offset STRING1 int 21h mov dx,offset STRING4 mov ah,09h int 21h mov ah,0ah mov dx,offset STRING2 int 21h mov dx,offset STRING5 mov ah,09h int 21h mov ah,01h int 21h sub al,30h mov cx,0 mov cl,al mov bl,al mov si,offset STRING1+2 mo
7、v di,offset STRING6first: mov dl,byte ptr si mov byte ptr di,dl inc si inc di loop first mov si,offset STRING2+2second: cmp byte ptr si,0dh jz thirdnext2: mov dl,byte ptr si mov byte ptr di,dl inc si inc di jnz secondthird: mov si,offset STRING1+2 mov bh,0 add si,bxthird1: cmp byte ptr si,$ jz forth
8、next3: mov dx,si mov di,dx inc si inc di jnz third1forth: mov si,offset STRING1 mov di,offset STRING6forth1: cmp byte ptr di,$ jz overnext4: mov dl,byte ptr di mov byte ptr si,dl inc si inc di jnz forth1over: mov dl,0dh mov ah,02h int 21h mov dl,0ah mov ah,02h int 21h mov dx,offset STRING1 mov ah,09
9、h int 21h MOV AX, 4C00h ; exit to operating system. INT 21h START ENDPCSEG ENDSEND START ; set entry point.3. DSEG SEGMENT DATASTRING1 db 50 db 0 db 50 dup($)STRING2 db Please enter the STRING1.,0dh,0ah,$STRING3 db 0dh,0ah,Please enter the starting position.,0dh,0ah,$STRING4 db 0dh,0ah,Please enter
10、the length you want to delete.,0dh,0ah,$a dw 0b dw 0DSEG ENDSSSEG SEGMENT STACK STACK db 256 DUP(0)SSEG ENDSCSEG SEGMENT CODE START PROC FAR ; set segment registers: MOV AX, DSEG MOV DS, AX MOV ES, AX mov dx,offset STRING2 mov ah,09h int 21h mov dx,offset STRING1 mov ah,0ah int 21h mov dx,offset STR
11、ING3 mov ah,09h int 21h mov ah,01h int 21h mov ah,0 mov a,ax sub a,30h mov dx,offset STRING4 mov ah,09h int 21h mov ah,01h int 21h mov ah,0 mov b,ax sub b,30h mov si,offset STRING1+2 add si,a mov di,offset STRING1+1 mov ch,0 mov cl,byte ptr dilop: mov di,si add di,b mov ax,di mov si,ax inc si loop l
12、op mov dl,0dh mov ah,02h int 21h mov dl,0ah mov ah,02h int 21h mov dx,offset STRING1+2 mov ah,09h int 21h MOV AX, 4C00h ; exit to operating system. INT 21h START ENDPCSEG ENDSEND START ; set entry point.4. DSEG SEGMENT DATASTRING db 50 db 0 db 50 dup($)STRING1 db Please enter the STRING.,0dh,0ah,$ST
13、RING2 db 0dh,0ah,The string is:,$DSEG ENDSSSEG SEGMENT STACK STACK db 256 DUP(0)SSEG ENDSCSEG SEGMENT CODE START PROC FAR ; set segment registers: MOV AX, DSEG MOV DS, AX MOV ES, AX mov dx,offset STRING1 mov ah,09h int 21h mov dx,offset STRING mov ah,0ah int 21h mov si,offset STRING+2 mov cl,STRING+
14、1 mov ch,0 dec cxoutlp: mov dx,cx mov bx,siinlp: mov al,bx cmp al,bx+1 jna next xchg al,bx+1 mov bx,alnext: inc bx dec dx jnz inlp loop outlp mov dx,offset STRING2 mov ah,09h int 21h mov dx,offset STRING+2 mov ah,09h int 21h MOV AX, 4C00h ; exit to operating system. INT 21h START ENDPCSEG ENDSEND START ; set entry point.4、结果分析(对输入输出部分截屏)5、实验总结尝试用绘图工具画图,有点不习惯
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1