flat assembler
Message board for the users of flat assembler.
Index
> Linux > Store CPUID values into a String Goto page 1, 2 Next |
Author |
|
revolution 30 Apr 2017, 14:14
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 |
|||
30 Apr 2017, 14:14 |
|
dstyl 30 Apr 2017, 15:01
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 rdi, title xor rax, rax call printf call cpuid ; mov rsi, bfer mov rdi, name xor rax, rax call printf ret cpuid: push rbx mov eax, esi mov ecx, edx 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", 10, 0 title: db "CPUID v1.0 by capo245 based on agner.org s asmlib", 10, 0 bfer: resb 5 |
|||
30 Apr 2017, 15:01 |
|
revolution 30 Apr 2017, 16:12
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. |
|||
30 Apr 2017, 16:12 |
|
dstyl 30 Apr 2017, 20:12
Yes im using nasm because the book im reading uses nasm. Thanks for your advice Ive changed bfer to bfer: resb 17 but it still doesnt show the cpuid string.
|
|||
30 Apr 2017, 20:12 |
|
revolution 01 May 2017, 00:14
What does it show?
|
|||
01 May 2017, 00:14 |
|
system error 01 May 2017, 00:17
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 |
|||
01 May 2017, 00:17 |
|
dstyl 01 May 2017, 08:19
revolution wrote: What does it show? Output is Code: CPUID v1.0 by capo245 based on agner.org s asmlib Vendor |
|||
01 May 2017, 08:19 |
|
dstyl 01 May 2017, 08:21
system error wrote: Why are u using "cpuid" as a label name? 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 rdi, title xor rax, rax call printf call cpuid ; mov rsi, bfer mov rdi, name xor rax, rax call printf ret cpuid: push rbx mov eax, 0 mov ecx, edx 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", 10, 0 title: db "CPUID v1.0 by capo245 based on agner.org s asmlib", 10, 0 section .bss bfer: resb 17 |
|||
01 May 2017, 08:21 |
|
revolution 01 May 2017, 13:06
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. |
|||
01 May 2017, 13:06 |
|
dstyl 01 May 2017, 14:08
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? |
|||
01 May 2017, 14:08 |
|
revolution 01 May 2017, 14:26
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. |
|||
01 May 2017, 14:26 |
|
system error 02 May 2017, 03:00
call cpuid
... cpuid: cpuid ret what is this? Is cpuid a function name or an X86 instruction? |
|||
02 May 2017, 03:00 |
|
revolution 02 May 2017, 04:04
system error wrote: Is cpuid a function name or an X86 instruction? |
|||
02 May 2017, 04:04 |
|
system error 02 May 2017, 10:49
revolution wrote: In NASM it can be both. 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 . Imagine how cryptic your source could look like. |
|||
02 May 2017, 10:49 |
|
revolution 02 May 2017, 10:56
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.
|
|||
02 May 2017, 10:56 |
|
Furs 07 May 2017, 15:06
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) |
|||
07 May 2017, 15:06 |
|
system error 07 May 2017, 18:08
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.... |
|||
07 May 2017, 18:08 |
|
rugxulo 08 May 2017, 14:18
system error wrote:
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. |
|||
08 May 2017, 14:18 |
|
rugxulo 08 May 2017, 14:42
system error wrote:
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.) |
|||
08 May 2017, 14:42 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.