none
Assembly code RRS feed

  • Question

  • Hi, I would really like an answer to this question. I would like to know what a very low-level runtime would look like if it was written in assembly. I would like to know what adding local variables to the stack, adding values to those variables (integer values, char values, string values, floating-point values, and arrays), adding/subtracting/multiplying/dividing those values (except for string and char values), executing the IL instructions, etc. would look like in assembly. Could you please try to include as much source code as possible? Any sample would be greatly appreciated!

    Thanks!!

    Note: Any answer to one of these things is all you need to answer if that is all you know.

    * I know C# and how runtimes work


    Nevin Janzen (Visit my Website)
    If this post answers your question, please click Propose As Answer. If this post is helpful, please click Vote As Helpful.



    Tuesday, April 24, 2012 11:25 PM

Answers

All replies

  • BTW, This generally doesn't have much to do with the CLR, but with runtimes in general.


    Nevin Janzen (Visit my Website)
    If this post answers your question, please click Propose As Answer. If this post is helpful, please click Vote As Helpful.

    Wednesday, April 25, 2012 1:14 AM
  • You can go to this webpage to see sample of assembly language

    http://msdn.microsoft.com/en-us/library/y8b57x4b.aspx

    You can find many examples of assembly language code by going to www.intel.comand looking at there microprocessor programming guide.

    It real has become obsolete to program in assembly language since the language compiler have become very efficient in optimzing the code.  T

    The Unix operating system (1972) was written in C language and there is no real runtime assmebly language routines.  The C language compiler in unix is writen in C language.  Yes C language is written in C language.  To develope Unix on any processor you one have to develope a small number of low level core functions in asembly language.  With these core function in place you can execute the Basic C language compiler.  Once you have the C language compiler running you can write all your code in C language including the Unix operating system and the more complicated C Language library functions.  There is no need to write run time assembly code.


    jdweng

    Wednesday, April 25, 2012 3:00 AM
  • "BTW, This generally doesn't have much to do with the CLR, but with runtimes in general."

    "Runtimes" is a bit vague, the Visual C++ compiler also uses the notion of runtime to denote the library that contains the standard C functions and some bits of functionality that deal with program startup, exception handling, RTTI etc. CLR on the other hand is way more complex, partly because it has to compile the IL code to x86 assembly code at runtime.

    "I would like to know what a very low-level runtime would look like if it was written in assembly"

    If I understand correctly you are asking "how to write a runtime like CLR in assembly". Like Joel said already, nobody is writing that much code in assembly anymore these days. Even if someone would do the source code required for a runtime of CLR's complexity will be huge, way too huge to fit in a forum post.

    "I would like to know what adding local variables to the stack, adding values to those variables (integer values, char values, string values, floating-point values, and arrays), adding/subtracting/multiplying/dividing those values (except for string and char values),"

    In particular that's the job of a "compiler", not of a "runtime". The compiler itself is a highly complex piece of code.

    "executing the IL instructions"

    IL instructions aren't executed, CLR is not an interpreter. A whole IL function is compiled to x86 code and then that code is executed.

    "Any sample would be greatly appreciated!"

    The closest thing to such a sample would be SSCLI: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14124

    Wednesday, April 25, 2012 6:34 AM
    Moderator
  • " "Runtimes" is a bit vague, the Visual C++ compiler also uses the notion of runtime to denote the library that contains the standard C functions and some bits of functionality that deal with program startup, exception handling, RTTI etc. CLR on the other hand is way more complex, partly because it has to compile the IL code to x86 assembly code at runtime. "

    I am sorry if I was not too clear. What I mean by 'runtime' is the operations that manage the running executable, kind of like the CLR.

    If I understand correctly you are asking "how to write a runtime like CLR in assembly". "

    What I am looking for are simple assembly code samples that show how to manage simple variables in a program when it is running. Basically, I want to write a relatively simple runtime, or 'VM', that manages the IL and memory and does other operations when the executable is running and i am just trying to gather tidbits of info on how to accomplish this. It is really quite simple.

    Like Joel said already, nobody is writing that much code in assembly anymore these days. Even if someone would do the source code required for a runtime of CLR's complexity will be huge, way too huge to fit in a forum post. "

    Just because there aren't too many people who can write assembly and lots of it doesn't mean it isn't useful and isn't the way to go. I find it to be the perfect solution.

    " In particular that's the job of a "compiler", not of a "runtime". The compiler itself is a highly complex piece of code. "

    I know how complex compilers and runtimes are!! That is not the point!! And that is NOT the job of the compiler! The compiler just compiles the source code into IL (this is quite a huge oversimplification :) ) and after that it doesn't touch the file generated. The RUNTIME manages the IL at runtime. I write compilers and can do all that stuff, I am just in the process of developing the runtime for a very simple programming language.

    " IL instructions aren't executed, CLR is not an interpreter. A whole IL function is compiled to x86 code and then that code is executed. "

    That is what I meant :)

    I am just looking for simple assembly code samples on the stuff mentioned above.

    Question: can assembly code be compiled directly into an executable, DLL, etc. without having to compile it into IL?

    Thanks!

    P.S.  Why are people SO discouraging on this site??


    Nevin Janzen (Visit my Website)
    If this post answers your question, please click Propose As Answer. If this post is helpful, please click Vote As Helpful.

    Wednesday, April 25, 2012 4:22 PM
  • "And that is NOT the job of the compiler! The compiler just compiles the source code into IL (this is quite a huge oversimplification :) ) and after that it doesn't touch the file generated. The RUNTIME manages the IL at runtime. I write compilers and can do all that stuff, I am just in the process of developing the runtime for a very simple programming language."

    You may say I'm nitpicking but that it is the job of a compiler. Yes, that's not the C# compiler or the VB compiler but it is a compiler, the JIT compiler which is a part of the CLR. In the C/C++ world the C# compiler would be called the "front-end" of the compiler and the JIT compiler would be called the "back-end" of the compiler. That said, back to your primary question:

    "What I am looking for are simple assembly code samples that show how to manage simple variables in a program when it is running."

    I'm starting to think that what you really want is not exactly how to write a compiler/runtime in assembly but how the assembly code generated by a compiler should look. For this you could try "The art of assembly language programing" book. For example this shows how to pass function parameters on the stack:

    http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_11/CH11-4.html#HEADING4-1

    • Marked as answer by Nevin Janzen Thursday, April 26, 2012 12:52 AM
    Wednesday, April 25, 2012 5:27 PM
    Moderator
  • You may say I'm nitpicking but that it is the job of a compiler. Yes, that's not the C# compiler or the VB compiler but it is a compiler, the JIT compiler which is a part of the CLR. In the C/C++ world the C# compiler would be called the "front-end" of the compiler and the JIT compiler would be called the "back-end" of the compiler. "

    Technically, yes, the runtime has a JIT compiler, but the term 'compiler' by itself usually refers to something like the C# or VB.NET compiler and the term 'JIT compiler' refers to the compiler in the runtime. So technically, yes, the runtime has a compiler (some might argue that the runtime is a compiler). Enough of that :)

    I'm starting to think that what you really want is not exactly how to write a compiler/runtime in assembly but how the assembly code generated by a compiler should look. For this you could try "The art of assembly language programing" book. For example this shows how to pass function parameters on the stack "

    THANK YOU!!! FINALLY!! :D :)  Bingo: that is exactly what I wanted!! :)  Thank you SO much!! :)

    :)


    Nevin Janzen (Visit my Website)
    If this post answers your question, please click Propose As Answer. If this post is helpful, please click Vote As Helpful.

    Thursday, April 26, 2012 12:52 AM