2 Replies - 904 Views - Last Post: 20 November 2012 - 10:32 AM Rate Topic: -----

#1 Mihagin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-November 12

Manchester Baby hardware simulator in C++

Posted 19 November 2012 - 07:58 AM

A little help needed please!

I am attempting to create a program that will simulate the Manchester Baby (SSEM) in C++. Since I'm not very advanced with either language I'm finding it hard to even begin writing the code.

The simulation should take as input a text file containing a binary computer program written in the machine code language of the Baby (essentially 32 lines each of 32 bits of binary data corresponding to the store).
When the simulation is running, it should step through each line of the input program, simulating the fetch-decode-execute cycle. For example, after fetching an instruction, it should work out what that instruction is (which operation it corresponds to), what its operand is, then simulate the execution of that operation by moving data around the simulated hardware.

  • JMP - Copy content of the specified line into the CI
  • JRP - Add the content of the specified line into the CI
  • LDN - Copy the content of the specified line, negated, into the accumulator
  • STO - Copy the content of the accumulator to the specified store line
  • SUB - Subtract the content of the specified line from the accumulator
  • CMP - If the accumulator is less than 0 increment the CI
  • STP - Halt the Baby and light the “stop lamp”


The "store" in the program contains 32 individually addressable lines where each line can store 32 bits of data. I was thinking of implementing each line as an array and the store as an array of those individual arrays but feel this is quite an inefficent way to do this? If anyone has a better suggestion I would appreciate it greatly.
I can't figure out how I am meant to save the instruction set in order for the program to be able to compare the input to it and carry out the operation.
I really need a kick start in the right direction. Any help at all would be wonderful.

Is This A Good Question/Topic? 0
  • +

Replies To: Manchester Baby hardware simulator in C++

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Manchester Baby hardware simulator in C++

Posted 19 November 2012 - 09:14 AM

Quote

I was thinking of implementing each line as an array and the store as an array of those individual arrays but feel this is quite an inefficent way to do this? If anyone has a better suggestion I would appreciate it greatly.

Wouldn't it make more sense to just represent the memory as an array of thirty-two, 32-bit (unsigned?) integers?

Quote

I can't figure out how I am meant to save the instruction set in order for the program to be able to compare the input to it and carry out the operation.

You will need to find out the encoding of each instruction. From here, it mentions the following, although you will need more specific info on each instruction.

Quote

3-bit function field (bits 13 to 15) -- 13-bit store address (0 to 12) -- 16 bits unused

This post has been edited by Aphex19: 19 November 2012 - 09:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5941
  • View blog
  • Posts: 12,869
  • Joined: 16-October 07

Re: Manchester Baby hardware simulator in C++

Posted 20 November 2012 - 10:32 AM

This looks like fun!

I'd start with something like:
struct Word {
	static const int SIZE = 32;
	enum Oper { JMP,JRP,LDN,STO,SUB,CMP,STP };
	unsigned char data[SIZE];
	int getValue() const;
	void setValue(int);
	int getAddr() const;
	void setAddr(int);
	Oper getOper() const;
	void setOper(Oper);
};

std::ostream &operator<<(std::ostream &, const Word &);


struct Baby {
	static const int RAM_SIZE = 32;
	Word ram[RAM_SIZE], accumulator, current;
	void loadProgram(std::istream &);
	void run();
};



Hope this helps.


View PostAphex19, on 19 November 2012 - 11:14 AM, said:

Wouldn't it make more sense to just represent the memory as an array of thirty-two, 32-bit (unsigned?) integers?


Depends. If you look at the implementation, it's hyper dyslexic. None of the numbers are natural, so having them as bits doesn't buy you anything there. You might still want to do it, but if you have to pluck things out and reverse them, array notation could ultimately be easier.

This post has been edited by baavgai: 20 November 2012 - 10:33 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1