Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > Assembly Language
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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?
Reply With Quote
  #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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05:05 PM



All times are GMT -4. The time now is 05:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.