Implementing an 8 bit fixed point register
nick83ola at gmail.com
Tue Jul 1 08:57:39 CEST 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 = 1 # or True? how to rapresent a binary bit
<exception .... blah blah not in range>
>>> reg2 = 0x7FE # in binary 11111111110 , or 11 bit long
#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
# truncated again
# or True? Z flag indicated an overflow in arithmetic operations
Is possibile to do so in python?
More information about the Python-list