View Single Post
  #1 (permalink)  
Old January 2nd, 2010, 12:28 PM
malexgreen malexgreen is offline
Registered User
 
Join Date: Jan 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble getting cpuid example in chapter 4 to work on a Mac

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?