Implementing an 8 bit fixed point register

moogyd at yahoo.co.uk moogyd at yahoo.co.uk
Tue Jul 1 06:56:04 EDT 2008


On 1 Jul, 08:57, nickooooola <nick83... at gmail.com> wrote:
> Hello to all
> I'm about to write a simulator for a microcontroller in python
> (why python? because I love it!!!)
>
> but I have a problem.
>
> The registry of this processor are all 8 bit long (and 10 bit for some
> other strange register)
> and I need to simulate the fixed point behaviour of the register,
> and to access the single bit.
>
> f.x. (this is a pseudo python session, only for understanding)
>
> >>> reg1 = fixed_int(8)
> >>> reg2 = fixed_int(10)
> >>> reg1[0].set()
> or
> >>> reg1[0] = 1 # or True? how to rapresent a binary bit
> >>> reg1[0]
> 1
> >>> reg1[1]
> 0
> >>> reg1[9]
>
> <exception .... blah blah not in range>>>> reg2 = 0x7FE   # in binary  11111111110 , or 11 bit long
> >>> reg2
>
> 0x7FE
> #or 1111111110, the memorization truncate the upper bits ( or perhaps
> generate an exception?)>>> reg2 += 0x02 #the result is 10000000000, again not contained in 10 bit
> >>> reg2
>
> 0x00
> # truncated again>>> myprocessor.flags['z']
>
> 1
> # or True? Z flag indicated an overflow in arithmetic operations
>
> Is possibile to do so in python?
>
> thanks

I am not sure if it is exactly what you are looking for (it may be a
bit low level), but myHDL may be interesting. It provides low level H/
W simulation capabilities.

http://myhdl.jandecaluwe.com/doku.php


Steven



More information about the Python-list mailing list