article

BUILDING AN ASSEMBLER step by step (1

Email
Submitted on: 1/3/2015 5:13:00 PM
By: vivek mohan (from psc cd)  
Level: Advanced
User Rating: By 4 Users
Compatibility: C
Views: 4126
 
     Hi ya all ! This is my first attempt to create an assembler called Universal ASM. And I decided to do it step by step sharing with you all. Please appreciate this effort by voting for me and sending your feedback on this project....

This article has accompanying files
 
				
 ___________________________________________________________
 |
 |		 BUILDING AN ASSEMBLER 
 |		 Step By Step
 |		 (Session 1)
 | 		By Vivek Mohan
 | 
 |Visit me at http://www.geocities.com/cppresources/
 | or shoot me an email at opendev@phreaker.net
 |
 | To join the mailing list for BUILDING AN ASSEMBLER 
 | step by step, mail to opendev@phreaker.net with the
 | subject field = join UASM mail with a little info about
 | yourself.
 |___________________________________________________________
 {{{{ INTRODUCTION }}}}
 Hi there ! Firstly thanx for taking a look at this. Frankly speaking I'm no ASM 
 Guru, but this is my first attempt towards creating an Assembler. I know very well
 that there are many people who are really interested in things like this, so I 
 decided to develop step by step, uploading each step and waiting for your feedback
 on suggestions, bugs and stuff like that. And I hope you appreciate the whole 
 effort by sending me you feedback on this project. You are always welcome 
 to contribute to this project.
 {{{{ THE ASSEMBLER }}}}
 I've named the assembler UNIVERSAL ASSEMBLER or UASM. The first version of UASM
 will assemble for the 8086 intel architecture. UASM will be an integral part of
 OPOS the open source operating system under development.
 {{{{ STEP 1 }}}}
 By the end of this session..
 1. UASM will assemble two simple types of MOV instructions
	
	mov offset, accumulator regs
	mov regs , Imm8/16
 
 2. UASM will assemble the two interrupt instructions
	int Imm8
	int3
 3. UASM will assemble the return instructions
	ret
 By the end of this session, using UASM we'll be able to use UASM to build a COM 
 program which can print a message.
 {{ 1.1 }}
 As the first step I wrote a few file IO routines for parsing the 
 source code. These routines can be found in the file fileio.c
 {{ 1.2 }}
 As the second step I wrote a few routines to convert between number systems
 as they are going to be very important. They can be found in the file math.c
 {{ 1.3 }}
 Then came a very important part of the assembler - The x86 instruction processing
 unit. This is where all the processing takes place. It can be found in the file 
 x86.c. Functions like mmm(..) , rrr(...) return the bit values for corresponding
 functions and regs. The array x86[] holds the various x86 instructions, so far only
 the implemented ones. The function mov constructs the mov instruction when the right
 args are passed. Intr and Ret also do the same for int and ret instructions. Most of
 the functions have been well connected so you won't have trouble understanding.
 {{ 1.4 }}
 UASM.C is the main file. The getinstruction function is like the driver code for the
 whole thing. It reads the instruction and the corresponding operands. It then calls
 the right function with the right args passed. Thats enough of coding for the first 
 session.... 
 {{ 1.5 }}
 Compiling... (using DJGPP)
	gcc -o uasm.exe uasm.c
 {{ 1.6 }}
 Assembling the example1.asm file
	
	uasm.exe example1.asm example1.com
 run the file and you'll see the message 'Hi';
 {{{{ Conclusion }}}}
 Looks like I've made a small working version of uasm. I hope there are no major
 errors or bugs but if you do find any please mail me.
 {{{{ Next Session }}}}
 In the next session the objectives will be to
 1. include support for comments
 2. support for all single byte instructions
 3. support for a few more mov instructions
 Thats all for now,....
 Vivek Mohan

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 6 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.