MSIL指令集

2010年12月5日 发表评论 阅读评论

为方便查询,把MSIL指令集粘出来!同时简单介绍下MSIL概念。如果你把你的源代码编译成受控代码,编译器将把你的源代码转换为Microsoft中间语言(MSIL),这种代码将是不依赖于CPU的,而且能够高效的转换为本地代码。

MSIL拥有众多的指令,像loading、storing、initializing以及基于对象的方法调用还有算术逻辑运算、流控、直接内存存储和异常处理等。在代码执行之前,必须通过JIT编译器将MSIL转换为基于特定CPU的代码。

由于运行时为它所支持的每一种计算机体系结构都提供了一到多个JIT编译器,同样的MSIL指令集合能够被JIT编译并且在所有支持的体系结构上面执行。当编译器产生MSIL的同时,也产生元数据,元数据描述了代码中的类型,包括每一种类型的定义、每一种类型成员的签名、代码引用的成员以及在执行时运行时用到的其它数据。

代码和元数据都包括在一个PE文件中,这个PE文件基于并且扩展了已发布的Microsoft PE以及曾经用于执行信息的通用对象文件格式(Common Object File Format)(COFF)。PE这种文件格式,将有利于帮助操作系统识别CLR镜像。在文件中和MSIL一起存在的元数据将使得你的代码是自描述的,也就是说不再需要类型库或者IDL。在执行过程中,运行是根据需要从文件中定位和提取元数据。

MSIL Instruction Set

Base Instructions

Instruction

Description

Stack Transition

1

add

add two values, returning a new value

…, value1, value2->…, result

2

add.ovf.<signed>

add integer value with overflow check

…, value1, value2->…, result

3

and

bitwise AND

…, value1, value2 ->…, result

4

arglist

get argument list

… -> …, argListHandle

5

beq.<length>

branch on equal

…, value1, value2 -> …

6

bge.<length>

branch on greater than or equal to

…, value1, value2 -> …

7

bge.un.<length>

branch on greater/equal, unsigned or unordered

…, value1, value2 -> …

8

bgt.<length>

branch on greater than

…, value1, value2 -> …

9

bgt.un<length>

branch on greater than, unsigned or unordered

…, value1, value2 -> …

10

ble.<length>

branch on less than or equal to

…, value1, value2 -> …

11

ble..un<length>

branch on less/equal, unsigned or unordered

…, value1, value2 -> …

12

blt.<length>

branch on less than

…, value1, value2 -> …

13

blt.un.<length>

branch on less than, unsigned or unordered

…, value1, value2 -> …

14

bne.un<length>

branch on not equal or unorded

…, value1, value2 -> …

15

br.<length>

unconditional branch

…, -> …

16

break

breakpoint instruction

…, -> …

17

brfalse.<length>

branch on false, null, or zero

…, value -> …

18

brtrue.<length>

branch on non-false or non-null

…, value -> …

19

call

call a method

…, arg1, arg2 … argn -> …, retVal (not always returned)

20

calli

indirect method call

…, arg1, arg2 … argn, ftn -> …, retVal (not always returned)

21

ceq

compare equal

…, value1, value2->…, result

22

cgt

compare greater than

…, value1, value2->…, result

23

cgt.un

compare greater than, unsigned or unordered

…, value1, value2->…, result

24

ckfinite

check for a finite real number

…, value -> …, value

25

clt

compare less than

…, value1, value2->…, result

26

clt.un

compare less than, unsigned or unordered

…, value1, value2->…, result

27

conv.<to type>

data conversion

…, value -> …, result

28

conv.ovf<to type>

data conversion with overflow detection

…, value -> …, result

29

conv.ovf.<to type>.un

unsigned data conversion with overflow detection

…, value -> …, result

30

cpblk

copy data from memory to memory

…, destaddr, srcaddr, size -> …

31

div

divide values

…, value1, value2->…, result

32

div.un

divide integer values, unsigned

…, value1, value2->…, result

33

dup

duplicate the top value of the stack

…, value -> …, value, value

34

endfilter

end filter clause of SEH

…, value -> …

35

endfinally

end the finally or fault clause of exception block

… -> …

36

initblk

initialize a block of memory to a value

…, addr, value, size -> …

37

jmp

jump to method

… -> …

38

ldarg.<length>

load argument onto the stack

… -> …, value

