桂电汇编部分实验完整代码

上传人:xins****2008 文档编号:197873557 上传时间:2023-04-06 格式:DOC 页数:24 大小:81KB
收藏 版权申诉 举报 下载
桂电汇编部分实验完整代码_第1页
第1页 / 共24页
桂电汇编部分实验完整代码_第2页
第2页 / 共24页
桂电汇编部分实验完整代码_第3页
第3页 / 共24页
资源描述:

《桂电汇编部分实验完整代码》由会员分享,可在线阅读,更多相关《桂电汇编部分实验完整代码(24页珍藏版)》请在装配图网上搜索。

1、实验三代码sseg segment stack dw 256 dup (?) sseg ends data segment msg1 db Enter keyword:,24h msg2 db Enter Sentence:,24h cr db 13,10,24h keyword db 250,?,250 dup (?) Sentence db 250,?,250 dup (?) match db Match at location:,24h match1 db of the sentence,13,10,24h nomatch db No match,13,10,24h data ends

2、code segment assume cs:code,ds:data,ss:sseg disp_hex proc near push ax push cx push dx push ax mov cl,4 ror al,cl and al,0fh add al,30h cmp al,39h jna d1 add al,7 d1: mov dl,al mov ah,2 int 21h pop ax and al,0fh add al,30h cmp al,39h jna d2 add al,7 d2: mov dl,al mov ah,2 int 21h mov dl,h mov ah,2 i

3、nt 21h pop dx pop cx pop ax ret disp_hex endp begin: mov ax,data mov ds,ax mov es,ax mov dx,offset msg1 mov ah,9 int 21h mov dx,offset keyword mov ah,0ah int 21h cmp keyword + 1,0 je quit mov dx,offset cr mov ah,9 int 21h b1: mov dx,offset msg2 mov ah,9 int 21h mov dx,offset Sentence mov ah,0ah int

4、21h mov dx,offset cr mov ah,9 int 21h mov dl,Sentence + 1 cmp dl,0 je quit mov dh,keyword + 1 mov di,offset Sentence + 2 b2: cmp dh,dl ja _nomatch mov si,offset keyword + 2 mov cl,dh mov ch,0 cld push di repe cmpsb pop di je _match inc di dec dl jmp b2 _match: mov ax,di sub ax,offset Sentence + 2 in

5、c ax push ax mov dx,offset match mov ah,9 int 21h pop ax call disp_hex mov dx,offset match1 mov ah,9 int 21h jmp b1 _nomatch: mov dx,offset nomatch mov ah,9 int 21h jmp b1 quit: mov ah,4ch int 21h code ends end begin /传递DATAS SEGMENTSTR1 DB ASDFG STR2 DB 100 DUP(?)DATAS ENDSSTACKS SEGMENT ;此处输入堆栈段代码

6、STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX LEA BX,STR1 LEA SI,STR2 MOV CX,100LOP:MOV BL,BX MOV SI,AL INC BX INC SI LOOP LOP MOV AH,4CH INT 21HCODES ENDS END START循环程序1CODE SEGMENTASSUME CS:CODESTART: MOV AH,02h MOV CX,15 MOV BL,10HLOO1: MOV BH,16LOOP2: M

7、OV DL,BL INT 21H MOV DL,20h INT 21H INC BL DEC BH CMP BH,0 JNE LOOP2 MOV DL,0ah INT 21H MOV DL,0dh INT 21H LOOP LOO1EXIT: MOV AH,4CH INT 21HCODE ENDS END START循环程序2 sseg segment stack dw 256 dup (?) sseg ends data segment msg1 db Enter keyword:,24h msg2 db Enter Sentence:,24h cr db 13,10,24h keyword

8、 db 250,?,250 dup (?) Sentence db 250,?,250 dup (?) match db Match at location:,24h match1 db of the sentence,13,10,24h nomatch db No match,13,10,24h data ends code segment assume cs:code,ds:data,ss:sseg disp_hex proc near push ax push cx push dx push ax mov cl,4 ror al,cl and al,0fh add al,30h cmp

9、al,39h jna d1 add al,7 d1: mov dl,al mov ah,2 int 21h pop ax and al,0fh add al,30h cmp al,39h jna d2 add al,7 d2: mov dl,al mov ah,2 int 21h mov dl,h mov ah,2 int 21h pop dx pop cx pop ax ret disp_hex endp begin: mov ax,data mov ds,ax mov es,ax mov dx,offset msg1 mov ah,9 int 21h mov dx,offset keywo

