Implementing an 8 bit fixed point register

nickooooola nick83ola at gmail.com
Tue Jul 1 02:57:39 EDT 2008


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



More information about the Python-list mailing list