1

I am aware of this question, and I think I know why it has been closed. I hope that my question manages to be more specific.

My skill level: I have a "Computer Science" degree. I have programmed in many languages. Back in the day I programmed in C on an embedded microcontroller (TI MSP430), and in Python and Prolog. I have absolutely no experience in programming in assembly language, although I think I understand the concept. I had to embed assembly for my microcontroller work, but this was on the level of initializing some of the attached hardware; nothing that even involved implementing an algorithm.

I am aware of the fact that Knuth's "The Art of Computer Programming" shows all algorithms in assembly. Going through this book is a huge investment and I'd do it if someone recommends it.

I realize this question is very general, but since I have absolutely no prior experience, I find it really difficult to put it into any context.

My "problem":

I have to implement a simulator for a project that is part of my thesis work. I tried doing it in two different high-level languages: Python and Prolog. I could not model the "things" I am simulating (autonomous, very simple units without any complex logic, but too many of them) without incurring too much overhead. I even considered using Erlang and Erlang processes, but the messaging between them is definitely a bad way to model how the things interact with each other.

I did consider using C or C++. The simulation involves changing the behaviour of the things I am modeling, and doing this in C or C++ would mean actually implementing a "virtual" machine (the simulator) that allows me to do this. It seems that assembler will make it slightly easier. I have to admit that the architecture I have written (very limited) assembly on had a flat address space, which is why I thought that would be an option.

It feels as if Assembly language might be the way forward. However, I am at a loss at:

  • which assembly language to pick
  • how to chose an architecture

Things I considered:

  • GNU Assembler
  • Knuth's MMIX

The questions:

  • Can I actually use any of the two for a (more or less) efficient implementation on an already existing architecture?
  • Does this sound like a completely misguided attempt?
12
  • 1
    recommended reading: Where to start
    – gnat
    Commented Jan 20, 2015 at 9:08
  • 1
    The second of your 3 questions is asking for a recommendation of an off-site resource, which is off-topic here. I would suggest editing your question and either rephrasing or removing it.
    – Jules
    Commented Jan 20, 2015 at 9:19
  • 1
    the question is not dumb, only a proven bad fit for Stack Exchange format. "We already tried supporting those questions, we even gave them their own site. Sadly, it didn't work out..."
    – gnat
    Commented Jan 20, 2015 at 9:27
  • 2
    @Boris: Just so you are aware: self-modifying code is quite a big red flag for virus scanners. It is something that has few legitimate uses (yours might be one), and is/was loved by virus authors. Commented Jan 20, 2015 at 9:49
  • 1
    @Boris: Just don't be surprised if your local virus scanner starts to act up. Commented Jan 20, 2015 at 10:27

1 Answer 1

2

MMIX isn't the solution you're looking for. It's primary purposes is to enable standardised implementations of algorithms and data structures so that they can be compared with each other in terms of efficiency. It is not intended to run on real hardware, and run-time efficiency was never its goal.

I also don't recommend using the GNU assembler, at least not if you are targeting an 80x86 processor. It uses a syntax that is somewhat different to the syntax Intel use to describe their processors, and it is the latter syntax that most educational resources for assembly programming are aimed at. NASM is I believe the most commonly used assembler for hand-coded intel assembly, and I would recommend it because of this (even if I hadn't been involved in writing it!).

That said, however, I'm not sure assembly language is the best approach to your problem.

(update after question edited: I originally suggested C/C++ here)

It may be that Java is actually your best bet - it has a handful of libraries available (asm.jar, BCEL, javassist) that are intended to make dynamic generation of java code at run time easy. You would program the dynamic parts of your system in Java bytecode, which is conceptually similar to assembly language, but much simpler, and this would then be converted to native machine code by the JVM. I think this is probably the best balance between simplicity and efficiency available. If it isn't efficient enough, LLVM can be used to achieve similar results in C++, but is harder to use.

2
  • I see. I still think assembly will turn out to be a vert difficult way to implement this, but I'm starting to see why you're tempted in this direction. It may be that Java is actually your best bet - it has a handful of libraries available (asm.jar, BCEL, javassist) that are intended to make dynamic generation of java code at run time easy. You would program the dynamic parts of your system in Java bytecode, which is conceptually similar to assembly language, but much simpler, and this would then be converted to native machine code by the JVM.
    – Jules
    Commented Jan 20, 2015 at 9:36
  • I think this is probably the best balance between simplicity and efficiency available. If it isn't efficient enough, LLVM can be used to achieve similar results in C++, but is harder to use.
    – Jules
    Commented Jan 20, 2015 at 9:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.