汇编编程实例.doc
《汇编编程实例.doc》由会员分享,可在线阅读,更多相关《汇编编程实例.doc(187页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、汇编编程实例.txt你妈生你的时候是不是把人给扔了把胎盘养大?别把虾米不当海鲜。别把虾米不当海鲜。案例1判断闰年程序data segment ;定义数据段 infon db 0dh,0ah,Please input a year: $ Y db 0dh,0ah,This is a leap year! $ N db 0dh,0ah,This is not a leap year! $ w dw 0 buf db 8 db ? db 8 dup(?)data endsstack segment stack db 200 dup(0)stack endscode segment assume ds
2、:data,ss:stack,cs:code start:mov ax,data mov ds,ax lea dx,infon ;在屏幕上显示提示信息 mov ah,9 int 21h lea dx,buf ;从键盘输入年份字符串 mov ah,10 int 21h mov cl, buf+1 lea di,buf+2 call datacate call ifyears jc a1 lea dx,n mov ah,9 int 21h jmp exit a1: lea dx,y mov ah,9 int 21h exit: mov ah,4ch int 21h datacate proc ne
3、ar; push cx; dec cx lea si,buf+2 tt1: inc si loop tt1 ;lea si,cxdi pop cx mov dh,30h mov bl,10 mov ax,1 l1: push ax sub byte ptr si,dh mul byte ptr si add w,ax pop ax mul bl dec si loop l1 ret datacate endp ifyears proc near push bx push cx push dx mov ax,w mov cx,ax mov dx,0 mov bx,4 div bx cmp dx,
4、0 jnz lab1 mov ax,cx mov bx,100 div bx cmp dx,0 jnz lab2 mov ax,cx mov bx,400 div bx cmp dx,0 jz lab2 lab1: clc jmp lab3 lab2: stc lab3: pop dx pop cx pop bx ret ifyears endpcode ends end start案例2产生随机数并运算的程序DATA SEGMENT CC DB + ww db - GG DB = II DB 0DH,0AH,$ AA DB 5 DUP(?) www dw 0 ghh db 0,0dh,0ah
5、,$ bnm dw 0DATA ENDSSTACK SEGMENT DB 200 DUP(0)STACK ENDSCODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACKSTART: MOV AX,DATA MOV DS,AX MOV CX,20 CALL RAND ;产生一随机数 CALL MCAT ;将随机数转换为16进制表示的ASCII码字符 MOV AX,BX PUSH AX CMP www,0 ;WWW=0? JE A1 ;执行+ CMP www,1 ;www=1? JE A2 ;执行- A1: MOV DL,CC ;显示+ MOV AH,2 INT
6、21H CALL RAND ;产生另一随机数 add bx,0fh CALL MCAT ;将随机数转换为16进制表示的ASCII码字符 MOV DL,GG ;显示= MOV AH,2 INT 21H POP AX ADD AX,BX cmp ax,0 jne yjw1 lea dx,ghh mov ah,9 int 21h jmp qq1 yjw1: JMP B1 A2: MOV DL,WW ;显示- MOV AH,2 INT 21H mov cx,65535 mai1: loop mai1 CALL RAND1 CALL MCAT MOV DL,GG MOV AH,2 INT 21H POP
7、 AX Sbb AX,BX cmp ax,0 jne yjw2 lea dx,ghh mov ah,9 int 21h jmp qq1 yjw2: JMP B1 B1: MOV BX,AX CALL MCAT lea DX,II MOV AH,9 INT 21H QQ1: MOV AH,4CH INT 21HMCAT PROC ;将随机数转换为16进制表示的ASCII码字符子程序 PUSH AX push bx PUSH CX PUSH DX CMP BX,9 JA S1 PUSH AX PUSH BX PUSH CX PUSH DX mov ax,bx mov bl,5 div bl cmp
8、 ah,3 jae vb1 mov www,1 jmp vn1 vb1:mov www,0 vn1:pop dx pop cx pop bx pop ax ADD BL,30H MOV AA,BL MOV AA+1,$ LEA DX,AA MOV AH,9 INT 21H JMP s3 s1:MOV CL,4 MOV AL,0 PUSH BX SHL BX,CL CMP BH,9 JBE V1 SUB BH,9 ADD BH,40H JMP MM1 V1:ADD BH,30H MM1:MOV AA,BH POP BX AND BL,0FH PUSH AX PUSH BX PUSH CX PUS
9、H DX mov ax,bx mov bl,5 div bl cmp ah,3 jae vb2 mov www,1 jmp vn2 vb2:mov www,0 vn2:pop dx pop cx pop bx pop ax CMP BL,9 JBE TT1 SUB BL,9 ADD BL,40H JMP RR1TT1: ADD BL,30HRR1: MOV AA+1,BL MOV AA+2,$ LEA DX,AA MOV AH,9 INT 21H s3:POP DX POP CX POP BX POP AX RETMCAT ENDPRAND PROC PUSH CX PUSH DX PUSH
10、AX STI MOV AH,0 ;读时钟计数器值 INT 1AH MOV AX,DX ;清高6位 AND AH,3 MOV DL,101 ;除101,产生0100余数 DIV DL MOV BL,AH ;余数存BX,作随机数 POP AX POP DX POP CX RETRAND ENDPRAND1 PROC PUSH CX PUSH DX PUSH AX STI MOV AH,0 INT 1AH MOV ax,cx AND AH,3 MOV DL,101 DIV DL MOV BL,AH POP AX POP DX POP CX RETRAND1 ENDPCODE ENDS END STA
11、RT 案例3计算平台长度程序data segmentobf db * welcome you !*,0dh,0ah db input data:,$a0 db ?a1 db ?b0 db ?b1 db ?a db ?b db ?data endsstack segment stack db 200 dup(0) stack endscode segment assume cs:code, ds:data,ss:stackmain:mov ax, data mov ds, ax mov ah, 9 lea dx, obf int 21h inc dx mov dl, 13 mov ah, 2 i
12、nt 21h mov dl,10 int 21h mov ah,1 int 21h cmp al, 13 jz lab1 mov a0, al mov a, al mov a1, 1x1: mov ah, 1 int 21h cmp al, 13 jz lab1 mov b, al mov bl, b cmp bl, a jnz x2 add a1, 1 jmp x1x2: mov b0, bl mov b1, 1x3: mov ah, 1 int 21h mov a, al cmp bl,a jnz x4 add b1,1 jmp x3x4: mov cl, b1 cmp cl, a1 jb
13、 y1 mov cl, b0 mov a0, cl mov cl, b1 mov a1,cl y1: cmp al, 13 jz lab1 mov b0, al mov b1, 1 mov b, al mov bl, b jmp x3lab1: mov ah, 2 mov dl,13 int 21h mov dl,10 int 21h cmp a1,10 jb z1 mov ah,0 mov al, a1 mov bl, 10 div bl add ax, 3030h mov bx, ax mov ah, 2 mov dl, bl int 21h mov dl, bh int 21h jmp
14、z2z1: add a1, 30h mov dl, a1 int 21h sub a1,30hz2: mov ah,2 mov dl, 13 int 21h mov dl, 10 int 21h mov cx, 0 mov cl, a1 mov ah, 2m: mov dl,a0 int 21h loop m mov ah, 4ch int 21hcode ends end main案例4加减乘除四则运算B_P EQU BYTE PTRW_P EQU WORD PTRD_P EQU DWORD PTRCODE SEGMENTASSUME CS:CODE,DS:CODE ORG 100H;主程序
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汇编 编程 实例
限制150内