Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Assembly Code, G3s, G4s, G5s, and Simulators?

Assembly Code, G3s, G4s, G5s, and Simulators?
Thread Tools
SSebeny
Junior Member
Join Date: Aug 1999
Location: Cuyahoga Falls, Ohio, USA
Status: Offline
Reply With Quote
Jul 21, 2003, 05:22 AM
 
Hello all,

This message is going to ramble while I give some background info, but eventualy I get to some questions which I would really like to hear your thoughts on...

I am a college student, majoring in computer science. My programming background is pretty light. I was introduced to Basic ages ago, then Visual Basic and Pascal in High School, but never did much with them. Then in college I took an ANSI C course and finally started to get a little serious about coding. Since then I've been working in a variant of C++ for 2 years.

At any rate I'm at a point where I'd say I'm finally making programs that when I stand back I can start to be proud and say that I really accomplished something. In the course I am currently enrolled in I am first creating a simulator for an imaginary processor. Its input is an object file (in the form of text records, not binary). Basically we have to write a program to load the contents of the file into a memory representation, and then have to step though the memory and execute each instruction until a halt. Sounds pretty simple, but that took about 175 pages of source code. And then the next step we will be writing an Assembler, and then a Linker, so it should be lots of fun.

Just a little more background before I get to the point and ask my question. A couple years ago I also took an assembly language programming course which focused on the Motorola 68HC11 embedded microcontroller. And now I am starting to learn Cocoa, and I made the trip out to WWDC a few weeks ago as I got a free student scholarship from Apple. While I was there I overheard someone talking about intermixing assembly code with high level code when writing something on the Mac. Which leads to my question...

Essentialy, from what I have heard the Motorola 68HC11 seems to be a semi-popular chip that gets studied in EE and CS courses. And when I took such a course we used a simulator, which was only available for Windows. And since I am learning Cocoa, and was looking for a project to work on, as well currently being enrolled in a course where I am writing an assembler and processor simulator, I thought that I might undertake the project of trying to write a M68HC11 simulator in Cocoa.

However, it then occured to me that it might be drastically easier to accomplish such a project if I could layer the simulated instructions on top of assembly instructions which exist on the native machine. So for example instead of using lots of high level code to simulate the M68HC11's add instruction, simply have a procedure which uses a native add instruction to accomplish the basic work of the instruction and then have some code to do conversions needed to translate to the format needed to use local instructions. Although there might not be a 1-to-1 instruction parody, I would think that a highpower chip like a G4 could accomplish anything some embedded controller could.

So, here are the questions finally...

1) Am I correct in understanding that you an intermix high level code with assembly code? Anything special I need to know about doing this? Anything I can read to give me any tips?

2) I don't currently know ANYTHING about the assembly instructions that exist on the G3/G4/G5. Where can I go to learn about them? And how much do assembly instructions change from say the G3 to the G4, or from various versions of the G4 like the 7400 to the 7455?

3) Would the M68HC11 be a good choice of an embedded controller to write such an assembler and simulator for? Or is there one that is more popular now, which would be a better choice? My initial thought was just doing this for the fun of it, and so that some students who are Mac users might not have to use Windows for such a class if they take it in the future, but would there be actual commercial use for something like this as well?

4) Does anyone forsee any problems doing something like this in Cocoa? I'm mostly only written C++ before, and only for command line programs, and none on the Mac. I've played around with Cocoa, but haven't done anything much with it yet. Any reason that I should stear clear of Cocoa for a project like this and just make it a command line app instead?

5) Would trying to layer the simulated assembly instructions on top of native assembly instructions be a good idea, or a stupid idea? I don't know, its just something that occured to me when I heard you can intermix high level and low level code.

6) If it would be an OK idea to layer simulated assembly instructions on top of native assembly instructions, then how would I account for differences in hardware? For example, is there someway to determine in software what CPU it is running on (G3/G4/G5) and then use that fact to selectively use different procedures in the code?

7) Anyone else have any other thoughts to share? Am I crazy all around for considering such a project? Is it a descent project? Would it be rediculously too much work to try and use assembly, or would that make it easier? Any suggestions for other routes to take? Or other features, etc. Are there any other assemblers and simulators for similar things available on the Mac that I should check out first?

I really look forward to any and all comments others here might have to share. Thanks in advance for any and all feedback!
-----
Stephen M. Sebeny
[email protected]
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 21, 2003, 10:21 AM
 
Originally posted by SSebeny:
1) Am I correct in understanding that you an intermix high level code with assembly code? Anything special I need to know about doing this? Anything I can read to give me any tips?
yes. It's not difficult if you know C and assembly.

Article explaining it


2) I don't currently know ANYTHING about the assembly instructions that exist on the G3/G4/G5. Where can I go to learn about them? And how much do assembly instructions change from say the G3 to the G4, or from various versions of the G4 like the 7400 to the 7455?
Google is your friend. Search for "PowerPC assembly" and you'll find lots of links to IBM's site with details.


3) Would the M68HC11 be a good choice of an embedded controller to write such an assembler and simulator for? Or is there one that is more popular now, which would be a better choice? My initial thought was just doing this for the fun of it, and so that some students who are Mac users might not have to use Windows for such a class if they take it in the future, but would there be actual commercial use for something like this as well?
I never used the M68HC11. When I was in school, everyone used the MIPS processor for assembly tutorials (partly because SPIM exists for every computer on earth). MIPS is a RISC processor, so it's a good choice for assembly work. I guess that's pretty ancient now though.

5) Would trying to layer the simulated assembly instructions on top of native assembly instructions be a good idea, or a stupid idea? I don't know, its just something that occured to me when I heard you can intermix high level and low level code.

6) If it would be an OK idea to layer simulated assembly instructions on top of native assembly instructions, then how would I account for differences in hardware? For example, is there someway to determine in software what CPU it is running on (G3/G4/G5) and then use that fact to selectively use different procedures in the code?
My senior design project (computer engineering) was to design a processor, then write a compiler, synthesize the processor in silicon, and run some programs, getting them to run as fast as possible.

We build a 5-stage super-scalaer RISC processor that ran at about 1.1 MHz.

We used YACC (yet another C compiler) to compile our C into assembly, and then I wrote a custom C program to convert the assembly into register-loadable bytecode. You just define your YACC asembly instructions and go to town. If you go with a real processor, then that work has probably already been done for you.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
   
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:19 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,