473,722 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CPU simulator written in C

I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.

Thanks in advance.
Nov 14 '05 #1
61 16259
In 'comp.lang.c', /* frank */ <__*******@desp ammed.com> wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents
It's a design question. There is no particular problem with that. It's just
another interpreter.
I tried to search con google with no success.


Better to dig your brain. The answer is there.

BTW, what is your question about the C-language?

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #2
/* frank */ <__*******@desp ammed.com> wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.


Your assignment said: "_make_ a CPU simulator". Not "copy a CPU
simulator". There is a very good reason for this. How do you expect to
learn anything if you just hand in someone else's work?

Richard
Nov 14 '05 #3
/* frank */ wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.


The key idea is to map all parts of a CPU on C structures
and routines. For example: the program counter (PC) can
be simply mapped to an int variable. Now you should create
mappings for registers, .... It's not that complicated.

HTH

Case

Nov 14 '05 #4
Case ha scritto:
It's not that complicated.


Thanks a lot.

I was searching only for a "starting input" .
Nov 14 '05 #5
/* frank */ wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.


You are searching with the wrong target word. The proper word is emulate,
not simulate.

To simulate is to try to predict how fast some CPU design (probably unbuilt)
will be. To emulate is to produce the effect on computer B that a program
was run on computer A. If you do not have source code for A, there are not
too many alternatives. In the real world you would have machine code, not
an asm file - which is a different thing. But it is easier to communicate
between humans with asm than with machine code.
Nov 14 '05 #6
In <2j************ *@uni-berlin.de> /* frank */ <__*******@desp ammed.com> writes:
I have to do a homework: make a CPU simulator using C language.
Well, C is particularly suitable for such an exercise.
I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.


Apart from being lazy, you're also stupid if you can expect any help
without specifying the CPU being emulated and the format of the .asm
files. I hope they're containing machine code and not assembly code,
because assemblying the code is, by far, the most difficult part of the
exercise.

Anyway, you can't expect any help until you describe your design and
ask very specific questions about its implementation.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
/* frank */ wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.

Thanks in advance.


Ha! I wrote something like this at the University.

I also wrote another one at my current worksite.

Here are some techniques:
1. Allocate variables for all registers.

2. You may need variables for the databus(es) too.

3. Write a simple program that executes a simple
instruction, such as adding two registers.

3.1 This may involve writing a function that simulates
a hardware adder. In my case, I had to put a value
onto a databus, have the adder retrieve from the
databus and repeat for the other argument. Another
function would trigger the actual addition, then
another function puts the sum onto the databus.

4. Once you get the above working, add a new feature
and test it. The paradigm of "Test Driven Development"
says to write the test first and expect the first
invocation to fail, since you haven't written the
code yet.

If you have a windowing operating system, you could
display the register contents and the databus contents
in separate windows.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #8
/* frank */ wrote:
Case ha scritto:
It's not that complicated.

I was searching only for a "starting input" .


That's what I thought. Good luck!

Case

Nov 14 '05 #9
On Wed, 23 Jun 2004 07:35:41 +0200, /* frank */
<__*******@desp ammed.com> wrote:
I have to do a homework: make a CPU simulator using C language.

I have a set of asm instructions so I have to write a program
that should:
- load .asm file
- view .asm file
- do a step by step simulation
- display registers contents

I tried to search con google with no success.

Any help (links, tricks/tips...)
would be really appreciated.

Thanks in advance. I googled eax ebx ecx edx ax bx in com.lang.c
-->
_______________ ________
In article <19************ *******@darwin. ntu.edu.au> cj*@dme.nt.gov. au
writes:I have repeatedly come across declarations of
the type 'struct REGS' (i think that was what was called,
have seen a few variations) and was wondering if
someone could tell me it's contents, and what it is used for.
I only have a very basic shareware compiler (for my PC anyway,
and I have never seen it under Unix) and it has no mention of this
structure.

Could someone enlighten me ?


This is not a Unix item but strictly a PC item as follows:

union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};

struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si, di, cflag, flags;
};

struct BYTEREGS {
unsigned char al, ah, bl, bh;
unsigned char cl, ch, dl, dh;
};

These structures allow C programs on PCs to access the CPU registers.

AX,BX,CX,DX,SI, DI,CF(carry flag),and FLAGS are all Intel 80x86
registers
AL/AH,BL/BH,CL/CH,DL/DH are pseudo 8 bit registers which are derived
from the
AL = Low half of AX, AH = High half of AX, etc.

The basic registers are 16 bits while the extended registers are 32
bits
EAX,EBX,ECX,EDX , etc.

In addition you have the segment registers CS,DS,ES,SS and the
pointers
SP,BP plus the index registers SI,DI and on the 80386 and above you
also
have debug registers.

In protected mode the segment registers become selector registers.

The segments are as follows:
CS code segment
DS data segment
ES extra segment
SS stack segment

The pointers are:
SP stack pointer
BP base pointer
--
Scott Hopson (sc****@filenet .com)
_______________ _______________ ______________

