Re: [OT] CPU simulator written in C
/* frank */ wrote:
[color=blue]
> Case ha scritto:
>[color=green]
>> It's not that complicated.[/color]
>
>
> Thanks a lot.
>
> I was searching only for a "starting input" .[/color]
I write a lot of these. Here are some hints.
1. I would skip the .asm part unless you have some sort of class
assignment going on that requires it. Its an unecessary complication
to have to assemble the code yourself. Better is to figgure out how
to get a "straight binary image" from a standard assembler and use
that. A binary image would contain only the code, without symbols
and other window dressing.
2. Contructing C structures or variables that contain the registers
and flags for the target CPU, these will "overflow" in C without
error. However, you will still need to make a routine that checks
what flags were set during that operation. Typically this is done
by examining the result and the operands, and checking if the result
makes sense. For example, adding two positive numbers and getting
a negative result means an overflow occurred.
3. Although common instruction sets today can be quite large, say
32 bits or more for an instruction, there is typically a much
shorter section of the instruction that determines what instruction
type is being processed. Your typical "execute" case statement
will extract that field and form a case based on that. Be prepared
for a large case statement on most current CPUs. This is good,
because it means your emulator will be fast.
Luck !
--
Samiam is Scott A. Moore
Personal web site: http:/www.moorecad.co m/scott
My electronics engineering consulting site: http://www.moorecad.com
ISO 7185 Standard Pascal web site: http://www.moorecad.com/standardpascal
Classic Basic Games web site: http://www.moorecad.com/classicbasic
The IP Pascal web site, a high performance, highly portable ISO 7185 Pascal
compiler system: http://www.moorecad.com/ippas
Being right is more powerfull than large corporations or governments.
The right argument may not be pervasive, but the facts eventually are.
/* frank */ wrote:
[color=blue]
> Case ha scritto:
>[color=green]
>> It's not that complicated.[/color]
>
>
> Thanks a lot.
>
> I was searching only for a "starting input" .[/color]
I write a lot of these. Here are some hints.
1. I would skip the .asm part unless you have some sort of class
assignment going on that requires it. Its an unecessary complication
to have to assemble the code yourself. Better is to figgure out how
to get a "straight binary image" from a standard assembler and use
that. A binary image would contain only the code, without symbols
and other window dressing.
2. Contructing C structures or variables that contain the registers
and flags for the target CPU, these will "overflow" in C without
error. However, you will still need to make a routine that checks
what flags were set during that operation. Typically this is done
by examining the result and the operands, and checking if the result
makes sense. For example, adding two positive numbers and getting
a negative result means an overflow occurred.
3. Although common instruction sets today can be quite large, say
32 bits or more for an instruction, there is typically a much
shorter section of the instruction that determines what instruction
type is being processed. Your typical "execute" case statement
will extract that field and form a case based on that. Be prepared
for a large case statement on most current CPUs. This is good,
because it means your emulator will be fast.
Luck !
--
Samiam is Scott A. Moore
Personal web site: http:/www.moorecad.co m/scott
My electronics engineering consulting site: http://www.moorecad.com
ISO 7185 Standard Pascal web site: http://www.moorecad.com/standardpascal
Classic Basic Games web site: http://www.moorecad.com/classicbasic
The IP Pascal web site, a high performance, highly portable ISO 7185 Pascal
compiler system: http://www.moorecad.com/ippas
Being right is more powerfull than large corporations or governments.
The right argument may not be pervasive, but the facts eventually are.
Comment