10、rd mov ah,0ah int 21h cmp keyword + 1,0 je quit mov dx,offset cr mov ah,9 int 21h b1: mov dx,offset msg2 mov ah,9 int 21h mov dx,offset Sentence mov ah,0ah int 21h mov dx,offset cr mov ah,9 int 21h mov dl,Sentence + 1 cmp dl,0 je quit mov dh,keyword + 1 mov di,offset Sentence + 2 b2: cmp dh,dl ja _n

11、omatch mov si,offset keyword + 2 mov cl,dh mov ch,0 cld push di repe cmpsb pop di je _match inc di dec dl jmp b2 _match: mov ax,di sub ax,offset Sentence + 2 inc ax push ax mov dx,offset match mov ah,9 int 21h pop ax call disp_hex mov dx,offset match1 mov ah,9 int 21h jmp b1 _nomatch: mov dx,offset

12、nomatch mov ah,9 int 21h jmp b1 quit: mov ah,4ch int 21h code ends end begin 求字符串长度的程序dseg segment maxlen db 80 actlen db ? string db 80 dup(?) mess db Please input a string:$ mess1 db 0ah,0dh,Chars :$ mess2 db 0ah,0dh,Digits:$ mess3 db 0ah,0dh,Others:$ char db ? digit db ? other db ? dseg ends prog

13、nam segment main proc far assume cs:prognam,ds:dseg start: push ds push ax mov ax,dseg mov ds,ax mov dx,offset mess mov ah,09h int 21h mov dx,offset maxlen mov ah,0ah int 21h mov di,offset string mov char,0 mov digit,0 mov other,0 next: mov al,di cmp al,0dh jz exit cmp al,30h jc next3 cmp al,3ah jc

14、next2 cmp al,41h jc next3 cmp al,5bh jc next1 cmp al,61h jc next3 cmp al,7bh jc next1 jmp next3 next1: inc char jmp next4 next2: inc digit jmp next4 next3: inc other next4: inc di jmp next exit: mov dx,offset mess1 mov ah,09h int 21h mov bl,char call show_msg mov dx,offset mess2 mov ah,09h int 21h m

15、ov bl,digit call show_msg mov dx,offset mess3 mov ah,09h int 21h mov bl,other call show_msg ret main endp show_msg proc near mov ch,4 rotate: mov cl,4 rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah jl printit add al,7h printit: mov dl,al mov ah,2 int 21h dec ch jnz rotate ret show_msg endp pro

16、gnam ends end start汇编语言程序设计源代码 -第七章 串操作程序设计例7-1 将数据段中SRC1为首地址的一组字节数据,传送到附加数据段中DEST1为首地址的内存区域,试编写程序。程序中的寄存器分配按照串操作指令的规定使用,以后的例题也是这样,不再特别说明。DATA SEGMENTSRC1 DB 89H,36H,0B7H,9AH,80H,0CEH,60H ;定义源字符串COUNT EQU $-SRC1 ;计算源字符串的长度DATA ENDSEXTR SEGMENTDEST1 DB COUNT DUP(?) ;定义目标串存储区域EXTR ENDSSTACK SEGMENT ST

17、ACKDB 200 DUP(?)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:EXTR,SS:STACK,CS:CODESTART: MOV AX,DATA MOV DS,AX MOV AX, EXTR MOV ES,AX LEA SI,SRC1 LEA DI,DEST1 MOV CX,COUNT CLD ;设置DF=0 REP MOVSB MOV AH,4CH INT 21HCODE ENDS END START 例7-2 将数据段中SRC为首地址的一组字节数据,向后移动4个字节单元后开始存放,试编写程序。DATA SEGMENTSRC DB 89H,36

18、H,0B7H,9AH,80H,0CEH,60HCOUNT EQU $-SRCDEST DB 4 DUP(0)DATA ENDSSTACK SEGMENT STACK DB 200 DUP(?)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART:MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,SRC ;设置SI的初值 ADD SI, COUNT-1 ;使SI指向源串的尾元素 LEA DI,DEST+3 ;使DI指向目的串的尾部 MOV CX,COUNT STD ;设置DF=1 REP

19、 MOVSB MOV AH,4CH INT 21HCODE ENDS END START 例7-3 数据段中有两个字符串,分别存放在以BUF1、BUF2为首地址的内存区域,编写程序比较这两个字符串是否相等,相等时在F单元存1,不相等时在F单元存-1。DATA SEGMENTBUF1 DB I like assemer ;定义字符串1COUNT1 EQU $-BUF1BUF2 DB I like assemer! ;定义字符串2COUNT2 EQU $-BUF2F DB ?DATA ENDSSTACK SEGMENT STACK DB 200 DUP(0)STACK ENDSCODE SEGME

