编写程序,计算下面函数的值并输出。

muiti-case-simple.png

首先定义 vcIO.inc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

.686         ;使用686指令集

.MODEL flat, stdcall       ;使用flat平坦内存模式

option casemap : none      ; 大小写不敏感



;函数声明

printf	 PROTO C : dword,:vararg  ;vararg参数:变参,参数个数不确定

scanf	 PROTO C : dword,:vararg  ;dword参数 :格式描述串的有效地址。

_getch    PROTO C : vararg         ;注意:所有的参数都是dword型!

主要程序
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

include vcIO.inc

.data

	prompt      byte  'Enter a integers  X  : ',0	  ;//字符串

	frmStr	    byte	 '%s',0ah,0		  ;//字符串的输出格式,0ah:“\n”

	frmStr1	    byte	 '%d',  0		  ;//数据的输入格式

	frmStr2	    byte	 '%d',0ah,0		  ;//数字的输出,0ah:“\n”

	x           dword     ?



.code

judge proto stdcall arg1:dword              ;子函数定义

	main proc

		pushad

			invoke printf,offset frmStr,offset prompt

			invoke scanf,offset frmStr1,offset x

			invoke judge,x

		popad

		invoke  _getch

		ret 0

	main endp



	judge proc stdcall arg1:dword      ;子函数实现

		mov eax,arg1

		cmp eax,0            ; eax 大于0 跳到 xxx

		jge xxx   

		imul eax,2

		jmp done

	xxx: 

		cmp eax,10      

		jg xxxx          

		imul eax,3		;eax 小于等于10

		jmp done

	xxxx:

		imul eax,4

		jmp done

	done:

		invoke printf,offset frmStr2,eax

		ret 

	judge endp



end main

运行结果

批注 2019-04-24 225734.png