Pergunta de entrevista da empresa Apple

Accurately (this is the catch) read a 64bit register value using a method that can read only 32bit at a time

Respostas da entrevista

Sigiloso

5 de jun. de 2020

uint32_t read_context; memcpy(&read_context, (void *)(REGISTER_BASE_ADDR), 4); printf("Register MSW: %x \t", read_context, 0, 0, 0, 0, 0); memcpy(&read_context, (void *)(REGISTER_BASE_ADDR + 4), 4); printf("Register LSW: %x \t" , read_context, 0, 0, 0, 0, 0);

6

Sigiloso

23 de ago. de 2020

#include #include void register_read(void* reg,void *result); int main() { //printf("Hello World"); uint64_t reg=0xAAAAAAAAFFFFFFFF,result; register_read((void*)®,(void*)&result); printf("%lX",result); return 0; } void register_read(void* reg,void *result){ uint32_t *ptr1,*ptr2; ptr1=(uint32_t *)(reg); ptr2=(uint32_t *)(result); for(int i=0;i<2;i++){ *ptr2=*ptr1; ptr1++; ptr2++; }

2

Sigiloso

27 de mar. de 2022

uint64_t result = (uint64_t) read32(ptr1) | read32(ptr1+4)

Sigiloso

18 de fev. de 2019

Create two new buffers. 32 bit buffer and 64 bit buffer. Pass the 32 bit buffer to read32() and when you get back 32 bits, store that in the 64 bit buffer (remember to keep track of the index pointing to the first empty entry in 64 bit buffer). Repeat the above again with empty 32 bit buffer.