flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Linux > Store CPUID values into a String

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
dstyl



Joined: 23 Jul 2015
Posts: 48
Store CPUID values into a String
Hi FASM members Wink
im writing a small cpuid programm based on agner.org s asmlib.
I have trouble storing the return values from cpuid (eax,ebx,ecx,edx)
into a string to print.
Thanks in advance Smile

Code:

; -----------------------------------------------------------------------------
;Simple CPUID Programm. Based on agner.orgs asmlib
; -----------------------------------------------------------------------------
        global  main

        extern  printf

        default rel

                section .text

main:
                mov                     rdititle
                xor                     raxrax
                call            printf
                call            cpuid                           ;
                mov                     rsibfer
                mov                     rdiname
                xor                     raxrax
                call            printf
                ret
cpuid:
        push            rbx
        mov             eaxesi
        mov             ecxedx
        cpuid                          ; input eax, ecx. output eax, ebx, ecx, edx
        mov             [bfer],    eax
        mov             [bfer+4],  ebx
        mov             [bfer+8],  ecx
        mov             [bfer+12], edx
        pop             rbx        
        ret

                section .data

name:   db              "Vendor %s"100
title:  db              "CPUID v1.0 by capo245 based on agner.org s asmlib"100
bfer:   dd              ""0


Post 30 Apr 2017, 11:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
Your bfer is too short. Also, you need to zero terminate the string when you store it.

Code:
;...
        mov             [bfer+12], edx
        mov             byte[bfer+16], 0 ;zero terminate
;...
bfer:   rd              5 ;reserve enough space for the whole string

Post 30 Apr 2017, 14:14
View user's profile Send private message Visit poster's website Reply with quote
dstyl



Joined: 23 Jul 2015
Posts: 48
Thanks for your advice but it still doesnt work.
Now i have

Code:

; -----------------------------------------------------------------------------
;Simple CPUID Programm. Based on agner.orgs asmlib
; -----------------------------------------------------------------------------
        global  main

        extern  printf

        default rel

                section .text

main:
                mov                     rdititle
                xor                     raxrax
                call            printf
                call            cpuid                           ;
                mov                     rsibfer
                mov                     rdiname
                xor                     raxrax
                call            printf
                ret
cpuid:
        push            rbx
        mov             eaxesi
        mov             ecxedx
        cpuid                          ; input eax, ecx. output eax, ebx, ecx, edx
        mov             [bfer],    eax
        mov             [bfer+4],  ebx
        mov             [bfer+8],  ecx
        mov             [bfer+12], edx
        mov         byte[bfer+16], 0
        pop             rbx        
        ret

                section .data

name:   db              "Vendor %s"100
title:  db              "CPUID v1.0 by capo245 based on agner.org s asmlib"100
bfer:   resb    5


Post 30 Apr 2017, 15:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
Are trying to convert fasm code to another assembler?

resb 5 is not the same as rd 5. You'll need at least 17 bytes for your buffer.
Post 30 Apr 2017, 16:12
View user's profile Send private message Visit poster's website Reply with quote
dstyl



Joined: 23 Jul 2015
Posts: 48
Yes im using nasm because the book im reading uses nasm. Thanks for your advice Smile Ive changed bfer to bfer: resb 17 but it still doesnt show the cpuid string.
Post 30 Apr 2017, 20:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
What does it show?
Post 01 May 2017, 00:14
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 673
Why are u using "cpuid" as a label name?

use eax,0 for CPUID

The vendor string starts with ebx + edx + ecx (if I remember it correctly)

resb goes to .bss
Post 01 May 2017, 00:17
View user's profile Send private message Reply with quote
dstyl



Joined: 23 Jul 2015
Posts: 48

revolution wrote:
What does it show?


Output is

Code:

CPUID v1.0 by capo245 based on agner.org s asmlib
Vendor 


Post 01 May 2017, 08:19
View user's profile Send private message Reply with quote
dstyl



Joined: 23 Jul 2015
Posts: 48

system error wrote:
Why are u using "cpuid" as a label name?

use eax,0 for CPUID

The vendor string starts with ebx + edx + ecx (if I remember it correctly)

resb goes to .bss


Thanks now i have but ist still shows no Vendor String

Code:

; -----------------------------------------------------------------------------
;Simple CPUID Programm. Based on agner.orgs asmlib
; -----------------------------------------------------------------------------
        global  main

        extern  printf

        default rel

                section .text

main:
                mov                     rdititle
                xor                     raxrax
                call            printf
                call            cpuid                           ;
                mov                     rsibfer
                mov                     rdiname
                xor                     raxrax
                call            printf
                ret
cpuid:
        push            rbx
        mov             eax0
        mov             ecxedx
        cpuid                          ; input eax, ecx. output eax, ebx, ecx, edx
        mov             [bfer],    eax
        mov             [bfer+4],  ebx
        mov             [bfer+8],  ecx
        mov             [bfer+12], edx
        mov         byte[bfer+16], 0
        pop             rbx        
        ret

                section .data

name:   db              "Vendor %s"100
title:  db              "CPUID v1.0 by capo245 based on agner.org s asmlib"100
                section .bss
bfer:   resb    17


Post 01 May 2017, 08:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
Regarding the CPUID instruction. Your calling value for EAX is undefined, and your output storage string is also wrong.

