More compact source code you may get with something like
var a: array[32, byte]
var p: ptr uint64
var myUint64: uint64 = 123456
p = cast[ptr uint64](addr a[8])
p[] = myUint64
Runbut so you have no influence on endianess and of course you have to care that you do write only to valid memory regions. The final assembler code may be identical to your above bit masking operations.
