Author Topic: Problem when storing a string.  (Read 2382 times)

Offline aVoX

  • Jr. Member
  • *
  • Posts: 13
Problem when storing a string.
« on: August 24, 2011, 02:26:46 PM »
Hello!
When rax/eax is initialized to 0, the processor vendor's name is stored in the rbx/ebx, rdx/edx and rcx/ecx registers. I want to store them in a global variable so that I can build the string together and return it. For further vendor identification in other functions, I additionally store ecx in another global variable, so I can quickly check the manufacturer without executing the CPUID instruction another time.
My problem is: When I return the full vendor name string (12 bytes) it reads into the second, shorter string (4 bytes), so instead of "AuthenticAMD" I get "AuthenticAMDcAMD", but why?
Code:
Code: [Select]
%define INTEL           6C65746Eh     ; "letn" - last part (ecx) of GenuineIntel
%define AMD             444D4163h     ; "DMAc" - last part (ecx) of AuthenticAMD
%define OTHER           0h
[...]
global _GetVendor
export _GetVendor
_GetVendor:
    XOR     eax, eax
    CPUID
    MOV     [g_vendor], ebx
    MOV     [g_vendor+4], edx
    MOV     [g_vendor+8], ecx
   
    PUSH    g_vendor
    POP     eax

    CMP     ecx, INTEL
    JE      .setintel
   
    CMP     ecx, AMD
    JE      .setamd

    MOV     dword [g_vendorId], OTHER
    JMP     .exit

  .setamd:
    MOV     dword [g_vendorId], AMD
    JMP     .exit

  .setintel:
    MOV     dword [g_vendorId], INTEL 

  .exit:
    RET     0

[...]
[section .bss]
    g_model    resb 48
    g_vendor   resb 12
    g_vendorId resb 4
; Note: No unicode!

Does this have something to do with the NTS?
Thanks in advance, aVoX.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2364
  • Country: us
Re: Problem when storing a string.
« Reply #1 on: August 24, 2011, 04:56:00 PM »
String not zero-terminated?

Best,
Frank


Offline aVoX

  • Jr. Member
  • *
  • Posts: 13
Re: Problem when storing a string.
« Reply #2 on: August 24, 2011, 06:44:42 PM »
Ok, all the strings written by CPUID in the respective registers are not null-terminated, so I will have to add an extra byte for a null-terminating symbol.
Thanks and bye.