473,734 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script Assembler in C++: What operations should I implement?

I wish to create my own assembly language for script. For now it is
mostly for fun and for the sake of the learning, but I am also creating
a game engine where I want this system in. Once the assembler is done I
will develop a simple script language/compiler which uses this
assembler. What operators do you suggest I implement in it?

Yours,
Morten Aune Lyrstad
Jul 22 '05 #1
21 2041
That should be operations, not operators. Sorry! :-)
Jul 22 '05 #2
That should be which operations, not what operators... Sorry! ;-)

Yours,
Morten Aune Lyrstad
Jul 22 '05 #3
Morten Aune Lyrstad wrote:

I wish to create my own assembly language for script. For now it is
mostly for fun and for the sake of the learning, but I am also creating
a game engine where I want this system in. Once the assembler is done I
will develop a simple script language/compiler which uses this
assembler. What operators do you suggest I implement in it?


First of all you should think about what type of 'virtual CPU' you
want to implement. Then start thinking about what operations this
virtual CPU should support.

For starters: I recommend a stack machine (that is: no registers,
all arithmetic works on a stack by pushing from the stack, performing
the operation, poping the result back on the stack).

So obivous operations are:
push
pop
cmp comparing top of stack with (top+1) of stack, test for equality
push true (=1) or false (=0) on stack
jump
jump_if_zero jump conditionally if top of stack equals 0
load (from memory address specified at top of stack, push value onto stack)
store (store *top at memory address specified with (top+1), pop both from stack )
add
subtract
multiply
divide
...

A statement like
i = j + 2

will translate to

push <address_of_i >
push <address_of_j >
load
push 2
add
store

Once you have that, other operations will come to your mind if you need them.
Eg. you will encounter that you often generate the sequence

....
push 0
cmp

where the sequence push 0, cmp could easily be replaced with a dedicated
cmp_zero

or various different jump types (jump_if_zero, jump_if_not zero, jump_if_positiv e,
jump_if_negativ e, etc)
It's a lot of fun, to design your own CPU and figuring out how well it can be
programmed.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #4
Wow; a great reply! Thank you very much!

Many great tips, plus good explanations. I love this! I was indeed
thinking of creating a stack machine. Your answer will help me start
off. Great!

Thanks,
Morten Aune Lyrstad
Jul 22 '05 #5
Morten Aune Lyrstad wrote:

Wow; a great reply! Thank you very much!

Many great tips, plus good explanations. I love this! I was indeed
thinking of creating a stack machine. Your answer will help me start
off. Great!


Another start: Search the Web for resources on the programming
language 'Forth'. It is a very simple programming language, which
made the stack principle to its core element. You can get lots of
ideas on possible operations and how to implement them from this
language.
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #6
Karl Heinz Buchegger wrote:
Morten Aune Lyrstad wrote:
Wow; a great reply! Thank you very much!

Many great tips, plus good explanations. I love this! I was indeed
thinking of creating a stack machine. Your answer will help me start
off. Great!

Another start: Search the Web for resources on the programming
language 'Forth'. It is a very simple programming language, which
made the stack principle to its core element. You can get lots of
ideas on possible operations and how to implement them from this
language.

Would you suggest that I make a push and pop for each different
datatype? Or should I make a more generic system?
Jul 22 '05 #7
Morten Aune Lyrstad wrote:

Karl Heinz Buchegger wrote:
Morten Aune Lyrstad wrote:
Wow; a great reply! Thank you very much!

Many great tips, plus good explanations. I love this! I was indeed
thinking of creating a stack machine. Your answer will help me start
off. Great!

Another start: Search the Web for resources on the programming
language 'Forth'. It is a very simple programming language, which
made the stack principle to its core element. You can get lots of
ideas on possible operations and how to implement them from this
language.

Would you suggest that I make a push and pop for each different
datatype? Or should I make a more generic system?


I think it is easier (and faster too) to generate multiple
data stacks: one for each data type. You won't have many:
integers, floating point and strings
(integers and floating point could be collected in one data
type by storing integers as floating point)
Then you need to duplicate the set of operations for each data
type and of course you will need operations for transfering
the top of stack element from one stack to another (He, he:
this is where the fun begins. Introduce a new 'hardware
concept' and see what 'assembly' instructions you need to
support it)

