Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 5th, 2006, 10:07 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,676 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 13 h 50 m 24 sec
Reputation Power: 68
Send a message via AIM to Yegg`
Machine coding

I'm not too knowledgable in what this really means. Am I correct in saying that assemblers [usually] convert their code to machine [readable] code? If this is so, then there must be some way to code in this machine code alone without the help of an assembler? Is the machine code basically or by and large merely binary?

I am working on writing my own language, which I also want to be able to be compiled to an executable file on a certain OS. I'd rather have my compiler convert my code directly to machine code as opposed to ASM and then to machine code from an assembler. Wouldn't this increase compilation time? Not that it would be by much in many cases, but I'd like to try.

Anyways, would anyone hapen to be able to fill in the blank spots and perhaps direct me to places where I can learn how to write machine code on the x86? I'm guessing OS matters? I'm on Windows at the moment, but I'd also like this to work on Linux for me as well.

Any help is appreciated.

Reply With Quote
  #2  
Old June 6th, 2006, 01:26 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 23 m 58 sec
Reputation Power: 1008
It's not worth the effort. The reason compilers support output to ASM first is that you can then manually tweak the ASM, whereas few people can tweak machine code. There's a lot to be said for modularity.

GAS also does a bit of optimisation that would be missing from your compiler, with the LIKELY() pragmas, etc.

Reply With Quote
  #3  
Old June 6th, 2006, 06:00 AM
xlordt's Avatar
xlordt xlordt is offline
Only the strong survives!!.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Feb 2003
Location: A World of wonder.
Posts: 5,543 xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)xlordt User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1Folding Points: 108894 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 22 h 41 m 58 sec
Reputation Power: 378
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt Send a message via Google Talk to xlordt Send a message via Skype to xlordt
Facebook
I also think it would be a waste of time... although... if compilar convert everything to machine code.. note that machine code is hardly human readable... so i think you should just let the compilar's do what it was made for.

Reply With Quote
  #4  
Old June 8th, 2006, 01:20 PM
Randux Randux is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 48 Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 18 h 47 m 23 sec
Reputation Power: 6
Quote:
Originally Posted by Yegg`
I'm not too knowledgable in what this really means. Am I correct in saying that assemblers [usually] convert their code to machine [readable] code? If this is so, then there must be some way to code in this machine code alone without the help of an assembler? Is the machine code basically or by and large merely binary?


Assemblers generate object code, which you could say is binary. It can be represented in various numbering systems, but the ones I'm familiar with are usually expressed in hexadecimal notation just because that format makes sense on the machine in question and all the utilities use the same format.

A number is a number is a number.

Yes, there is most definitely a way to write object code without an assembler, and I've had several jobs where I got paid to do it. It's very interesting work and has its place. Sometimes it's not practical to use an assembler, and so we write in object code. It's also extraordinarily useful to be able to read object code. When you can do that, you can understand much from storage dumps without having to resort to program listings or dissasemblers.

Quote:
Originally Posted by Yegg`
I am working on writing my own language, which I also want to be able to be compiled to an executable file on a certain OS. I'd rather have my compiler convert my code directly to machine code as opposed to ASM and then to machine code from an assembler. Wouldn't this increase compilation time? Not that it would be by much in many cases, but I'd like to try.


Most assemblers operate in several passes including macro (preprocessing) and two passes over the source to resolve symbols backwards and forwards, before generating object code. Except in R&D and academic environments (damn you, Niklaus Wirthless!) code is executed more than it's compiled. So people normally make a design decision to spend time during compilation and assembly to generate the best possible executable. After that it still has to be linked or bound to generate the executable, and even during runtime, depending on how the software is packaged, it may invoke yet other executables which have to be loaded. There's really quite a lot involved in getting something from source code, into memory, and giving it control.

Quote:
Originally Posted by Yegg`
Anyways, would anyone hapen to be able to fill in the blank spots and perhaps direct me to places where I can learn how to write machine code on the x86? I'm guessing OS matters? I'm on Windows at the moment, but I'd also like this to work on Linux for me as well.
Any help is appreciated.


The best place to learn about your machine is from the processor manuals. Fortunately, Intel publishes extensive free documentation on x86 which I found in one of the links in one of the posts on the languages forum here about assembly language. The processor manuals explain the architecture of the machine and document all of the formats of instructions including their opcodes, operands, and other things like numbering systems notation. Anyone who needs to be expert in assembly language should also consult whatever processor manuals he has as third party assembly language texts cannot cover this sort of material in the level of detail required to understand enough to do a proper job of coding.

In answer to your question about operating system dependencies, yes, this matters quite a lot even on the same hardware. Fundamental operations such as moving data around, doing arithmetic, and local flow control are architectural; they don't vary from OS to OS on the same hardware, because they're not operating systems services- they're hardware instructions/features. But services such as obtaining and freeing memory, doing high-level (device-dependent) I/O, etc. are operating system services and are provided through interfaces. So you'll have to use the APIs provided by whatever platform (OS) you want your code to run on. And if you want the same mainline to run on multiple OS, you can use the macro or preprocessor language of your assembler (if it provides one) to tailor the executable for each environment. If you don't have that support, you can write it. And if you want, you can do the support in object code, except that it's less efficient as it will involve branching to/around environmental code instead of generating a purpose-built program for the OS...

