Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > Assembly Language
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Assembly Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 2nd, 2010, 12:28 PM
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?
  #2 (permalink)  
Old January 10th, 2010, 07:05 AM
Authorized User
 
Join Date: Jan 2010
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by malexgreen View Post
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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 7 image upload on Mac OS X laolaonk BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 February 19th, 2006 10:20 PM
Trouble with Chapter 3 mickmo2000 BOOK: Professional Crystal Reports for VS.NET 0 February 13th, 2004 05:16 PM
Chapter 1 ASP.NET Trouble Shooting rragoonanan BOOK: Beginning ASP.NET 1.0 14 December 3rd, 2003 09:53 AM
Trouble with Chapter 8 Example 6 EdgesofTwilight BOOK: Beginning Visual C++ 6 0 October 25th, 2003 04:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.