473,839 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help in writing cpu simulator

7 New Member
hi all
i need a help in writing cpu simulator

i will thank everybody who will guide me how to start doing that and explain this:

Program conditionals (loops, if-then-else) are translated into a different family of assembly instructions called branch instructions. Branch instructions check some simple condition, and if the condition is true the next instruction executed by the CPU will not be the following instruction in the code, but rather the CPU will jump to another place in the program. For example, let's assume that instruction number 15 in the program is a branch instruction that tells the CPU to check whether a certain value is positive, and if so jump back 4 instructions. The CPU will then check the condition: if the condition fails (the value is not positive) the next instruction it will execute will be instruction number 16 --- the following instruction. If the condition holds however --- the value in question is indeed positive --- the CPU will jump back 4 instructions, and the next instruction executed will be instruction number 11 (= 15 - 4).
also this :


Syntax Equivalent Java Code Details
nop /**/ No-OPeration: Do nothing
add rA rB rC rA = rB + rC Sum registers rB and rC and store the result in register rA
sub rA rB rC rA = rB - rC Subtract register rC from register rB and store the result in register rA
mul rA rB rC rA = rB * rC Multiply registers rB and rC and store the result in register rA
div rA rB rC rA = rB / rC Divide register rB by register rC and store the result in register rA
b Offset PC = PC + Offset Branch: add the offset to the PC register (equivalent to goto)
bz rA Offset if(rA==0) PC = PC + Offset Jump "Offset" instructions if rA contains 0 (conditional goto)
bpos rA Offset if(rA > 0) PC = PC + Offset Jump "Offset" instructions if rA contains a positive integer (conditional goto)
bneg rA Offset if(rA < 0) PC = PC + Offset Jump "Offset" instructions if rA contains a negative integer (conditional goto)
load rA rB rA = memory[rB] Load the data from memory address rB into register rA
store rA rB memory[rB] = rA Store the value in register rA in memory address rB
read rA rA = SimpleInput.in. readInt() Read an integer from the user and store it in register rA
write rA System.out.prin tln(rA) Print the value stored in rA
exit rA System.exit(rA) Exit the emulator with the value from register rA as exit status
set rA Number rA = Number Store the integer "Number" in rA


i also thanks everybody to provide me the main algorithm
Jan 21 '07 #1
1 3355
r035198x
13,262 MVP
hi all
i need a help in writing cpu simulator

i will thank everybody who will guide me how to start doing that and explain this:

Program conditionals (loops, if-then-else) are translated into a different family of assembly instructions called branch instructions. Branch instructions check some simple condition, and if the condition is true the next instruction executed by the CPU will not be the following instruction in the code, but rather the CPU will jump to another place in the program. For example, let's assume that instruction number 15 in the program is a branch instruction that tells the CPU to check whether a certain value is positive, and if so jump back 4 instructions. The CPU will then check the condition: if the condition fails (the value is not positive) the next instruction it will execute will be instruction number 16 --- the following instruction. If the condition holds however --- the value in question is indeed positive --- the CPU will jump back 4 instructions, and the next instruction executed will be instruction number 11 (= 15 - 4).
also this :


Syntax Equivalent Java Code Details
nop /**/ No-OPeration: Do nothing
add rA rB rC rA = rB + rC Sum registers rB and rC and store the result in register rA
sub rA rB rC rA = rB - rC Subtract register rC from register rB and store the result in register rA
mul rA rB rC rA = rB * rC Multiply registers rB and rC and store the result in register rA
div rA rB rC rA = rB / rC Divide register rB by register rC and store the result in register rA
b Offset PC = PC + Offset Branch: add the offset to the PC register (equivalent to goto)
bz rA Offset if(rA==0) PC = PC + Offset Jump "Offset" instructions if rA contains 0 (conditional goto)
bpos rA Offset if(rA > 0) PC = PC + Offset Jump "Offset" instructions if rA contains a positive integer (conditional goto)
bneg rA Offset if(rA < 0) PC = PC + Offset Jump "Offset" instructions if rA contains a negative integer (conditional goto)
load rA rB rA = memory[rB] Load the data from memory address rB into register rA
store rA rB memory[rB] = rA Store the value in register rA in memory address rB
read rA rA = SimpleInput.in. readInt() Read an integer from the user and store it in register rA
write rA System.out.prin tln(rA) Print the value stored in rA
exit rA System.exit(rA) Exit the emulator with the value from register rA as exit status
set rA Number rA = Number Store the integer "Number" in rA


i also thanks everybody to provide me the main algorithm
Well you should have done something at least. You just posted the question and no ideas of your own. Go through the instructions you want to simulate and put labels on them. Then read about how to use labels in Java. After that you should be able to do this.
Jan 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3463
by: Miki Tebeka | last post by:
Hello All, I'll be writing a hardware simulator for one of our CPU's shortly. Any advices/links/... on the subject? Thanks. Miki
0
2312
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);
1
3368
by: Gandu | last post by:
I apologize if this is not the appropriate newsgroup to post this message. Could someone please tell me a good place to get an an Aloha protocol simulator source code(C++) that is well-documented and easy to understand. Thanks in advance for your help.
15
7782
by: Douglas Garstang | last post by:
All, I posted a newsgroup question here a few weeks back, asking some questions that related to my 10 year quest (so far) to understand pointers. Someone suggested I write a simple emulator. Part of his post is below. I would have emailed him directly but a valid email wasn't included.
61
16324
by: /* frank */ | last post by:
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.
13
1439
by: mgorbach | last post by:
Im writing a program that does monte carlo simulation and im having trouble figuring out how to get the threading model right. I have a simulation class which contains all simulation data and methods to run the simulation for an x number of sweeps. An instance of this object is declared in the class of my main form. The main form handles graphics (it shows the particles moving on the form). I am now trying to split up the work so that the...
0
1708
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...
10
2681
by: shraddhashraddha | last post by:
I am shraddha and i have a project in which i have to design a discrete event simulator in java to simulate a counter servicing a queue of customers bt i am nt getting any clue of how to go about the programming part please help me in writing the code and provide some help , u c i m vry confused how to go abt it , someone plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz help me out.
3
9253
by: patrickdepinguin | last post by:
Hi, I need to write large quantities of data to a file in C. The data comes from statistics that are continuously gathered from a simulator, and in order to not slow the whole thing down I would obviously want the writes to go as fast and efficient as possible. Since I/O operations are rather slow, I was thinking that using a large buffer would be better than writing each data point every time. Each data point calls my function, at which...
0
9698
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
10597
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
10656
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
10299
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
9434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.