This issue comes up more often than one might think. If you have a current assembler, it can generate opcodes that aren't supported on older hardware or older versions of the OS. What we do is to make tests at execution time for various hardware and operating features and contour the execution path based on whether or not they're available.

I made some comments that may be relevant to your question in this thread:

http://forums.devshed.com/other-programming-languages-139/is-there-a-good-website-about-assembly-328013-2.html?pp=15

Edit: Sorry, I remembered incorrectly about the link to the processor manuals. The GCC page has a nice list here: http://gcc.gnu.org/readings.html

p.s. Thanks Simon
Comments on this post
SimonGreenhill agrees!

Last edited by Randux : June 11th, 2006 at 12:21 PM. Reason: Incorrect pointer to processor manuals

Reply With Quote
  #5  
Old June 9th, 2006, 01:59 AM
Randux Randux is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 48 Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level)Randux User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 18 h 47 m 23 sec
Reputation Power: 6
Talking

Quote:
Originally Posted by LinuxPenguin
It's not worth the effort. The reason compilers support output to ASM first is that you can then manually tweak the ASM, whereas few people can tweak machine code. There's a lot to be said for modularity.


The reason that compilers produce assembly language is to save the compiler writers from having to do extra work!

Reply With Quote
  #6  
Old July 17th, 2006, 09:00 PM
FieroGT42 FieroGT42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 4 FieroGT42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by Yegg`
I'm not too knowledgable in what this really means. Am I correct in saying that assemblers [usually] convert their code to machine [readable] code? If this is so, then there must be some way to code in this machine code alone without the help of an assembler? Is the machine code basically or by and large merely binary?


Yes and no. There are different types of assembly language (ASM for short). I've worked with a few modern types as well as other versions like BAL on an HP-UX mainframe in college. Edit: My mistake, that was on the emulated IBM MVS. Duh :P

Some types of higher-level ASM produce a pretty generic, intermediate bytecode which you use a platform-specific assembler to convert into machine-specific machine code.

The really fun types of assembly are the ones where you are basically writing hardcore machine code yourself. In one of my classes, we used a type of ASM like this. We'd code using mnemonic codes like MOV, ADD, MUL, but then we'd look up the machine code for that operation (usually expressed in hexadecimal, but we'd also have to conver to binary occasionally) and write the instructions as machine code. We'd also manually pack and unpack decimal fields with paper and pencil, convert between ASCII/EBCDIC, etc. When we were done, we could literally write programs in machine code. Well, those of us who could make it through... It was the most dreaded class of the program.

Fun stuff! But If you're already going through the pains of making your own language, I suggest you just get it to use a higher level ASM first. Then if it's not efficient enough, go hardcore, straight to optimized machine code.

Reply With Quote
  #7  
Old July 28th, 2006, 01:25 AM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,082 Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Schol-R-LEA User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 10 h 16 m 50 sec
Reputation Power: 446
A thread about machine code and no one has mentioned Mel Kaye yet? For shame.
__________________
Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
#define KINSEY (rand() % 7) λ Scheme is the Red Pill
Scheme in ShortUnderstanding the C/C++ Preprocessor
Taming PythonA Highly Opinionated Review of Programming Languages for the Novice, v1.1

FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

Reply With Quote
  #8  
Old July 28th, 2006, 08:02 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Contributing User
Click here for more information
 
Join Date: Jul 2006
Location: Sector ZZ9 Plural Z Alpha
Posts: 31 Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)Itsacon User rank is Sergeant Major (2000 - 5000 Reputation Level)  Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2Folding Points: 682581 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 h 44 m 20 sec
Reputation Power: 51
Send a message via ICQ to Itsacon
All hail Mel!

I've done some bytecode programming for the 8051 processor in my time. Very educational, but not practical.

Great way to get optimized code, but VERY high-maintainance. For example: Most jumps in assembler are relative. So adding a single line of code means you have to check ALL your branches for correctness. In ASM, you use labels to avoid this. The assembler fill in the correct jumps at the last moment, saving you the bother :-)

Reply With Quote
  #9  
Old July 28th, 2006, 04:17 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,440 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 50 m 56 sec
Reputation Power: 797
Used to have this crazy prof in my undergrad microprocessor programming class that had pretty much the entire 8085 instruction set's op codes memorized.

In this class, you would:
1. First, write your program out in assembler.
2. Hand assemble it using a sheet that contained the ASM instructions and their opcodes. Note that some instructions took 1 byte, some two and some 3 bytes, so you had to figure out the addresses of the instructions as well at this stage.
3. Resolve all the JMP labels (in step 2, you figure out the addresses of the instructions as well, so you just need to replace the JMP labels with the actual addresses).
4. Enter the program into the 8085 kit and then run it, using a hex keypad and toggle switches

The prof could do steps 1-3 on the board without using a sheet since he knew the opcodes as well as how many bytes each took. The man could also pretty much resolve all the JMP labels in his head, so he would write the machine code out directly. Heck, I think he was only using the board so that the class could compare their answers with his to see if they got it correct -- IIRC he once keyed in a program directly and got it to work first time.

One more impressive feat from this man was that he would walk into class and take roll call. Then, at the end of the 1-hour long class, he would write down the #s of people who were absent on the board. Mind you, my class had 74 kids and at any given time, at least 30% would be playing hooky!
Comments on this post
Schol-R-LEA agrees: That's an impressive memory. As for hand-assebling, it's a very insightful exercise to go through -
once.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Machine coding


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump