Click here to Skip to main content
15,894,337 members
Home / Discussions / C#
   

C#

 
AnswerRe: making a microprocessor simulator in C# Pin
OriginalGriff15-Mar-10 3:45
mveOriginalGriff15-Mar-10 3:45 
GeneralRe: making a microprocessor simulator in C# Pin
Djtech0115-Mar-10 4:11
Djtech0115-Mar-10 4:11 
GeneralRe: making a microprocessor simulator in C# Pin
OriginalGriff15-Mar-10 4:20
mveOriginalGriff15-Mar-10 4:20 
GeneralRe: making a microprocessor simulator in C# Pin
Dave Kreskowiak15-Mar-10 4:39
mveDave Kreskowiak15-Mar-10 4:39 
GeneralRe: making a microprocessor simulator in C# Pin
OriginalGriff15-Mar-10 4:46
mveOriginalGriff15-Mar-10 4:46 
AnswerRe: making a microprocessor simulator in C# Pin
Richard MacCutchan15-Mar-10 3:57
mveRichard MacCutchan15-Mar-10 3:57 
AnswerRe: making a microprocessor simulator in C# [modified] Pin
harold aptroot15-Mar-10 4:08
harold aptroot15-Mar-10 4:08 
AnswerRe: making a microprocessor simulator in C# Pin
Luc Pattyn15-Mar-10 4:09
sitebuilderLuc Pattyn15-Mar-10 4:09 
Hi,

now I'm getting the picture of what it is you are trying to do.

I've created lots of microprocessor simulators over the years, using all kinds of languages, from Fortran4 to C#. And I have ran hundreds of millions of simulated instructions on them! I assume you are looking for logic simulation at the user level (i.e. executing the programming model correctly in user mode, but not getting accurate timing as to number of cycles per instruction, and probably not modeling all the protection levels); and I assume you want maximum performance.

You seem set out to generate some IL code to accomplish that. Well, I haven't done so (at least not for simulation), and I am not inclined to do it any time soon. It is perfectly feasible, but I don't believe it leads to best performance.

Functions/methods in most, if not all, languages have one dominant characteristic: they use a stack model, however the stack before and after the execution is in the same state. The same is true in IL; a method may push a few items, it is bound to pop exactly the same number of items before it can return. IL validators will even check for that. So there should really not be any problem in creating an IL method that simulates one (or a series of) microprocessor instruction(s). The only thing is, I don't want to call a method for every instruction simulated.

My latest simulators (assuming a simple RISC processor for a minute) contain one huge switch statement, with lots of cases, one for each instruction type. On a CISC, that might be 256 cases, one per byte value. And each case holds one or a few lines simulating the instruction. Beware, the most code often is required for getting all the flags right (zero, negative, carry, etc). And the other design decision that needs careful analysis is how and where to keep the procoessor state; you can organize it very OO-like, but then you will pay the price for each access. Keeping one array of registers often is a fair approach.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.

GeneralRe: making a microprocessor simulator in C# Pin
DaveyM6915-Mar-10 5:09
professionalDaveyM6915-Mar-10 5:09 
GeneralRe: making a microprocessor simulator in C# Pin
Luc Pattyn15-Mar-10 5:25
sitebuilderLuc Pattyn15-Mar-10 5:25 
GeneralRe: making a microprocessor simulator in C# Pin
DaveyM6915-Mar-10 5:48
professionalDaveyM6915-Mar-10 5:48 
GeneralRe: making a microprocessor simulator in C# Pin
Luc Pattyn15-Mar-10 6:39
sitebuilderLuc Pattyn15-Mar-10 6:39 
GeneralRe: making a microprocessor simulator in C# Pin
DaveyM6915-Mar-10 7:22
professionalDaveyM6915-Mar-10 7:22 
GeneralRe: making a microprocessor simulator in C# Pin
CPallini15-Mar-10 7:52
mveCPallini15-Mar-10 7:52 
GeneralRe: making a microprocessor simulator in C# Pin
DaveyM6915-Mar-10 8:10
professionalDaveyM6915-Mar-10 8:10 
GeneralRe: making a microprocessor simulator in C# Pin
harold aptroot15-Mar-10 8:17
harold aptroot15-Mar-10 8:17 
GeneralRe: making a microprocessor simulator in C# Pin
CPallini15-Mar-10 9:09
mveCPallini15-Mar-10 9:09 
GeneralRe: making a microprocessor simulator in C# Pin
CPallini15-Mar-10 9:06
mveCPallini15-Mar-10 9:06 
AnswerRe: making a microprocessor simulator in C# Pin
Djtech0115-Mar-10 4:19
Djtech0115-Mar-10 4:19 
GeneralRe: making a microprocessor simulator in C# Pin
Dave Kreskowiak15-Mar-10 4:33
mveDave Kreskowiak15-Mar-10 4:33 
AnswerRe: making a microprocessor simulator in C# Pin
Dave Kreskowiak15-Mar-10 4:30
mveDave Kreskowiak15-Mar-10 4:30 
AnswerRe: making a microprocessor simulator in C# Pin
Djtech0115-Mar-10 4:42
Djtech0115-Mar-10 4:42 
GeneralRe: making a microprocessor simulator in C# Pin
OriginalGriff15-Mar-10 4:49
mveOriginalGriff15-Mar-10 4:49 
GeneralRe: making a microprocessor simulator in C# Pin
Djtech0115-Mar-10 4:57
Djtech0115-Mar-10 4:57 
QuestionAdvanced C# Question Pin
Dave Kerr15-Mar-10 1:19
mentorDave Kerr15-Mar-10 1:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.