MISL深入学习(2) 简单数组的使用
2008-08-18 17:02
393 查看
Code
1 .assembly extern mscorlib{}
2 .assembly Arr
3 {
4 .ver 1:0:1:0
5 }
6
7 .module Arr.exe
8
9 .method static void Main() cil managed
10 {
11 .maxstack 30
12 .entrypoint
13 .locals init(int32 Counter,int32[] intArr)
14
15
16 ldc.i4 10
17 dup /*dup指令"复制"计算栈中顶端的值,并存贮于计算栈顶*/
18 stloc Counter
19 newarr int32 /*于托管栈中分配新数组,数组引用类型.并将引用地址返回栈顶*/
20 stloc intArr /*将引用地址赋予intArr*/
21
22 /*
23 allocate and zero-initialize a zero-based, one-dimensional
24 array. The top of the evaluation stack specifies the total
25 number of elements in the array, and the instruction itself
26 specifies the data type of the elements.
27 */
28
29 //循环
30 Loop:
31 ldloc Counter
32 brfalse finished /**/
33
34 //自减
35 ldloc Counter
36 ldc.i4.1
37 sub
38 dup
39 call void[mscorlib]System.Console::WriteLine(int32)
40 stloc Counter
41
42 ldloc intArr //数组引用
43 ldloc Counter //数组索引
44 dup
45 ldc.i4.4
46 mul
47 stelem.i4
48 br.s Loop
49
50 /*
51 stloc是store local variable
52 ldloc是load local variable
53 */
54
55
56 /*两个数组操作指令的说明*/
57 /*
58 stelem.<typeSuffix> stelem 是 store element store
59 an item into an element of an array, with type and
60 range checking. The type is specified by the suffix
61 of the instruction and (for stelem.ref) the object
62 itself; any mismatch results in a System.ArrayTypeMismatchException.
63 The top of the stack contains the value to be stored.
64 The second item on the stack is the index, an unsigned
65 integer. A System.IndexOutOfRangeException will be thrown
66 if the index is larger than the size of the array. The
67 third item on the stack is the array itself, which will
68 result in a System.NullReferenceException if it is null.
69 To store an unboxed value type into an array, use ldelema
70 and stobj rather than stelem.<typeSuffix>.
71 */
72
73 /*
74 ldelem.<exTypeSuffix> ldelem 是 load element
75 load an element out of a zero-based, one-dimensional
76 array,with range and type checking. The type of the
77 array must match the suffix of the instruction or a
78 System.ArrayTypeMismatchException is raised. An out of
79 range subscript results in a System.IndexOutOfRangeException,
80 while an attempt to access an element of the null array results
81 in a System.NullReferenceException.
82 栈顶储存将提取数组的元素位置索引,栈顶次位储存数组引用地址
83 */
84
85
86 finished:
87 ldstr "finished!"
88 call void[mscorlib]System.Console::WriteLine(string)
89
90 /*输出数组intArr中索引为3的值*/
91 ldloc intArr
92 ldc.i4.3
93 ldelem.i4 /*看前面的注释*/
94 call void[mscorlib]System.Console::WriteLine(int32)
95
96 ldloc intArr
97 ldc.i4.2
98 ldelem.i4 /*看前面的注释*/
99 call void[mscorlib]System.Console::WriteLine(int32)
100
101
102 ldloc intArr
103 ldc.i4.1
104 ldelem.i4 /*看前面的注释*/
105 call void[mscorlib]System.Console::WriteLine(int32)
106
107 ret
108 }
1 .assembly extern mscorlib{}
2 .assembly Arr
3 {
4 .ver 1:0:1:0
5 }
6
7 .module Arr.exe
8
9 .method static void Main() cil managed
10 {
11 .maxstack 30
12 .entrypoint
13 .locals init(int32 Counter,int32[] intArr)
14
15
16 ldc.i4 10
17 dup /*dup指令"复制"计算栈中顶端的值,并存贮于计算栈顶*/
18 stloc Counter
19 newarr int32 /*于托管栈中分配新数组,数组引用类型.并将引用地址返回栈顶*/
20 stloc intArr /*将引用地址赋予intArr*/
21
22 /*
23 allocate and zero-initialize a zero-based, one-dimensional
24 array. The top of the evaluation stack specifies the total
25 number of elements in the array, and the instruction itself
26 specifies the data type of the elements.
27 */
28
29 //循环
30 Loop:
31 ldloc Counter
32 brfalse finished /**/
33
34 //自减
35 ldloc Counter
36 ldc.i4.1
37 sub
38 dup
39 call void[mscorlib]System.Console::WriteLine(int32)
40 stloc Counter
41
42 ldloc intArr //数组引用
43 ldloc Counter //数组索引
44 dup
45 ldc.i4.4
46 mul
47 stelem.i4
48 br.s Loop
49
50 /*
51 stloc是store local variable
52 ldloc是load local variable
53 */
54
55
56 /*两个数组操作指令的说明*/
57 /*
58 stelem.<typeSuffix> stelem 是 store element store
59 an item into an element of an array, with type and
60 range checking. The type is specified by the suffix
61 of the instruction and (for stelem.ref) the object
62 itself; any mismatch results in a System.ArrayTypeMismatchException.
63 The top of the stack contains the value to be stored.
64 The second item on the stack is the index, an unsigned
65 integer. A System.IndexOutOfRangeException will be thrown
66 if the index is larger than the size of the array. The
67 third item on the stack is the array itself, which will
68 result in a System.NullReferenceException if it is null.
69 To store an unboxed value type into an array, use ldelema
70 and stobj rather than stelem.<typeSuffix>.
71 */
72
73 /*
74 ldelem.<exTypeSuffix> ldelem 是 load element
75 load an element out of a zero-based, one-dimensional
76 array,with range and type checking. The type of the
77 array must match the suffix of the instruction or a
78 System.ArrayTypeMismatchException is raised. An out of
79 range subscript results in a System.IndexOutOfRangeException,
80 while an attempt to access an element of the null array results
81 in a System.NullReferenceException.
82 栈顶储存将提取数组的元素位置索引,栈顶次位储存数组引用地址
83 */
84
85
86 finished:
87 ldstr "finished!"
88 call void[mscorlib]System.Console::WriteLine(string)
89
90 /*输出数组intArr中索引为3的值*/
91 ldloc intArr
92 ldc.i4.3
93 ldelem.i4 /*看前面的注释*/
94 call void[mscorlib]System.Console::WriteLine(int32)
95
96 ldloc intArr
97 ldc.i4.2
98 ldelem.i4 /*看前面的注释*/
99 call void[mscorlib]System.Console::WriteLine(int32)
100
101
102 ldloc intArr
103 ldc.i4.1
104 ldelem.i4 /*看前面的注释*/
105 call void[mscorlib]System.Console::WriteLine(int32)
106
107 ret
108 }
相关文章推荐
- C#委托的简单学习:定义委托和使用、Func<int f1,out r1>、给自定义的类或数组排序(冒泡排序)
- PHP 学习笔记 - - - 简单方法的使用 (数组)
- JavaScript学习笔记之循环在遍历数组的简单使用
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
- json数组的简单使用
- [c专家编程学习] 深入数组1
- 【Java学习笔记】数组使用
- vagrant简单学习使用
- hadoop生态系统学习之路(五)hbase的简单使用
- 深入分析JavaWeb 2 -- Tomcat服务器学习和使用
- 学习笔记 Tianmao 篇 OkHttp 网络的使用的简单封装 获取Json用GSON来解析
- 【Dubbo基础】dubbo学习过程、使用经验分享及实现原理简单介绍
- EJB中JNDI的逻辑名的使用及部署_{EJB之无状态会话Bean简单应用-学习与实践}续(inber原作)
- HTML--1.学习使用简单的标签
- maven系列学习之二:maven初体验-简单使用maven进行测试,编译、打包和运行
- ThinkPHP框架学习之使用数组进行查询
- 数据结构学习笔记(3)_使用数组实现简单线性表功能
- Spark学习使用笔记 - Scala篇(2)- 数组
- Java中数组的简单使用
- java学习二十七 数组的使用