/*************************************************************** __CPU_BYTEORDER.C Byte-order accessors for canonical PROGRAM fields and architectural data-object representation. PART OF : CPU - library . Copyright (C) 2026 by Andrew V.Kosteltsev. All Rights Reserved. ***************************************************************/ #include #include __mpu_uint16_t __cpu_data_get_u16( const __mpu_UNIT_t *p ) { __mpu_uint16_t v = 0; if( p ) memcpy( &v, p, sizeof(v) ); return( v ); } __mpu_uint32_t __cpu_data_get_u32( const __mpu_UNIT_t *p ) { __mpu_uint32_t v = 0; if( p ) memcpy( &v, p, sizeof(v) ); return( v ); } __mpu_uint64_t __cpu_data_get_u64( const __mpu_UNIT_t *p ) { __mpu_uint64_t v = 0; if( p ) memcpy( &v, p, sizeof(v) ); return( v ); } void __cpu_data_put_u16( __mpu_UNIT_t *p, __mpu_uint16_t v ) { if( p ) memcpy( p, &v, sizeof(v) ); } void __cpu_data_put_u32( __mpu_UNIT_t *p, __mpu_uint32_t v ) { if( p ) memcpy( p, &v, sizeof(v) ); } void __cpu_data_put_u64( __mpu_UNIT_t *p, __mpu_uint64_t v ) { if( p ) memcpy( p, &v, sizeof(v) ); } __mpu_uint16_t __cpu_code_get_u16( const __mpu_UNIT_t *p ) { if( !p ) return( 0 ); return (__mpu_uint16_t)(((__mpu_uint16_t)p[0] << 8) | (__mpu_uint16_t)p[1]); } __mpu_uint32_t __cpu_code_get_u32( const __mpu_UNIT_t *p ) { __mpu_uint32_t v; if( !p ) return( 0 ); v = ((__mpu_uint32_t)p[0] << 24); v |= ((__mpu_uint32_t)p[1] << 16); v |= ((__mpu_uint32_t)p[2] << 8); v |= (__mpu_uint32_t)p[3]; return( v ); } __mpu_uint64_t __cpu_code_get_u64( const __mpu_UNIT_t *p ) { __mpu_uint64_t v = 0; int k; if( !p ) return( 0 ); for( k = 0; k < 8; ++k ) v = ( v << 8 ) | p[k]; return( v ); } void __cpu_code_put_u16( __mpu_UNIT_t *p, __mpu_uint16_t v ) { if( !p ) return; p[0] = (__mpu_UNIT_t)(v >> 8); p[1] = (__mpu_UNIT_t)v; } void __cpu_code_put_u32( __mpu_UNIT_t *p, __mpu_uint32_t v ) { if( !p ) return; p[0] = (__mpu_UNIT_t)(v >> 24); p[1] = (__mpu_UNIT_t)(v >> 16); p[2] = (__mpu_UNIT_t)(v >> 8); p[3] = (__mpu_UNIT_t)v; } void __cpu_code_put_u64( __mpu_UNIT_t *p, __mpu_uint64_t v ) { int k; if( !p ) return; for( k = 7; k >= 0; --k ) { p[k] = (__mpu_UNIT_t)( v & __mpu_UINT64_C( 0xff ) ); v >>= 8; } }