如何设置64位寄存器字段中的第45位?

发布于 2025-01-04 06:19:23 字数 503 浏览 2 评论 0原文

我试图使用 C 设置 64 位宽的寄存器中的第 46 位。我该如何设置该位?

目前我正在这样做:

uint32_t= address ;
uint64_t data =1ULL << 46;

打印这表明位 14 正在设置。我无法设置甚至位 32。如果我设置位 32,它将设置位 0。33 将设置位 1。看起来它正在进行循环移位0-31 后再次从 0 开始。

以 64 位宽注册。

知道我该如何设置这个位吗?

例如:

reg_addr.val = FEATURE_REG;

printf(stdout, "Programming enable at address %x=%llx\n",
    reg_addr.val,reg_addr.val);

data.val = (1ULL << 46);

printf("Data value %llx\n",data.val);}

I was trying to set 46th bit in a register which of 64 bits wide using C.How do i go about setting this bit ?

Currently i am doing this:

uint32_t= address ;
uint64_t data =1ULL << 46;

Printing this is showing that bit 14 is getting set.I am not able to set even bit 32. If i set bit 32 it sets bit 0. 33 will set bit 1. Looks like it is doing circular shifting after 0-31 again it starts over with 0.

Register in 64 bit wide.

Any idea how do i go about setting this bit ?

Eg:

reg_addr.val = FEATURE_REG;

printf(stdout, "Programming enable at address %x=%llx\n",
    reg_addr.val,reg_addr.val);

data.val = (1ULL << 46);

printf("Data value %llx\n",data.val);}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉薄对峙 2025-01-11 06:19:23

如果您使用 uint32_t 或 uint64_t 类型,则正确打印是通过以下方式完成的:

printf(stdout, "Programming enable at address %" PRIu32 "=%" PRIu64 "\n",reg_addr.addr, reg_addr.val);

假设 reg_addr.addr 的类型为 uint32_t,类型 reg_addr.val 的类型为 uint64_t。

If you use types as uint32_t or uint64_t printing correctly is done with:

printf(stdout, "Programming enable at address %" PRIu32 "=%" PRIu64 "\n",reg_addr.addr, reg_addr.val);

assuming reg_addr.addr is of type uint32_t and type reg_addr.val is of uint64_t.

醉梦枕江山 2025-01-11 06:19:23

你的代码是正确的。

您应该检查您的平台是否正确支持 64 位整数类型:

printf("%zu %zu\n", sizeof 1ULL, sizeof data);

should print

8 8

如果是这种情况,则错误可能(如 @pmg 在评论中提到的)在于您检查该位是否设置的方式。

在新的编辑中,您提到它是一个寄存器。由于其易失性属性,IO 寄存器可能具有特殊行为。我建议你首先检查一下用普通物体设置一点。

Your code is correct.

You should check that 64-bit integer types are correctly supported in your platform:

printf("%zu %zu\n", sizeof 1ULL, sizeof data);

should print

8 8

If this is the case, the error is probably (as mentioned by @pmg in the comments) in how you check if the bit is set.

In the new edit, you mentioned it is a register. IO registers can have special behavior due to their volatile property. I suggest you to first check to set a bit with a normal object.

百合的盛世恋 2025-01-11 06:19:23

我希望您不要检查该行的输出来得出移位未正确完成的结论!?

printf(stdout, "在地址 %x=%llx\n 处启用编程", reg_addr.val,reg_addr.val);

将 64 位值两次传递给 printf,但使用 %x(可能是 32 位)和 %llx(64 位)来输出值将不起作用。我猜你的意思是在第一个参数处获取 reg_addr.val 的地址!?

printf(stdout, "在地址 %x=%llx\n 处启用编程", ®_addr.val,reg_addr.val);

I hope you do not check the output of this line to conclude the shifting is not done correctly!?

printf(stdout, "Programming enable at address %x=%llx\n", reg_addr.val,reg_addr.val);

Passing the 64 bit value two times to printf, but using %x (probably 32 bit) and %llx (64 bit) to output the values will not work. I guess you meant to take the address of reg_addr.val at the first parameter!?

printf(stdout, "Programming enable at address %x=%llx\n", ®_addr.val,reg_addr.val);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文