# How can I write a 64 bit number in Control Register from Python

**URL:** <https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519>\
**Category:** Support\
**Created:** [April 27, 2023, 9:42am UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519 "2023-04-27T09:42:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide-giacomini](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/davide-giacomini/32/3137_2.png) [@davide-giacomini](https://discuss.pynq.io/u/davide-giacomini)\
**Post date:** [April 27, 2023, 9:42am UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/1 "2023-04-27T09:42:43Z")

</div>

Hello everyone,

I am writing a Python interface between the ARM and the FPGA of my Pynq Z2 and I have to write in the Control Register some scalars of 64 bits. For now I found a workaround like this:

```auto
MSB_mu_cpu = Fxp(mu_cpu).like(d_fixed_t).bin()[:32]
LSB_mu_cpu = Fxp(mu_cpu).like(d_fixed_t).bin()[32:]
MSB_DELTA_T = Fxp(DELTA_T).like(d_fixed_t).bin()[:32]
LSB_DELTA_T = Fxp(DELTA_T).like(d_fixed_t).bin()[32:]

lin_ip.write(0x10, buffer_X_FPGA.physical_address)
lin_ip.write(0x1c, int(LSB_mu_cpu, 2))
lin_ip.write(0x20, int(MSB_mu_cpu, 2))
lin_ip.write(0x28, int(LSB_DELTA_T, 2))
lin_ip.write(0x2c, int(MSB_DELTA_T, 2))

```

In this code, I firstly get the binary string of te variables already converted in fixed points and then I write manually the LSB and MSB bits. Although, when I have to read from memory I will get still the MSB and LSB separately, and this creates some issues when riconverting them.

For reference, I am using this lbrary for fixed ponints: [GitHub - francof2a/fxpmath: A python library for fractional fixed-point (base 2) arithmetic and binary manipulation with Numpy compatibility.](https://github.com/francof2a/fxpmath).

Thank you in advance,  
Davide

---

<div class="post-metadata">

**Author:** ![briansune](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/briansune/32/3087_2.png) [@briansune](https://discuss.pynq.io/u/briansune)\
**Post date:** [April 27, 2023, 11:50am UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/2 "2023-04-27T11:50:01Z")

</div>

@davide-giacomini

Zynq ARM A9 is 32bit so even you need 64bit ctrl TX, should it split it into at least 2 cycle of combine 64 bit data?

So instead of considering it as 1 64 bit TX the back-end ends up with two 32bit join data.

ENJOY~

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 27, 2023, 1:35pm UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/3 "2023-04-27T13:35:04Z")

</div>

Hi @davide-giacomini,

For read, you can request a longer read, `length=8`

> <https://github.com/Xilinx/PYNQ/blob/master/pynq/mmio.py#L82>

And for write, you can pass the data as bytes

> <https://github.com/Xilinx/PYNQ/blob/master/pynq/mmio.py#L130>

Mario

---

<div class="post-metadata">

**Author:** ![briansune](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/briansune/32/3087_2.png) [@briansune](https://discuss.pynq.io/u/briansune)\
**Post date:** [April 27, 2023, 3:45pm UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/4 "2023-04-27T15:45:32Z")

</div>

@marioruiz

read(self, offset=0, length=4, word\_order=“little”):

So does this mean we could read back as either little-endian or big-endian in MMIO API?  
But it is still in a byte form no matter how.  
How about write ← could we write as either little-endian or big-endian in MMIO API?

Thank you

ENJOY~

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 27, 2023, 5:55pm UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/5 "2023-04-27T17:55:20Z")

</div>

Hi Brian,

> So does this mean we could read back as either little-endian or big-endian in MMIO API?  
> But it is still in a byte form no matter how.

Only at the word level (32-bit). The return would be an `int`

> How about write ← could we write as either little-endian or big-endian in MMIO API?

No, this capability is not part of the write. If you want to write more than 32-bit, you need to pass the data as `bytes`

Mario

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [April 27, 2023, 5:55pm UTC](https://discuss.pynq.io/t/how-can-i-write-a-64-bit-number-in-control-register-from-python/5519/6 "2023-04-27T17:55:25Z")

</div>