Hi,

I am not really familiar with interrupt calls, especially when done in
a 32 Bit OS enviroment.

I using the WatCom C Compiler Ver. 11b building 32 Bit Dos
applications.

I am trying to call interrupt 2FH, function 0DH for detecting the
driveletters of all connected cdroms.

I programmed this under 16bit dos and it works well, but I am not sure
how to adapt it for 32 Bit.

I have enclosed the code for 16 Bit. I would be pleased if anyone can
give advice.

Thanks a lot in advance.

Philipp

{
union REGS regs;
struct SREGS sregs;
char driveLetters [27];

regs.x.ax = 0x150D;
sregs.es = FP_SEG (driveLetters);
regs.x.bx = FP_OFF (driveLetters);
int86x (0x2F, &regs, &regs, &sregs);
}

*************** *******
* Auszug aus <i86.h> *
*************** *******
struct DWORDREGS {
unsigned int eax;
unsigned int ebx;
unsigned int ecx;
unsigned int edx;
unsigned int esi;
unsigned int edi;
unsigned int cflag;
};
struct WORDREGS {
unsigned short ax; __FILLER(_1)
unsigned short bx; __FILLER(_2)
unsigned short cx; __FILLER(_3)
unsigned short dx; __FILLER(_4)
unsigned short si; __FILLER(_5)
unsigned short di; __FILLER(_6)
#if defined(__WINDO WS_386__)
unsigned short cflag;
#else
unsigned int cflag;
#endif
};
struct BYTEREGS {
unsigned char al, ah; __FILLER(_1)
unsigned char bl, bh; __FILLER(_2)
unsigned char cl, ch; __FILLER(_3)
unsigned char dl, dh; __FILLER(_4)
};
union REGS {
#if defined(__386__ ) && !defined(__WIND OWS_386__)
struct DWORDREGS x;
#else
struct WORDREGS x;
#endif
struct WORDREGS w;
struct BYTEREGS h;
};
struct SREGS {
unsigned short es, cs, ss, ds;
#if defined(__386__ )
unsigned short fs, gs;
#endif
};
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2307
by: Alex Vinokur | last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at : * http://alexvn.freeservers.com/s1/utm.html * http://sourceforge.net/projects/turing-machine/ The program simulates a Universal Turing Machine (UTM). The UTM used in the Simulator is three-tape Turing Machine: * Tape#0 contains transition table and initial instantaneous description of a Particular Turing Machine (TM);
9
2633
by: Milk | last post by:
Hi all, Can anyone help me to do this Question. Coz this is my first time study C++ language and my lecture want me to do this kind of program, i really don't have any ideal pls help me here is the Question:: Improve the following (badly written) matrix multiplicationprogram and translate it into MIPs assembly language then assemble into machine language (hexadecimal representation). You may use a compiler to produce an assembly
26
5578
by: Wouter van Teijlingen | last post by:
Dear Readers, This is my first post to this group. I was pointed to this group in a other vb group, so i have better luck here! For my learning curve of VB .NET i want to make a traffic simulation program. Before i start programming, i need to know if there even is a possibility to make a algorithm in VB .NET that is able to let traffic drive and making the lights go green, orange or red.
0
1603
by: SatishPasala | last post by:
Hi I am developing a Windows Mobile application. I want Visual Studio to use Palm Simulator to display the application. Now it is pointing to Default Simulator. I downloaded the Palm Simulator. I need to add it to Visual Studio. Can some one help me to add the simulator?
0
1404
by: François | last post by:
Hi, My current job is to develop VoiceXML dialogs. The voice platform that we use provides neither a debugger nor a simulator, and each time I want to test a new dialog, I have to upload it on the remote production server, and to call the voice platform. So I would like to know where I can find a freeware VoiceXML simulator able to run a VoiceXML dialog. As my dialogs only use DTMF as an input, and text-to-speech synthesis for the...
1
4479
by: Ciko | last post by:
Was wondering how I could write a simple simulator (assembler CPU Z80). Thanks for any advice, link.
0
4079
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college information through mobile, however i just use simulator to test my system... one of modules or function was enable the student to downloads some notes which in txt file format through mobile.Hence, i tested using IE,it does not appear any problem, i...
0
1705
by: Killingkids | last post by:
hello, everyone...im facing a big problem in my final year project, hope that u all can help me solve the problem ... i was doing a mobile web application which enable student to check the college information through mobile, however i just use simulator to test my system... one of modules or function was enable the student to downloads some notes which in txt file format through mobile.Hence, i tested using IE,it does not appear any problem, i...
3
4741
by: DanielJohnson | last post by:
I was wondering if anyblody can suggest me a network simulator written in python in which I can add on my own code and extend its functionality. I am looking for a simulator which will simualte TCP, UDP, RTP and most networking protocol. The learning curve for ns2 and other simulator is too high for me at this time and thats why I am considering Python for it. Every help will be appreciated.
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.