News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Out of curiosity...about cpu instruction set

Started by sydetys, October 01, 2008, 07:02:24 AM

Previous topic - Next topic

sydetys

I have one manual which is from year 2003, in there they use instruction set .386, and mentions .586,
How about nowadays? example what should I put in there at the beginning of code if I want to use specifically my CPU´s instruction set? I have Intel Core 2 Duo E6750.


donkey

You can check the cpu type by family, model and stepping or the availability of specific instruction sets using the CPUID instruction. Here's a snippet from WinExplorer that returns the processor family, model and stepping information as well as the preocessor string...

GetProcessorStrings FRAME pszProcString,pszBrand,pszFamily,pszStepping,pszModel
uses edi,esi,ebx
LOCAL model :D
LOCAL family :D
LOCAL stepping :D
LOCAL prcstring[64] :B

// Test for CPUID
pushfd ; save EFLAGS
pop eax ; store EFLAGS in EAX
mov ebx, eax ; save in EBX for later testing
xor eax, 00200000h ; toggle bit 21
push eax ; push to stack
popfd ; save changed EAX to EFLAGS
pushfd ; push EFLAGS to TOS
pop eax ; store EFLAGS in EAX
cmp eax, ebx ; see if bit 21 has changed
jz >>.NO_CPUID ; if no change, no CPUID

xor eax,eax
cpuid
mov edi,[pszProcString]
mov [edi],ebx
mov [edi+4],edx
mov [edi+8],ecx
mov D[edi+12],0

xor eax,eax
inc eax
cpuid

mov D[model], 0
mov D[family], 0
mov D[stepping], 0

mov [family], ah
and B[family], 0Fh
// check for extended family
cmp B[family],0fh
jne >
mov ecx,eax
shr ecx,20
and ecx,0FFh
add [family],ecx
:

mov [model],al
and B[model],0F0h
shr B[model],4
// check for extended model
cmp B[model],0fh
jne >
mov ecx,eax
shr ecx,16
and ecx,0Fh
add [model],ecx
:

mov [stepping],al
and B[stepping],0Fh

invoke dw2ascii,[family],[pszFamily]
invoke dw2ascii,[stepping],[pszStepping]
invoke dw2ascii,[model],[pszModel]
and ebx,0Fh
invoke dw2ascii,ebx,[pszBrand]
test ebx,ebx
jnz >>
invoke szCopy,[pszBrand],"Branding not supported"
:
test ebx,ebx
jz >
// In processors where branding is available
// use the extended processor string
mov eax,80000002h
cpuid
lea edi,prcstring
mov [edi],eax
mov [edi+4],ebx
mov [edi+8],ecx
mov [edi+12],edx

mov eax,80000003h
cpuid
mov [edi],eax
mov [edi+4],ebx
mov [edi+8],ecx
mov [edi+12],edx

mov eax,80000004h
cpuid
mov [edi],eax
mov [edi+4],ebx
mov [edi+8],ecx
mov [edi+12],edx

// Strip leading spaces
mov al," "
mov ecx,32
repe scasb
dec edi
invoke szCopy,[pszProcString],edi
:

xor eax,eax ; return success (0)
RET

.NO_CPUID
mov edi,[pszBrand]
mov D[edi],0
mov edi,[pszFamily]
mov D[edi],0
mov edi,[pszStepping]
mov D[edi],0
mov edi,[pszModel]
mov D[edi],0

invoke szCopy,[pszProcString],"CPUID not supported"
xor eax,eax
dec eax ; return error (-1)
RET

ENDF
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

sydetys

So instead of using ready codes .586 or .686 at beginngin of asm file, I can use more specific codes instead?
I knew it...

I lack in CPU knowledge, how stepping and such is helping?

hutch--

Your notation is standard MASM. If you want to use the later instructions, try this.


.686p
.MMX
.XMM


Use a later version of ML.EXE for the more recent SSE instructions, 6.15 upwards for SSE2. If you don't mind the massive download, VC2008 has ML.EXE version 9.0 which does the later stuff again.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

Sorry sydetys,

I misunderstood your question, I thought you were looking for a way to programatically check which CPU your already assembled program was running on, you should read Hutch's post, it has the answer to your question.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

sydetys

Good, no worries donkey.

Hutch: you mean by VC2008, visual c++, or Studio?, I have Visual studio 2008 but it´s huge  and integrates itself inside my OS real tightly, I will start to use it later..maybe.
Free download of c++ 2008 is waiting for a chance to install itself..maybe now is the time..

BTW: I made very basic program (hello world...yeeah NOOB), I disassembled it with free version of IDA Pro and result was VERY different from original code, why?
is result very RAW assembler, without any macros and such? THAT kind of assembler I should learn, but I can´t find anything but masm or linux GCC assembler guides..links? thanks.

And I fear the book I  ordered from bookshop will be for linux.....I hope not..




BlackVortex

Search for ml.exe in your visual basic installation, if you wanna find the newer version. But you don't need it, I doubt you'll be using SSE,MMX etc any time soon.

Also, raw assembly of course doesn't have labels,macros,proc names, and other programming structs. You should learn to program in masm, but at the same time understand the code it outputs ... its disassembly.

P.S.: Actually, you can program in masm in what you call "raw mode", but you'll be missing the whole point of programming itself.
Remember, understand low-level code, but don't try to write it   :green2

donkey

Hi sydetys,

I use GoAsm which is much closer to raw assembly than MASM however even with that assembler there is not a 1 to 1 assembler to ML relationship, a MOV instruction can be changed to LEA, stack frames have to be built, and quite a few other minor changes to your code have to be made in order to satisfy addressing and other requirements of the processor. Not being much of a macro user I rarely have issues with that but even INVOKE can create some unexpected code. Remember that the disassembly is Machine Language translated to Assembly Language and there are always nuances lost in the translation, Machine Language and Assembly Language are not equivalent even though the correlation is close.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

herge

 Hi Hutch:

The [MASMsetup.exe]ML.EXE does not work with VC2008
 it does work with  the previous version VC2005.
 It won't even install with VC2008.
 It is very hard to find, you have to look for
 VC2008 and then download the Previous version that's
 why I have VC2005 and VC2008. It don't Google easy.
 Plus a 50 MB SP1 if you look for updates for it.  (VC2005).
 It takes a day or two to download
 if you have dial up modem.
 So if you want ML.EXE  to work get VC2005!

 Regards herge


// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

GregL

herge,

Visual C++ 2008 Express Edition SP1 includes ml.exe 9.0. On my system it's in C:\Program Files\Microsoft Visual Studio 9.0\VC\bin.