将十六进制转换为二进制 - ASM

发布于 2025-02-11 02:05:47 字数 122 浏览 2 评论 0原文

在AX中给定一个数字,将相应的位字符串存储在Str1中。 如果AX = 0x1234,则结果应为: str1 = 0001001000111

我如何将AX中的所有内容转换为二进制 我必须使用循环吗? 如何实施此方法?

given a number in AX, store the corresponding bit string in str1.
if AX = 0x1234, the result should be:
str1 = 0001001000111

How can I convert everything in AX to binary
Do I have to use loop?
How to implement this method?

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

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

发布评论

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

评论(1

妥活 2025-02-18 02:05:47

ax中输入编号,然后输出二进制字符串在[rdi]中。如果ax = 0x1234[rdi] =“ 0001001000110100”带有终止​​空字符。

使用NASM靶向X86_64。

SSE2优化版本

基于彼得·科德斯(Peter Cordes)的职位,带有手动调度。

movd xmm2, eax
mov rdx, 0x0102040810204080
movq xmm1, rdx
mov edx, 0x30303030
movd xmm0, edx
punpcklbw xmm2, xmm2
punpcklwd xmm2, xmm2
punpckldq xmm2, xmm2
pshufd xmm2, xmm2, 0x4e; swap high64/low64
punpcklqdq xmm1, xmm1; bit-select mask
pand xmm2, xmm1
pcmpeqb xmm1, xmm2
pshufd xmm0, xmm0, 0; "0000..."
psubb xmm0, xmm1
movdqu [rdi], xmm0
mov byte [rdi + 16], 0

旧版本使用展开的环路

每次迭代都不依赖于先前的迭代,并且循环完全展开。

如果您不熟悉NASM宏。阅读文档( https://wwwww.nasm.us/xdoc/2.10 rc8/html/nasmdoc4.html )。

%assign i 0
%rep 16
  xor edx, edx
  bt eax, 15 - i
  adc edx, 48
  mov [rdi + i], dl
  %assign i i + 1
%endrep
mov byte [rdi + 16], 0

Input number in ax, and output binary string in [rdi]. If ax = 0x1234, [rdi] = "0001001000110100" with a terminating null character.

Using NASM targeting x86_64.

SSE2 optimized version

Based on Peter Cordes' post, with hand-tuned scheduling.

movd xmm2, eax
mov rdx, 0x0102040810204080
movq xmm1, rdx
mov edx, 0x30303030
movd xmm0, edx
punpcklbw xmm2, xmm2
punpcklwd xmm2, xmm2
punpckldq xmm2, xmm2
pshufd xmm2, xmm2, 0x4e; swap high64/low64
punpcklqdq xmm1, xmm1; bit-select mask
pand xmm2, xmm1
pcmpeqb xmm1, xmm2
pshufd xmm0, xmm0, 0; "0000..."
psubb xmm0, xmm1
movdqu [rdi], xmm0
mov byte [rdi + 16], 0

Old version using an unrolled loop

Each iteration has no dependency on the previous iteration, and the loop is fully unrolled.

If you are not familiar with NASM macros. Read the docs (https://www.nasm.us/xdoc/2.10rc8/html/nasmdoc4.html).

%assign i 0
%rep 16
  xor edx, edx
  bt eax, 15 - i
  adc edx, 48
  mov [rdi + i], dl
  %assign i i + 1
%endrep
mov byte [rdi + 16], 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文