Quote:
Originally Posted by malexgreen
I am using MacOSX version 10.6.2. Here is the code
#mycpuid.s : Sample program to extract the processor Vendor ID on a x86 processor
#place code at address defined as the .data section
.data
output:
.ascii "The processor Vendor ID is 'NNNNNNNNNNNN'\n"
#place code at address defined as the .text section
.text
.globl start
start:
#setup CPUID instruct to return the vedor ID string into the ebx, edx, and ecx
#registers
movl $0, %eax
cpuid
#make edi a pointer to the locatino of output
movl $output, %edi
#move the vendor id string from the registers to the mem location
#pointed to by edi+28, edi+32, etc...
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)
#setup Linux (and hopefully MacOSX) system call to print this to STDOUT
#sys call value
movl $4, %eax
#first descriptor to write to
movl $1, %ebx
#pointer to the string
movl $output, %ecx
#length of the string
movl $42, %edx
#perform interrupt 0x80
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80
I get the following error message when I attempt to run it:
[contentment-3:~/Documents/assembly_language_area/my_code] magreen% ./mycpuid
Illegal instruction
I've tried it on a Windows box using cygwin on Windows XP (running as a guest on top of VMWare Fusion), with a similar result. Does the system call that is used in the program work for MacOSX?
|
I'm reading the same book! I've just programmed this section of the code under Fedora 12 Linux and it works perfectly. I get 'GenuineIntel' as a result.
Btw, I doubt this code is cross-compatible with Windows XP or a Mac because it is using INT $0x80 interrupt. That is the niche right there.
The Int 0x80 interrupt is for LINUX ONLY. I have even tried compiling it on OpenBSD (A Unix varient) and it just exits without any output.
Try installing Linux and running the code. I KNOW! It's such a shame the book is Linux specific. BUT - YOU MUST INSTALL LINUX TO GET IT TO WORK because its assembler language and not C - with C you can run it on any machine that has a GCC compiler - but NOT assembler. That is hardware specific, and o/s specific.