[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

8086 simulator in ruby

Vasil Vangelovski

8/17/2007 7:14:00 PM

I'm thinking of writing a simulator for the intel 8086 processor in
ruby. At first I'm interested in implementing basic instruction
execution and memory access, no interrupts. The interface may later be
implemented with Tk maybe even as an ajax application on rails. My buest
guess is using metaprogramming for interpreting the assembly
instructions. I'm not wery experienced with design patterns, so I need
some ideas on the levels of abstraction (the classes) i need to start
with this. Any ideas?
--
Posted via http://www.ruby-....

19 Answers

Phlip

8/17/2007 7:42:00 PM

0

Vasil Vangelovski wrote:

> I'm thinking of writing a simulator for the intel 8086 processor in
> ruby. At first I'm interested in implementing basic instruction
> execution and memory access, no interrupts. The interface may later be
> implemented with Tk maybe even as an ajax application on rails. My buest
> guess is using metaprogramming for interpreting the assembly
> instructions. I'm not wery experienced with design patterns, so I need
> some ideas on the levels of abstraction (the classes) i need to start
> with this. Any ideas?

Woo-hoo! Like Larry Wall said (he'd know), Real programmers can write
assembler in any language!

Try:

cpu = CPU.new
cpu.push 42
cpu.shift :b

and away you go!

(Oh, and use Test Driven Development to write it all. I think that's
generally how Intel invents chips, too!)

--
Phlip
http://www.oreilly.com/catalog/9780...
^ assert_xpath
http://tinyurl.... <-- assert_latest Model

Wilson Bilkovich

8/17/2007 7:49:00 PM

0

On 8/17/07, Vasil Vangelovski <vvangelovski@gmail.com> wrote:
> I'm thinking of writing a simulator for the intel 8086 processor in
> ruby. At first I'm interested in implementing basic instruction
> execution and memory access, no interrupts. The interface may later be
> implemented with Tk maybe even as an ajax application on rails. My buest
> guess is using metaprogramming for interpreting the assembly
> instructions. I'm not wery experienced with design patterns, so I need
> some ideas on the levels of abstraction (the classes) i need to start
> with this. Any ideas?

Check out rubinius at http:/... for a Ruby implementation
written (mostly) in Ruby and (mostly) test-first. It may help you
think of some ideas.

What you are describing is basically just a virtual machine that you
happen to already know the V-ISA for. You can definitely do this in
Ruby, though simulating a real CPU is never going to be easy.

John Joyce

8/17/2007 8:59:00 PM

0

Aww, how about a C-64 emulator...
you could even offer an option to simulate "speed" when loading from
"tape"
(avg time: 30 - 60min, chance of failure: 65% or higher)
Or even a PDP-11

Just be sure to include the frustrations of old, slow machines that
often had problems, as an option to set. Can be very instructional to
users who never had the experience and to those who start to wax
nostalgic.

Phlip

8/17/2007 9:16:00 PM

0

John Joyce wrote:

> Aww, how about a C-64 emulator...
> you could even offer an option to simulate "speed" when loading from
> "tape"
> (avg time: 30 - 60min, chance of failure: 65% or higher)
> Or even a PDP-11

Dude, there are simulations of Ada & Babbage's "Inference Engine" out there!

--
Phlip
http://www.oreilly.com/catalog/9780...
^ assert_xpath
http://tinyurl.... <-- assert_latest Model

Robert Dober

8/17/2007 9:16:00 PM

0

On 8/17/07, Vasil Vangelovski <vvangelovski@gmail.com> wrote:
> I'm thinking of writing a simulator for the intel 8086 processor in
> ruby. At first I'm interested in implementing basic instruction
> execution and memory access, no interrupts. The interface may later be
> implemented with Tk maybe even as an ajax application on rails. My buest
> guess is using metaprogramming for interpreting the assembly
> instructions. I'm not wery experienced with design patterns, so I need
> some ideas on the levels of abstraction (the classes) i need to start
> with this. Any ideas?
> --
> Posted via http://www.ruby-....
>
>
I do not think metaprogramming is of use here, maybe you can get some
inspiration from here?
http://www.rubyquiz.com/q...
HTH
Robert

--
I'm an atheist and that's it. I believe there's nothing we can know
except that we should be kind to each other and do what we can for
other people.
-- Katharine Hepburn

Robert Klemme

8/17/2007 9:20:00 PM

0

On 17.08.2007 21:41, Phlip wrote:
> Vasil Vangelovski wrote:
>
>> I'm thinking of writing a simulator for the intel 8086 processor in
>> ruby. At first I'm interested in implementing basic instruction
>> execution and memory access, no interrupts. The interface may later be
>> implemented with Tk maybe even as an ajax application on rails. My buest
>> guess is using metaprogramming for interpreting the assembly
>> instructions. I'm not wery experienced with design patterns, so I need
>> some ideas on the levels of abstraction (the classes) i need to start
>> with this. Any ideas?
>
> Woo-hoo! Like Larry Wall said (he'd know), Real programmers can write
> assembler in any language!
>
> Try:
>
> cpu = CPU.new
> cpu.push 42
> cpu.shift :b
>
> and away you go!

I'd rather do

CPU8086 do
label :begin
push 42
shift :b
jmp :begin
end

I.e. create an instance behind the scenes and instance_eval the block.

Kind regards

robert

Phlip

8/17/2007 10:01:00 PM

0

Robert Klemme wrote:

> CPU8086 do
> label :begin
> push 42
> shift :b
> jmp :begin
> end

How you get a class name to respond to do? I thought objects couldn't
respond to do, essentially at the syntax level...

(Or is that pseudo?)

--
Phlip
http://www.oreilly.com/catalog/9780...
^ assert_xpath
http://tinyurl.... <-- assert_latest Model

Tom Werner

8/17/2007 10:11:00 PM

0

Phlip wrote:
> Robert Klemme wrote:
>
>
>> CPU8086 do
>> label :begin
>> push 42
>> shift :b
>> jmp :begin
>> end
>>
>
> How you get a class name to respond to do? I thought objects couldn't
> respond to do, essentially at the syntax level...
>
> (Or is that pseudo?)
>
>

def FOO
yield
end

FOO do
puts 'FOO called'
end

# => FOO called

--
Tom Preston-Werner

* Libraries:
Chronic (chronic.rubyforge.org)
God (god.rubyforge.org)
* Site:
rubyisawesome.com


John Joyce

8/18/2007 2:45:00 AM

0


On Aug 17, 2007, at 5:00 PM, Phlip wrote:

> Robert Klemme wrote:
>
>> CPU8086 do
>> label :begin
>> push 42
>> shift :b
>> jmp :begin
>> end
>
> How you get a class name to respond to do? I thought objects couldn't
> respond to do, essentially at the syntax level...
>
> (Or is that pseudo?)
>

Nah, it's just a normal block of Ruby!
With an iterator, you might do:

10.times do
puts 'hello'
end

In this case, 10 is not really any different than CPU8086.
Think of do-end as a block that iterates 1 time. That's what it is!


Marc Heiler

8/18/2007 6:29:00 AM

0

> Try:

> cpu = CPU.new
> cpu.push 42
> cpu.shift :b

> and away you go!

Actually, even though this example may be totally useless (although it
contains the ultimate answer to everything!), I really really love the
abstraction you can get. Would be funny to write in ruby but get
compiled assembler code!

Wouldnt using cpu << 42 be nicer though? :D
--
Posted via http://www.ruby-....