如何以十六进制打印寄存器的内容

发布于 2024-09-05 04:32:55 字数 387 浏览 3 评论 0原文

我目前正在开始使用 NASM,想知道如何使用 NASM 以十六进制输出寄存器的内容。 我可以输出 eax 的内容,

section .bss
    reg_buf: resb 4
.
.
.
print_register:
    mov [reg_buf], eax
    mov eax, SYS_WRITE
    mov ebx, SYS_OUT
    mov ecx, reg_buf
    mov edx, 4
    int 80h
    ret

假设 eax 包含 0x44444444,那么输出将是“DDDD”。显然,每对“44”都被解释为“D”。我的 ASCII 表认可这一点。

但是我如何让我的程序输出实际的寄存器内容(0x44444444)?

I'm currently getting started with NASM and wanted to know, how to output the contents of a register with NASM in Hexadecimal.
I can output the content of eax with

section .bss
    reg_buf: resb 4
.
.
.
print_register:
    mov [reg_buf], eax
    mov eax, SYS_WRITE
    mov ebx, SYS_OUT
    mov ecx, reg_buf
    mov edx, 4
    int 80h
    ret

Let's say eax contains 0x44444444 then the output would be "DDDD". Apparently each pair of "44" is interpreted as 'D'. My ASCII table approves this.

But how do I get my program to output the actual register content (0x44444444)?

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

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

发布评论

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

评论(2

往日情怀 2024-09-12 04:32:55

这就是我被教导要做的事情..

.
.
SECTION .data
numbers: db "0123456789ABCDEF" ;; have initialized string of all the digits in base 16
.
.
.
  ;;binary to hex

mov al , byte [someBuffer+someOffset] ;; some buffer( or whatever ) with your data in
mov ebx, eax  ;; dealing with nybbles so make copy for obtaining second nybble

and al,0Fh   ;; mask out bits for first nybble
mov al, byte [numbers+eax] ;; offset into numbers is the hex equiv in numbers string
mov byte [someAddress+someOffset+2], al
;;store al into a buffer or string or whatever it's the first hex number

shr bl, 4 ;; get next nybble
mov bl, byte [numbers+ebx] ;; get the hex equiv from numbers string
mov byte [someAddress+someOffset+1], bl
;;place into position next to where al was stored, this completes the process,
;;you now have your hexadecimal equivalent output it or whatever you need with it
.
.
.

This is how i was taught to do it..

.
.
SECTION .data
numbers: db "0123456789ABCDEF" ;; have initialized string of all the digits in base 16
.
.
.
  ;;binary to hex

mov al , byte [someBuffer+someOffset] ;; some buffer( or whatever ) with your data in
mov ebx, eax  ;; dealing with nybbles so make copy for obtaining second nybble

and al,0Fh   ;; mask out bits for first nybble
mov al, byte [numbers+eax] ;; offset into numbers is the hex equiv in numbers string
mov byte [someAddress+someOffset+2], al
;;store al into a buffer or string or whatever it's the first hex number

shr bl, 4 ;; get next nybble
mov bl, byte [numbers+ebx] ;; get the hex equiv from numbers string
mov byte [someAddress+someOffset+1], bl
;;place into position next to where al was stored, this completes the process,
;;you now have your hexadecimal equivalent output it or whatever you need with it
.
.
.
故事灯 2024-09-12 04:32:55

您需要首先将寄存器格式化为文本字符串。最简单的 API 可能是 itoa,然后是 write 调用。您需要分配一个字符串缓冲区才能使其工作。

如果您不想在汇编中执行此操作,您可以创建一个快速的 C/Python/Perl/etc 程序来从您的程序中读取并生成所有输出文本。

You need to format your register as a text string first. The simplest to use API would likely be itoa, followed by your write call. You will need a string buffer allocated for this to work.

If you don't want to do it in assembly, you can make a quick C/Python/Perl/etc program to read from your program and make all output text.

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