20、NT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART: MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,BUF1 LEA DI,BUF2 MOV CX,COUNT1 MOV DX,COUNT2 CMP CX,DX JNZ NEXT CLD REPE CMPSB JNE NEXT MOV F,1 JMP QUITNEXT: MOV F,-1QUIT: MOV AH,4CH INT 21HCODE ENDS END START 例7-4 在STR为首地址的字符串中查找有没有空格字符。如果没有空格,在F单元存入-1;如果有空格,

21、在F单元存入找到的第一个空格的偏移地址。DATA SEGMENTSTR DB I love china ;定义字符串COUNT EQU $-STR ;计算字符串长度F DW -1 ;假设字符串中不存在空格DATA ENDSSTACK SEGMENT STACK DB 200 DUP(0)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART: MOV AX,DATA MOV DS,AX MOV ES,AX LEA DI,STR MOV CX,COUNT MOV AL, CLD REPNE SCASB JNE ET

22、DEC DI MOV F,DIET: MOV AH,4CH INT 21HCODE ENDS END START 例7-5 在STR为首地址的字符串中查找有没有空格字符。如果没有空格,在F单元存入-1;如果有空格,在F单元存入空格的个数。DATA SEGMENTSTR DB I love china ;定义字符串COUNT EQU $-STR ;计算字符串长度F DW -1 ;假设字符串中不存在空格DATA ENDSSTACK SEGMENT STACK DB 200 DUP(0)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS

23、:CODESTART: MOV AX,DATA MOV DS,AX MOV ES,AX LEA DI,STR MOV CX,COUNT MOV AL, CLD MOV BX,0 ;BX用于累计空格的个数LP: REPNE SCASB JNE NT ;字符串中没有空格后退出 INC BX JMP LPNT: CMP BX,0 ;判断字符串中有无空格 JE ET ;没有空格时转 MOV F,BX ;有空格时保存空格的个数ET: MOV AH,4CH INT 21HCODE ENDS END START 例7-6 在STR1为首地址的字符串中,查找有几个子字符串china,并将包含的子字符串的个数存

24、入F单元。DATA SEGMENTSTR1 DB I love china,china is a greate country COUNT1 EQU $-STR1 ;计算源串的字符串长度STR2 DB china COUNT2 EQU $-STR2 ;计算目的串子字符串长度COUNT EQU COUNT1-COUNT2+1 ;需要再源串中查找的次数F DW 0 DATA ENDSSTACK SEGMENT STACK DB 200 DUP(0)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART: MOV AX,

25、DATA MOV DS,AX MOV ES,AX CLD LEA SI,STR1 MOV BX,SILP: LEA DI,STR2 MOV CX,COUNT2 REPE CMPSB JE NT ;找到子字符串时转移 INC BX JMP ETNT: INC DX MOV BX,SIET: MOV SI,BX CMP BX,COUNT ;比较查找是否结束 JBE LP ;查找没有结束时转移 MOV F,DX MOV AH,4CH INT 21HCODE ENDS END START 例7-7 在以BUF1首地址的内存缓冲区中有一组压缩BCD码,将其转换成非压缩BCD码存放在以BUF2首地址的内存

26、区域,存放时将压缩BCD码的高4位存放在高地址处,低4位存放在低地址处。DATA SEGMENTBUF1 DB 79H,86H,24H,91H,82H,19H,43H COUNT EQU $-BUF1 BUF2 DB COUNT*2 DUP(?) DATA ENDSSTACK SEGMENT STACK DB 200 DUP(?)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART: MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,BUF1 LEA DI,BUF2 MOV DX,CO

27、UNT CLD LP: LODSB MOV BL,AL AND AL,0FH STOSB MOV CL,4 SHR BL,CL MOV AL,BL STOSB DEC DX JNZ LP MOV AH,4CH INT 21HCODE ENDS END START 例7- 8 有一组带符号数,已经按照由小到大的顺序存放在以BUF为首地址的内存区域,试编写程序将一个数据插入到适当的位置,使得该组数据仍然符合由小到大的顺序排列。DATA SEGMENTBUF DB -120,-89,-60,43,67,94,100,112 DB ? ;分配空间,存放移动的数据COUNT EQU $-BUF1 M D

28、B 80 ;待插入的数据DATA ENDSSTACK SEGMENT STACK DB 200 DUP(?)STACK ENDSCODE SEGMENT ASSUME DS:DATA,ES:DATA,SS:STACK,CS:CODESTART: MOV AX,DATA MOV DS,AX MOV ES,AX LEA SI,BUF MOV DI,SI MOV CX,COUNT CLD ;设置DF=0 MOV BL,MLP: CMP BL,SI JLE NT INC SI INC DI DEC CX JNZ LPNT: LODSB XCHG BL,AL STOSB DEC CX JNZ NT MO

