Emulator

(1/1)

Richard Marks:
Emulator

This is an emulator for a simple non-existent computer system. ^-^ (The ECPU)
There is a total of 2MB of RAM in which you may execute your own programs.
1MB of RAM is your program space, and 1MB of RAM is for your code's usage.
You may be thinking "one meg? thats nothing!" well my friend, this means that you can have up to a whopping max-length of 1,048,576 instructions!

Memory Map

The memory is mapped in two 1MB chunks.
Your program gets loaded into virtual memory address 0x100000 and may extend all the way to address 0x1FFFFF

This leaves you with the memory from 0x000000 to 0x0FFFFF in which you may write data and store your variables.

If you write values into virtual memory between 0x100000 and 0x1FFFFF then you will be modifying the program code.
This can be a useful technique for some hardcore coders as long as you know what you are doing.

At this time, you may only use 32-bit integers in any memory location.

Richard Marks:
New features in version 0.0.6

I've added some new features in the latest version of the ECPU project.

STACK

There now is what is called a STACK that is mainly used to pass parameters to the new BIOS routines, though I'm sure you will find some interesting uses for it.

Here is how it works.
At the end of FREE memory 0x0FFFFF the STACK begins.
When you PUSH a value on the stack, the stack will grow backwards.
Meaning if you push one value on the stack, the stack will have a size of one, and you will have 1 less memory location in which you may store data. (Well, if you use the location that the stack stores data..you will corrupt your stack, and pretty much cause chaos.

When you POP a value off the stack, the stack shrinks.

If you don't quite get it, maybe this illustration will help:

Code:


This is an empty stack []

This is your free memory <...>

This is your program's memory {$$$}

This is the entire memory <...>[]{$$$}

If I push an A on the stack, then we eat up 1 location in your free memory like this <..>[A]{$$$}

If I push a letter B on the stack, then we eat up another location in free memory <.>[BA]{$$$}

When I pop off a value, the stack shrinks <..>[A]{$$$}

If I pop again, the stack will be empty and we will have our full free memory again <...>[]{$$$}


Did that help any?

BIOS Routines

Now we have some really nifty new stuff!

There is a new instruction in the ECPU instruction set called sys that is used to execute these nice extended functionality routines.

The sys instruction is used in conjunction with the stack for passing the parameters to the BIOS routines.

BIOS routines use the stack to get the parameters.

The parameters are pushed on to the stack in reverse order. (The first parameter is pushed last.)


For example, to use the "get_char" BIOS routine, you need to push the memory location in which you wish to store the character that was read from stdin before calling the routine.
Code:

PUSH 1000
SYS 0

will read a single character from stdin and store it in memory location 1000

Code:

PUSH 500
SYS 1

will read a string from stdin and store it starting from memory location 500 and will advance the data pointer to the end of the string. if the string will not fit in memory, the string will be truncated.

When SYS finishes, the parameters that it used are POPed off the stack.
If you push more parameters than a routine needs, the unused parameters are ignored.
You should be careful not to waste stack space by forgetting to clear it out.

Navigation

[0] Message Index