assembler design and coding

Thread Starter

abhi.creations

Joined Sep 10, 2007
9
hi all,
can any person help and support me in designing/ developing an assembler for a microcontroller.
i have to do coding in c language and finally have to come up with an assembler.
i am new in this stuff.
please support me by giving its study material/ebook and by giving every important concept for designing assembler. and also by giving contact of any specialized person.
i shall be very thankfull to you.

note: this topic is also under discussion in the topic "number of insructions in microcontroller"
 
You asked me the same thing in a private message. Here is my answer...

Unfortunately, I don't know / don't remember such a tutorial. On the other hand, you could take a look on the open-source assemblers' source code, like GAS (GNU Assembler) and NASM. GAS is part of the binutils package for GNU/Linux. Most probably, they're both written in plain C.
 

Thread Starter

abhi.creations

Joined Sep 10, 2007
9
those are nice materials.
well till now i have gone thruogh the "second chapter: assembler" of book "system software: an introduction to system programming byLeland L. Bech "
and also i have looked at the above links.

this has given me some ideas about the basic funtions of assembler and assembler design.
now getting problems:
1. how to implement symbol table and optable in c coding.
2. how to search symbol table.
3. how assembler convert source program to object code. and how to implement this.
4. how to implement/process assembler directives( or pseudo instruction)
5. how to generate listing file using c coding.
6. what are the things take care about the addresssing mode, memory - registered instruction. and how to implement it in c coding.
7. how our c program (assembler) read input source file.

please support me , very soon i have to learn and implement it. its very urgent for me.
 

beenthere

Joined Apr 20, 2004
15,819
Your list of assembly directives is usually produced as a text file. You can use Wordpad, or some really good text editor like UltraEdit for the function.

To input it and begin the process is know as "parsing" the text input. This is a link to a helpful site - http://www.dreamincode.net/code/snippet488.htm.

As you may be discovering by now, writing an assembler is not a weekend project. Having an understanding in depth of how machine language instructions actually work is going to be vital. You will have to set up a structure for the assembler directives so you can make the parsing routine work. You really can't just fly into this - some level of understanding has to be reached before you can perform the task.
 

Thread Starter

abhi.creations

Joined Sep 10, 2007
9
can you provide me complete c source code(assembler) for a simple PIC (or 8051) microcontroller assembler for reference. and also give me the procedure of using it. so that i can come up with my own assembler.
 

Papabravo

Joined Feb 24, 2006
21,159
can you provide me complete c source code(assembler) for a simple PIC (or 8051) microcontroller assembler for reference. and also give me the procedure of using it. so that i can come up with my own assembler.
What is the matter with you? I gave you the link to the C source for an 8051/6805/Z8 assembler with instructions on how to use it. Are you not paying attention to our posts or are just in too big of a hurry?
 

Thread Starter

abhi.creations

Joined Sep 10, 2007
9
hi, i have gone through 8051 but it is too big at starting level. some boddy was suggested me to go through 8051. but now i realize that PIC10F or PIC12 microcontroller will be better. because it is having only 31 instructions as compared to 111 instructions of 8051. but whatever previous source codes has given me all basic idea of implementation.
so please send me the assembler source codes for PIC MCU.
 

Papabravo

Joined Feb 24, 2006
21,159
I guess you still believe, despite all of our exhortations to the contrary, that the complexity of an assembler is a function of the number of instructions. I guess you are just not reachable on issues that you have made up your mind about. You should go far in this field since you already know all the answers. Good luck on finding the source code that you seek.

One more time. There are three different assemblers in the package. Would it not be possible to adapt the code to the PIC instruction set? Could you at least understand the construction of the tables and data structures? I thought that was what you were looking for. Was I mistaken?
 

HarveyH42

Joined Jul 22, 2007
426
I guess this thread is difficult for me to understand. If you don't know anything about the microcontroller, how can you write an assembler for it? If you don't program in assembly, how will you know what features are needed or useful to include?

I taught myself assembly on a Commodore 64 (6502), with no assembler, or any other software (none availiable at the time). I had to convert everything into numbers, and use a BASIC program to poke the numbers into the appropriate memory adress. As my programs got longer and more complex, need a simpler way of entering programs. Also, debugging was a pain, one typo could crash the program and computer. So in BASIC, I wrote a disassembler first, so I could look at other people's code (still do that :) ) and to find my own bugs. Adding an assembler was a snap, since it re-used the same routines in the disassembler. About then, I was able to buy an assembler programming package...

I guess I don't understand the problem because I started at the lowest level first, and understood the numbers the CPU worked with, then moved it up to a higher level language so I didn't have to waste time looking up numbers or do number conversions.

Anyway, each instruction is a number (opcode), you can call it anything you like in your program, but the CPU will only understand the number.

Some instruction are followed by an oprand, 1 or 2 bytes, which can be a value, offset, or address.

I use AVR MCUs, which have 32 working registers, the 6502 had 3. Not sure how that works out, but doesn't matter. Atmel provides free programming software...
 
Top