从寄存器连接字符串并打印它们(CPUID)

Joining strings from registers and printing them (CPUID)

开始学习 NASM 汇编,我在 Stack Overflow 中查看了一些汇编问题,并在这里找到了这个: Concatenating strings from registers and printing them

I believe that this question is not duplicated because I am trying to replicate the code in NASM and also things were not very clear in the other question.

我决定在NASM中复制这段代码,但我不太理解有问题的 MASM 代码。
我了解了 CPUID 并做了一些测试程序。

按顺序,我想知道我们如何连接寄存器然后使用 NASM 在屏幕上打印它们。

我想打印 'ebx' + 'edx' + 'ecx' 因为这是 CPUID 输出由 what I see in GDB.[=17= 组织的方式]

我用 eax=1

调用了 CPUID

"String" 不是一个非常精确的术语。 CPUID/EAX=0 的供应商标识字符串仅包含 12 个 ASCII 字符,打包到 3 个 DWORD 寄存器中。没有像 C 中那样的终止字符,也没有像 PASCAL 中那样的长度信息。但它总是相同的寄存器,而且总是 3*4=12 个字节。这是写入系统调用的理想选择:

section .bss

    buff resb 12

section .text
global _start

_start:

    mov eax, 0
    cpuid

    mov dword [buff+0], ebx     ; Fill the first four bytes
    mov dword [buff+4], edx     ; Fill the second four bytes
    mov dword [buff+8], ecx     ; Fill the third four bytes


    mov eax, 4                  ; SYSCALL write
    mov ebx, 1                  ; File descriptor = STDOUT
    mov ecx, buff               ; Pointer to ASCII string
    mov edx, 12                 ; Count of bytes to send
    int 0x80                    ; Call Linux kernel

    mov eax, 1                  ; SYSCALL exit
    mov ebx, 0                  ; Exit Code
    int 80h                     ; Call Linux kernel