I want to fetch and decode a instruction at address X. After that I want to increment the address by 4 and then execute the decoded instruction. The registers are 32 bit big endian. I am not asking for a solution, more a pointer or tips on how to do this in C, or if any of you know some good guides to follow.
Asked
Active
Viewed 452 times
-1
-
The "address" will be implemented using a pointer to `char`. Your simulated "instructions" will live in an array of char. – Mike Nakis Apr 06 '17 at 20:59
-
okay, so lets say reg 63 work as the program counter how do i call that and the use it as pointer for the other instructuions – user123 Apr 06 '17 at 21:09
-
I believe you are looking for this function to jump to the address http://man7.org/linux/man-pages/man3/fseek.3.html and this one to read https://linux.die.net/man/3/fread (the address is automatically updated after reading). – Fernando Coelho Apr 06 '17 at 21:09
-
First, design this on paper, with pictures and basic flow. Then translate it into whatever language you are familiar with, or pseudo-code, or just some computer-like language you invent. Make sure it works, by logical inspection; that's good enough. Only then do you translate that to "C". Something like this can be implemented with a very small subset of the language -- perhaps your problem is in the first few steps. If you still have problems translating some constructs into "C", come back with your pseudo code, and someone will help you. – kozel Apr 07 '17 at 03:09
-
Welcome to Stack Overflow! Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). You should include at least an outline (but preferably a [mcve]) of the code that you are having problems with, then we can try to help with the specific problem. You should also read [ask]. – Toby Speight Apr 07 '17 at 13:47
1 Answers
1
You probably want assembly for this, not C. You could link assembly code into a C program, but you shouldn't write that in C.

Gold Dragon
- 480
- 2
- 9
-
dealing with the actual instruction set of the processor? No way you want C for that. ASM all the way – Gold Dragon Apr 08 '17 at 15:14
-
You can write a full processor simulator in "C", or even a higher-level language (e.g., Python). Implementing a simple processor in high-level language is a common assignment in CS classes. See http://stackoverflow.com/questions/23026095/how-do-you-simulate-hardware-in-python – kozel Apr 08 '17 at 18:05