The 'assembly' instructions by itself get simpler, if they
don't need to figure out what's actually on the stack and
react accordingly. That's something the compiler can do
and generate different instructions. On the other hand:
the instruction set gets bigger, but it's not that big of
a deal :-)

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #8
Karl Heinz Buchegger wrote:
Morten Aune Lyrstad wrote:
Karl Heinz Buchegger wrote:
Morten Aune Lyrstad wrote:
Wow; a great reply! Thank you very much!

Many great tips, plus good explanations. I love this! I was indeed
thinking of creating a stack machine. Your answer will help me start
off. Great!
Another start: Search the Web for resources on the programming
language 'Forth'. It is a very simple programming language, which
made the stack principle to its core element. You can get lots of
ideas on possible operations and how to implement them from this
language.


Would you suggest that I make a push and pop for each different
datatype? Or should I make a more generic system?

I think it is easier (and faster too) to generate multiple
data stacks: one for each data type. You won't have many:
integers, floating point and strings
(integers and floating point could be collected in one data
type by storing integers as floating point)
Then you need to duplicate the set of operations for each data
type and of course you will need operations for transfering
the top of stack element from one stack to another (He, he:
this is where the fun begins. Introduce a new 'hardware
concept' and see what 'assembly' instructions you need to
support it)

The 'assembly' instructions by itself get simpler, if they
don't need to figure out what's actually on the stack and
react accordingly. That's something the compiler can do
and generate different instructions. On the other hand:
the instruction set gets bigger, but it's not that big of
a deal :-)

Great idea, thanks again! :-)
Jul 22 '05 #9
The comparison operations (like cmp) does not pop the variables it tests
from the stack; am I right?
Jul 22 '05 #10

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

Similar topics

1
2288
by: Fabian | last post by:
I notice on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndude/html/dude100499.asp that the writer has measured the time taken to run the script down to the millisecond. Does anyone know what tools he used to calculate these load times? -- --
4
2402
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a hierarchy of algebraic matrices with the addition operation. Thus, I want to have a virtual base class class Matr;
1
1325
by: jd | last post by:
I have implemented a COM object in Python and I would like to be able to change the script without stopping and restarting the application that's using the COM object. Is there a way to do this? (I can change the program that calls the COM object if needed.) Thanks... -- jeff
2
3564
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several thumbnails. Above these thumbnails I placed a large picture with text next to it to describe what the picture is about. So, when you click a thumb, the large pic AND text change dynamically to reflect the thumbnail -- see...
14
2472
by: spamtrap | last post by:
Mostly for testing reasons I'd like to see if it makes sense to chose the following approach for just-in-time compilation of shaders for a renderer: Seeing as the shaders themsefs consist mostly of very basic operations I'd like to translate them into assembly, have an assembler compile the binary code and then call the resulting machine code from c++. The thing is that up until now I have only used inline assembly in my c++ projects,...
0
1597
by: ssnsridhar | last post by:
Hi, I ve saw a sample instance provider and have done a service which wil just display wat i have entered in ma service code.. Now i want to Enumerate, Create, Get, Modify operations. Can anyone plz help me out.. I have included ma code in this.. plz tel how to implement those operations.. using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics;
8
3133
by: John | last post by:
Hi, gurus, How can I implement the following feature in C#: Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ", group") For Each objMember In objGroup.Members WScript.Echo vbCrLf & " Name: " & objMember.Name Next
24
3232
by: Peter Michaux | last post by:
I have a Perl script that I want to run as a set-user-ID program. Many OSes don't allow scripts run as set-user-ID. To make this script portable, it seems I need to write a C wrapper program that calls exec or system to give the Perl script the necessary effective permissions. How can I make the C wrapper program secure? or "more" secure? The Perl script, which is "-rwsr-xr-x root root" will look at the real user id and then check a...
0
2200
by: tabassumpatil | last post by:
Please send the c code for: 1.STACK OPERATIONS : Transfer the names stored in stack s1 to stack s2 and print the contents of stack s2. 2.QUEUE OPERATIONS : Write a program to implement DOUBLE ENDED QUEUE operations a) Use names as data to perform all operations like enqueue,dequeue,print,etc. b)Use students records as data to perform the same operations. 3.FILE OPERATIONS: write c program to implement following FILE operations:...
0
8951
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
9317
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
9248
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
9187
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...
1
6743
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4818
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3266
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
2734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2184
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.