29、V AH,4CH INT 21HCODE ENDS END START .MODELSMALL .DATA N = 80 BuffDB N, ?, N DUP(?) NumDW 36 DUP(0);每个字用于存放09,AZ出现的个数 .CODE .STARTUP LEADX, Buff MOVAH, 0AH INT21H;输入一个字符串 XORCH, CH MOVCL, Buff+1;CX=输入字符串的个数 LEASI, Buff+2 XORBX, BX .REPEAT MOVBL, SI;考虑下面的思考题 INCSI .IFBL=0 & BL=a & BL=A & BL=Z;分类统计AZ中的

30、每个字母的个数 SUBBL, A-10 ADDBX, BX INCNumBX .ENDIF .UNTILCXZ .EXIT 0 END /* Note:Your choice is C IDE */#include stdio.h#include string.hvoid main() void copystr(char *,char *,int); int m; char str120,str220; printf(n input string:); gets(str1); printf(which character that being to copy?); scanf(%d,&m);

31、if(strlen)(str1)m) printf(input error); else copystr(str1,str2,m); printf(result:%sn,str2); void copystr(char*p1,char*p2,int m)int n;n=0;while(nm-1)n+;p1+;while(*p1!=0)*p2=*p1;p1+;p2+;*p2=0;#include stdio.hvoid main() int i,k,m,n,num50,*p; printf(input number of person:n=); scanf(%d,&n); p=num; for(

32、i=0;in;i+) *(p+i)=i+1; i=0; k=0; m=0; while(mn-1) if(*(p+i)!=0) k+; if(k=3) *(p+i)=0; k=0; m+; i+; if(i=n) i=0; while(*p=0) p+; printf(The last one is No.%dn,*p);/* Note:Your choice is C IDE */#include stdio.hvoid main() int upper=0,lower=0,digit=0,space=0,other=0,i=0; char*p,s40; printf(input strin

33、g: ); while(si=getchar()!=n) i+; if(A=*p)&(*pZ) +upper; else if(a=*p)&(*p=z) +lower; else if(*p= ) +space; else if(*p=0) +digit; else +other; p+; printf(); /* Note:Your choice is C IDE */#include stdio.hvoid main() int sum_day(int,int); int leap(int year); int year,month,day,days; printf(请输入年月日:); s

34、canf(%d%d%d, &year,&month,&day); printf(%d/%d/%d,year,month,day); days=sum_day(month,day); if(leap(year)&month=3) days+=1; printf(这是本年的第 %d天.n,days); printf(星期%d,days%7);int sum_day(int month,int day)int day_tab12=31,28,31,30,31,30,31,31,30,31,30,31;int i;for(i=0;imonth;i+) day+=day_tabi; return(day

35、);int leap(int year)int leap;leap=year%4=0&year%100!=0|year%400=0;return(leap); CODE SEGMENTASSUME CS:CODESTART: MOV AH,02h MOV CX,15 MOV BL,10HLOO1: MOV BH,16LOOP2: MOV DL,BL INT 21H MOV DL,20h INT 21H INC BL DEC BH CMP BH,0 JNE LOOP2 MOV DL,0ah INT 21H MOV DL,0dh INT 21H LOOP LOO1EXIT: MOV AH,4CH

36、INT 21HCODE ENDS END START#include#includeint main(void) int i,d=0; char str8080,max80; gets(str0); strcpy(max,str0); printf(Input the char arry:n); for(i=0;strcmp(stri,stop)!=0;i+) d=strlen(stri);printf(第%d个字符串的长度为:%dn,d);gets(stri+1);if(strcmp(stri,stri+1)0) strcpy(max,stri+1);d=0; printf(The max

37、strings is:%sn,max);return 0;#include#includevoid main() int i,d,maxlen=0;char str80,max80; i=0;while(strcmp(str,STOP)!=0)d=0;gets(str);d=strlen(str);printf(第%d个字符串的长度为:%dn,i+1,d);if(d-maxlen0)strcpy(max,str);maxlen=strlen(str);i+; printf(最长的字符串为:%sn,max);#include stdio.hvoid main() int upper=0,lowe

38、r=0,digit=0,space=0,other=0,i=0; char *p,s40; printf(input string:); while(si=getchar()!=n) i+; p=&s0; while(*p!=n) if(A=*p)&(*p=Z) +upper; else if(a=*p)&(*p=z) +lower; else if(*p= ) +space; else if(*p=0) +digit; else +other; p+; printf(总长度为%dn字母长度为%dn数字长度%dn其他%d,lower+upper+space+digit+other,lower+upper,digit,other); #include int letter; /字母个数 int digit; /数字个数 int space; /空格个数 int others; /其它字母个数 void main() void count(char str); /统计个数的函数的声明 char s81; printf(请输

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!