# include<stdio.h> void main() { __asm { DATA SEGMENT STRING1 DB 0DH,0AH,"Please input the first numbers:",0DH,0AH,"$" STRING2 DB 0DH,0AH,"Please input the second numbers:",0DH,0AH,"$" NUM1 DW 0 NUM2 DW 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,DATA MOV DS,AX LEA DX,STRING1 ;9号功能,显示字符串1输入第一个数 MOV AH,09H INT 21H LP: MOV AH,1 INT 21H CMP AL,0DH ;当输入的字符为回车结束数据输入 JZ NEXT SUB AL,30H MOV AH,0 MOV CX,AX MOV BX,10 MOV AX,NUM1 MUL BX ADD AX,CX MOV NUM1,AX JMP LP NEXT: LEA DX,STRING2 ;9号功能,显示字符串2输入第二个数 MOV AH,09H INT 21H LP1: MOV AH,1 INT 21H CMP AL,0DH JZ NEXT1 ;;当输入的字符为回车结束数据输入 SUB AL,30H MOV AH,0 MOV CX,AX MOV BX,10 MOV AX,NUM2 MUL BX ADD AX,CX MOV NUM2,AX JMP LP1 NEXT1: CALL DOO ;调用换行子程序 CALL A ;调用加法子程序 CALL DOO CALL B ;调用减法子程序 CALL DOO CALL C ;调用乘法子程序 CALL DOO CALL D ;调用换行子程序 MOV AH,4CH ;返回DOS INT 21H A PROC NEAR ;加法子程序 MOV DX,NUM1 CALL PRINT ;调用数据以十进制输出子程序,把NUM1以十进制形式输出 MOV DL,"+" CALL STDOUT ;调用输出子程序,把+号输出 MOV DX,NUM2 CALL PRINT MOV DL,"=" ;调用输出子程序,把=号输出 CALL STDOUT MOV AX,NUM1 ADD AX,NUM2 MOV DX,AX CALL PRINT RET A ENDP B PROC NEAR ;减法子程序 MOV DX,NUM1 CALL PRINT MOV DL,"-" CALL STDOUT MOV DX,NUM2 CALL PRINT MOV DL,"=" CALL STDOUT MOV AX,NUM1 MOV BX,NUM2 SUB AX,BX MOV DX,AX CALL PRINT RET B ENDP C PROC NEAR ;乘法子程序 MOV DX,NUM1 CALL PRINT MOV DL,"*" CALL STDOUT MOV DX,NUM2 CALL PRINT MOV DL,"=" CALL STDOUT MOV AX,NUM1 MOV DX,0 MUL NUM2 MOV DX,AX CALL PRINT RET C ENDP D PROC NEAR ;除法子程序 MOV DX,NUM1 CALL PRINT MOV DL,"/" CALL STDOUT MOV DX,NUM2 CALL PRINT MOV DL,"=" CALL STDOUT MOV DX,0 MOV AX,NUM1 DIV NUM2 MOV DX,AX CALL PRINT RET D ENDP PRINT PROC NEAR ;数据以十进制输出子程序 PUSH DX PUSH AX PUSH CX PUSH BX MOV CX,0 DO:MOV AX,DX MOV DX,0 MOV BX,10 DIV BX XCHG AX,DX ADD AL,30H PUSH AX INC CX CMP DX,0 JNZ DO DO1:POP AX MOV DL,AL CALL STDOUT LOOP DO1 POP BX POP CX POP AX POP DX RET PRINT ENDP STDOUT PROC NEAR ;输出子程序 MOV AH,2 INT 21H RET STDOUT ENDP DOO PROC NEAR ;换行子程序 MOV AH,02H MOV DL,0DH INT 21H MOV AH,02H MOV DL,0AH INT 21H RET DOO ENDP CODE ENDS END START } }
如上面的程序,编译的时候会报错。
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(6): error C2400: “操作码”中的内联汇编语法错误;找到“SEGMENT”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(7): error C2400: “操作码”中的内联汇编语法错误;找到“DB”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(7): error C2015: 常量中的字符太多
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(8): error C2400: “操作码”中的内联汇编语法错误;找到“DB”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(8): error C2015: 常量中的字符太多
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(9): error C2400: “操作码”中的内联汇编语法错误;找到“DW”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(10): error C2400: “操作码”中的内联汇编语法错误;找到“DW”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(11): error C2400: “操作码”中的内联汇编语法错误;找到“ENDS”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(12): error C2400: “操作码”中的内联汇编语法错误;找到“SEGMENT”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(13): warning C4405: “CS”: 标识符是保留字
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(13): error C2400: “操作码”中的内联汇编语法错误;找到“CS”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(14): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(30): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(33): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(50): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(53): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(68): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(69): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(73): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(77): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(78): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(82): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(83): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(84): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(88): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(92): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(93): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(98): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(99): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(100): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(104): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(108): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(114): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(115): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(116): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(120): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(125): error C2443: 操作数大小冲突
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(130): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(131): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(156): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(157): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(161): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(163): error C2400: “操作码”中的内联汇编语法错误;找到“PROC”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(171): error C2400: “操作码”中的内联汇编语法错误;找到“ENDP”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(172): error C2400: “操作码”中的内联汇编语法错误;找到“ENDS”
1>d:\documents\visual studio 2010\projects\调试1\调试1\调试1.cpp(173): error C2400: “操作码”中的内联汇编语法错误;找到“START”
谁知道该怎么样嵌套。
10
20
#pragma option -N- //-- #include <conio.h> #include <dos.h> #include <stdio.h> //-- #define YES 1 #define NO 0 #define CURSOR_MOVE 1 #define LEFT_DOWN 2 #define LEFT_UP 4 #define RIGHT_DOWN 8 #define RIGHT_UP 16 int MouseActive=NO,MouseMask,MouseButton,MouseX,MouseY; //-- void far mscall() { asm { push ds push si xor si,si mov ds,si mov si,[0x40E] mov ds,si cmp ax,MouseMask jne changed cmp bx,MouseButton jne changed cmp cx,MouseX jne changed cmp dx,MouseY je nochange } changed: asm { mov MouseMask,ax mov MouseButton,bx mov MouseX,cx mov MouseY,dx mov MouseActive,YES jmp end } nochange: asm { mov MouseActive,NO } end: asm { pop si pop ds } } //-- void MsLinkUserCall() { union REGS r; struct SREGS sr; *((int *)(0x0000040E))=FP_SEG(&MouseActive); r.x.ax=0x0C; r.x.cx=0x001F; r.x.dx=FP_OFF(mscall); sr.es=FP_SEG(mscall); int86x(0x33,&r,&r,&sr); } //-- int MsInstall() { void far *address; union REGS regs; address=getvect(0x33); if((address==NULL)||(*(unsigned char *)address==0xCF)) return 0; else { regs.x.ax=0; int86(0x33,®s,®s); return regs.x.ax; } } //-- void MsShow() { union REGS regs; regs.x.ax=1; int86(0x33,®s,®s); } //-- void MsHide() { union REGS regs; regs.x.ax=2; int86(0x33,®s,®s); } //-- void MsSetLoc(x,y) unsigned int x,y; { union REGS regs; regs.x.ax=4; regs.x.cx=x; regs.x.dx=y; int86(0x33,®s,®s); } //-- void MsSetHoriLimit(l,r) unsigned int l,r; { union REGS regs; regs.x.ax=7; regs.x.cx=l; regs.x.dx=r; int86(0x33,®s,®s); } //-- void MsSetVertLimit(t,b) unsigned int t,b; { union REGS regs; regs.x.ax=8; regs.x.cx=t; regs.x.dx=b; int86(0x33,®s,®s); } //-- void main() { if (!MsInstall()) { printf("I need a mouse.\n"); return; } clrscr(); MsLinkUserCall(); MsSetHoriLimit(0,638); MsSetVertLimit(0,192); MsSetLoc(0,0); MsShow(); while (1) { if (kbhit()) { if (getch()==27) break; } if (MouseActive==YES) { if (MouseMask&LEFT_DOWN) { MsHide();printf(" LEFT_DOWN");MsShow(); } if (MouseMask&LEFT_UP) { MsHide();printf(" LEFT_UP");MsShow(); } if (MouseMask&RIGHT_DOWN) { MsHide();printf(" RIGHT_DOWN");MsShow(); } if (MouseMask&RIGHT_UP) { MsHide();printf(" RIGHT_UP");MsShow(); } if (MouseButton&1) { MsHide();printf(" LEFT_DRAG");MsShow(); } if (MouseButton&2) { MsHide();printf(" RIGHT_DRAG");MsShow(); } if (MouseMask&CURSOR_MOVE) { MsHide();printf(" MOVE_TO(%3d,%3d)",MouseX,MouseY);MsShow(); } MsHide();printf("\n");MsShow(); MouseActive=NO; } } MsHide(); MsInstall(); }
5
项目、属性、配置属性、C/C++、输出文件、汇编程序输出:程序集、机器码和源代码(/Facs)
在重新编译,查看生成的.asm文件内容。
5