View Single Post
  #39  
Old April 26th 14, 11:29 AM posted to comp.sys.intel,comp.sys.ibm.pc.hardware.chips,alt.windows7.general
Stanley Daniel de Liver
external usenet poster
 
Posts: 3
Default How many x86 instructions?

On Sat, 26 Apr 2014 01:58:41 +0100, Yousuf Khan
wrote:

On 25/04/2014 5:54 AM, Stanley Daniel de Liver wrote:
On Fri, 21 Feb 2014 05:55:02 -0000, Yousuf Khan
wrote:
I remember I designed an early version of the CPUID program that ran
under DOS. The whole executable including its *.exe headers was
something like 40 bytes! Got it down to under 20 bytes when I
converted it to *.com (which had no headers)! Most of the space was
used to store strings, like "This processor is a:" followed by
generated strings like 386SX or 486DX, etc.


I doubt the minimalism; a print rtn is 6 bytes, and the text "This
processor is a:" is 20 on it's own!


You could make some really tiny assembler programs on x86. Of course,
compiled programs ignored most of these useful high-level instructions
and stuck with simple instructions to do everything.

Yousuf Khan

Did you cater for all the early cpus?

;This code assembles under nasm as 105 bytes of machine code, and will
;return the following values in ax:
;
;AX CPU
;0 8088 (NMOS)
;1 8086 (NMOS)
;2 8088 (CMOS)
;3 8086 (CMOS)
;4 NEC V20
;5 NEC V30
;6 80188
;7 80186
;8 286
;0Ah 386 and higher


(this wasn't my code, I probably had it from clax some years back)
I don't know if I still have my old program anymore, but I do remember
at that time it could distinguish 386SX from DX and 486SX from DX as
well.

Yousuf Khan


Here's the routine I boiled it down to:
test_cpu:
; mikes shorter test for processor
mov ax,07000h
push ax
popf
sti
pushf
pop ax
and ah,0C0h ; isolate top 2 bits
shr ah,1 ; avoid negative
cmp ah,020h
; anything greater means 8086 - but 80 =-1!
; anything less means bit 4 off, i.e 286
; equal implies 386
ret

of course when the CPUID instruction was introduced it made the later
chips much easier to identify!
--
It's a money /life balance.