GithubHelp home page GithubHelp logo

ilcalculator's Introduction

ILCalculator

A very simple ILCalculator written in pure IL

.assembly extern mscorlib{}
.assembly Calculator{}
.module Calculator.dll
 
.namespace Calculator
{
	.class public abstract sealed auto ansi beforefieldinit Calculator extends [mscorlib]System.Object
	{
	        .method public hidebysig specialname rtspecialname instance void .ctor() cil managed
		{
		  .maxstack 8

		  IL_0000: ldarg.0      
		  IL_0001: call instance void [mscorlib]System.Object::.ctor()
		  IL_0006: nop
		  IL_0007: ret
		}
		
		.method public hidebysig static void Execute() cil managed
		{
			.maxstack 8
			.locals init(
				[0] int32 firstValue,
				[1] int32 secondValue,
				[2] string character,
				[3] int32 result
			)
			
			ldstr "Enter the first number: "
			call void [mscorlib]System.Console::Write(string)
			call string [mscorlib]System.Console::ReadLine()
			call int32 [mscorlib]System.Int32::Parse(string)
			stloc.0
			
			ldstr "Enter the second number: "
			call void [mscorlib]System.Console::Write(string)
			call string [mscorlib]System.Console::ReadLine()
			call int32 [mscorlib]System.Int32::Parse(string)
			stloc.1
			
			ldstr "Enter the character: "
			call void [mscorlib]System.Console::Write(string)
			call string [mscorlib]System.Console::ReadLine()
			stloc.2
			
			ldloc.2
			ldstr "+"
			call bool [mscorlib]System.String::op_Equality(string, string)
			brfalse.s IL_0007
			
			IL_0001: ldloc.0
			IL_0002: ldloc.1
 			IL_0003: add
			IL_0006: call void Calculator.Calculator::WriteResult(int32)
			br IL_0102
			
			IL_0007: ldloc.2
			ldstr "-"
			call bool [mscorlib]System.String::op_Equality(string, string)
			brfalse.s IL_0014 
			
			IL_0008: ldloc.0
			IL_0009: ldloc.1
 			IL_0010: sub
			IL_0013: call void Calculator.Calculator::WriteResult(int32)
			br IL_0102
			
			IL_0014: ldloc.2
			ldstr "*"
			call bool [mscorlib]System.String::op_Equality(string, string)
			brfalse.s IL_0021 
			
			IL_0015: ldloc.0
			IL_0016: ldloc.1
 			IL_0017: mul
			IL_0020: call void Calculator.Calculator::WriteResult(int32)
			br IL_0102
			
			IL_0021: ldloc.2
			ldstr "/"
			call bool [mscorlib]System.String::op_Equality(string, string)
			brfalse.s IL_0100 
			
			IL_0022: ldloc.0
			IL_0023: ldloc.1
 			IL_0024: div
			IL_0027: call void Calculator.Calculator::WriteResult(int32)
			br IL_0102
			
			IL_0100: ldstr "Undefined character"
			IL_0101: call void [mscorlib]System.Console::WriteLine(string)
			IL_0102: ret
		}
		
		.method private hidebysig static void WriteResult(int32 result) cil managed
		{
			IL_0001: ldstr "Result is {0}"
			IL_0002: ldarg.0
			IL_0003: box [mscorlib]System.Int32
			IL_0004: call string [mscorlib]System.String::Format(string, object)
			IL_0005: call void [mscorlib]System.Console::WriteLine(string)
			IL_0006: ret
		}
	}
}

ilcalculator's People

Contributors

skyuzii avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.