39

ldarga.<length>

load an argument address

…, -> …, address of argument number argNum

40

ldc.<type>

load numeric constant

… -> …, num

41

ldftn

load method pointer

… -> …, ftn

42

ldind.<type>

load value indirect onto the stack

…, addr -> …, value

43

ldloc

load local variable onto the stack

… -> …, value

44

ldloca.<length>

load local variable address

… -> …, address

45

ldnull

load a null pointer

… -> …, null value

46

leave.<length>

exit a protected region of code

…, ->

47

localloc

allocate space in the local dynamic memory pool

size -> address

48

mul

multiply values

…, value1, value2 -> …, result

49

mul.ovf<type>

multiply integer values with overflow check

…, value1, value2 -> …, result

50

neg

negate

…, value -> …, result

51

nop

no operation

…, -> …,

52

not

bitwise complement

…, value -> …, result

53

or

bitwise OR

…, value1, value2 -> …, result

54

pop

remove the top element of the stack

…, value -> …

55

rem

compute the remainder

…, value1, value2 -> …, result

56

rem.un

compute integer remainder, unsigned

…, value1, value2 -> …, result

57

ret

return from method

retVal on callee evaluation stack (not always present) ->

…, retVal on caller evaluation stack (not always present)

58

shl

shift integer left

…, value, shiftAmount -> …, result

59

shr

shift integer right

…, value, shiftAmount -> …, result

60

shr.un

shift integer right, unsigned

…, value, shiftAmount -> …, result

61

starg.<length>

store a value in an argument slot

…, value -> …,

62

stind.<type>

store value indirect from stack

…, addr, val -> …

63

stloc

pop value from stack to local variable

…, value -> …

64

sub

substract numeric values

…, value1, value2 -> …, result

65

sub.ovf.<type>

substract integer values, checking for overflow

…, value1, value2 -> …, result

66

switch

table switch on value

…, value -> …,

67

xor

bitwise XOR

…, value1, value2 -> …, result

Object Model Instructions

Instruction

Description

Stack Transition

1

box

convert value type to object reference

…, valueType -> …, obj

2

callvirt

call a method associated, a runtime, with an object

…, obj, arg1, … argN -> …, returnVal (not always returned)

3

cast class

cast an object to a class

…, obj -> …, obj2

4

cpobj

copy a value type

…, destValObj, srcValObj -> …,

5

initobj

Initialize a value type

…,addrOfValObj -> …,

6

isinst

test if an object is is an instance of a class or interface

…, obj -> …, result

7

ldelem.<type>

load an element fo an array

…, array, index -> …, value

8

ldelema

load address of an element of an array

…, array, index -> …, address

9

ldfld

load field of an object

…, obj -> …, value

10

ldflda

load field address

…, obj -> …, address

11

ldlen

load the length of an array

…, array -> …, length

12

ldobj

copy value type to the stack

…, addrOfValObj -> …, valObj

13

ldsfld

load static field of a class

…, -> …, value

14

ldsflda

load static field address

…, -> …, address

15

ldstr

load a literal string

…, -> …, string

16

ldtoken

load the runtime representation of metadata token

… -> …, RuntimeHandle

17

ldvirtfn

load a virtual method pointer

… object -> …, ftn

18

mkrefany

push a typed reference on the stack

…, ptr -> …, typedRef

19

newarr

Create a zero-base, on-dimensional array

…, numElems -> …, array

20

newobj

create a new object

…, arg1, … argN -> …, obj

21

refanytype

load the type out of a typed reference

…, TypedRef -> …, type

22

refanyval

load the address out of a typed reference

…, TypedRef -> …, address

23

rethrow

rethrow the current exception

…, -> …,

24

sizeof

load the size in bytes of a value type

…, -> …, size (4 bytes, unsigned)

25

stelem.<type>

store an element of an array

…, array, index, value -> …,

26

stfld

store into a field of an object

…, obj, value -> …,

27

stobj

store a value type from the stack into memory

…, addr, valObj -> …,

28

stsfld

store a static field of class

…, val -> …,

29

throw

throw an exception

…, object -> …,

30

unbox

convert boxed value type to its raw form

 


转载请注明来自:[闪电博客]http://shandian.biz/102.html

分类: 电脑知识 标签:
  1. Dozer
    2011年1月18日10:02 | #1

    学习了~~~