1. Set EAX to be the function number you want for CPUID.
2. Set the output string according to the CPUs output.
Post 01 May 2017, 13:06
View user's profile Send private message Visit poster's website Reply with quote
dstyl



Joined: 23 Jul 2015
Posts: 48
Thanks for your advice sadly i dont know what is meant with function number for CPUID.
How do i set the outputstring to the cpu outpout i thought it returns the string in eax, ebx, ecx and edx.
Could you please post some code so i could learn from you?
Post 01 May 2017, 14:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
There is a Wikipedia entry: https://en.wikipedia.org/wiki/CPUID

Also the CPU manuals (from Intel and/or AMD) have a lot more detail.
Post 01 May 2017, 14:26
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 673
call cpuid
...
cpuid:

cpuid

ret

what is this? Is cpuid a function name or an X86 instruction?
Post 02 May 2017, 03:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries

system error wrote:
Is cpuid a function name or an X86 instruction?

In NASM it can be both.
Post 02 May 2017, 04:04
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 673

revolution wrote:
In NASM it can be both.



Surprised

How did they come up with such design decision? Allowing keywords to be used as programmer-defined identifiers is breaking every syntactic rules I've known so far, even in HLLs. Imagine jmp jmp, call call, loop loop,, yong yong Very Happy . Imagine how cryptic your source could look like.
Post 02 May 2017, 10:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15299
Location: Bigweld Industries
Indeed, if you want to write confusing code then NASM allows you a little bit more leeway than fasm. As usual it is up to the programmer to make sure it all makes sense. It isn't really the job of the language to enforce beautiful looking code. Any language that is so anal about style will probably be too restrictive to be nice to program in anyway.
Post 02 May 2017, 10:56
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 889
I have mixed feelings here. On one hand, it's a bit more confusing to be able to use a label as an instruction name. On the other, code won't break just because Intel decide to add an instruction with the same name as a label you have used. So I think NASM does it right.

(still it's obviously not the same as a macro replacing the instruction which is much more confusing and should be done rarely or for older code if new instruction clashes with it etc)
Post 07 May 2017, 15:06
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 673

revolution wrote:
It isn't really the job of the language to enforce beautiful looking code. Any language that is so anal about style will probably be too restrictive to be nice to program in anyway.



It's not about beautiful looking code. It's about semantics. People created textual symbols and symbolic languages because they didn't want to get confused with similar-looking patterns which proven to be error-prone by the past machine coders.

It's like naming your kid as Tyrone, and his kids as Tyrone, and their next kids as all Tyrone. Is it wrong? No but it creates a very confusing semantics. Imagine the family name....
Post 07 May 2017, 18:08
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2124
Location: Usono (aka, USA)

system error wrote:


Surprised

How did they come up with such design decision? Allowing keywords to be used as programmer-defined identifiers is breaking every syntactic rules I've known so far, even in HLLs. Imagine jmp jmp, call call, loop loop,, yong yong Very Happy . Imagine how cryptic your source could look like.



While most programming languages are full of restrictions, some go out of their way to be user-friendly to end users, where even "normal" people are expected to be able to learn and use such a (e.g. scripting) language. REXX, for instance, avoids reserved words, confusing symbols, pointers, manual memory management, specific-sized ints, etc. in an attempt to be easy to use. It also supports nested comments and case insensitive keywords (whereas Modula-2 and Oberon have uppercase reserved words but are case sensitive, unlike Pascal).

Bah, I really suck at REXX, but here's a wimpy example:


Code:

/* REXX */

system='System' ; if=15 ; else=system error

do while if > 0
  x=d2x(if)
  if if \= 10 then say center(if,3':' else x
  else say ten ':' else x
  /* foo /* bar */ baz */
  if = if - 1
end





Code:

15  : System ERROR F
14  : System ERROR E
13  : System ERROR D
12  : System ERROR C
11  : System ERROR B
TEN : System ERROR A
 9  : System ERROR 9
 8  : System ERROR 8
 7  : System ERROR 7
 6  : System ERROR 6
 5  : System ERROR 5
 4  : System ERROR 4
 3  : System ERROR 3
 2  : System ERROR 2
 1  : System ERROR 1




It knows the context, so it knows what is a variable and what is a reserved keyword.
Post 08 May 2017, 14:18
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2124
Location: Usono (aka, USA)

system error wrote:

It's not about beautiful looking code. It's about semantics. People created textual symbols and symbolic languages because they didn't want to get confused with similar-looking patterns which proven to be error-prone by the past machine coders.

It's like naming your kid as Tyrone, and his kids as Tyrone, and their next kids as all Tyrone. Is it wrong? No but it creates a very confusing semantics. Imagine the family name....



Sorry for going off-topic. (Perhaps this and my last post should be split off into the Heap.)

There's a lot that could be said on this, even though I'm no expert. Redundancy is bad when you're trying to be exact, but that's why there are many ways of identifying something, and context matters a lot. Generally speaking, the smaller number of reserved words, the better. But a lot of times "reserved", even in traditional programming languages, only applies to certain sections of the grammar. So you can't necessarily use "if" as a variable in C, but you can make a structure member (or indeed several, since C89 or MASMv6) named that. (Example omitted because it's pointless.)
Post 08 May 2017, 14:42
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.