Previous in Forum: How do logic gates function?   Next in Forum: Simple Investigations for High School Students
Close
Close
Close
6 comments
Rate Comments: Nested
Participant

Join Date: Oct 2007
Posts: 4

Microcontroller Programming: How does the Controller Find the Machine Code?

10/18/2007 1:33 AM

I am doing a project on "design of a RISC micro controller" using VHDL.

I want to know how the instruction is fetching and then executing. Where we are wring a program (ROM/RAM). Initially we have to load all the instruction set in the ROM which is non volatile. After loading the address of the program in the program counter how does the controller find the machine code of that particular instruction from ROM?

Register to Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Guru
Engineering Fields - Control Engineering - New Member China - Member - New Member

Join Date: Sep 2006
Location: CHINA
Posts: 2945
Good Answers: 14
#1

Re: Microcontroller Programming: How does the Controller Find the Machine Code?

10/18/2007 10:07 PM

Im curious, if you dont know how the microchip or cpu works, how shall you design a controller, especially risc type?

its a huge topic, long cut to short,

a microchip is constructed by a cpu, i/o, timer and basic rom. timer is very important, it controls all command running in order.

in one work periodic, cpu put out address code, search positon the machine code exist, next periodic, it fectch it into its register or ram to store for next use. the process of seraching can be either ram or rom, either inner or extra depend on your design. then timer allow algorithm operate to determind which way will go next. then timer give anothe time periodic to let cpu determine next step and then repeat. ...

thats all.

Register to Reply
Guru
Philippines - Member - New Member Engineering Fields - Instrumentation Engineering - New Member Engineering Fields - Control Engineering - Who am I?

Join Date: Oct 2006
Location: Northern Mindanao, Philippines
Posts: 2147
Good Answers: 53
#2

Re: Microcontroller Programming: How does the Controller Find the Machine Code?

10/18/2007 11:01 PM

Like cnpower, I don't understand how you can work on a project like this without some knowledge about microprocessors.

Most microprocessors I know always execute the first instructions at address 0 (or the first address). Once it finishes executing that instruction, it goes on to the next instruction in address 1.

Some instructions are contained in more than one address. For example, address 5 has an instruction to add the contents of the accumulator to a certain number which is contained in address 6. In this case, once the instruction has finished executing, the next instruction to be done will be in address 7, not 6.

This is just part of the workings of a microprocessor but it answers your particular question...hopefully.

__________________
Miscommunication: when what people heard you say differs from what you said. Make yourself understood.
Register to Reply
Guru

Join Date: Dec 2005
Location: Etats Unis
Posts: 1871
Good Answers: 45
#3

Re: Microcontroller Programming: How does the Controller Find the Machine Code?

10/19/2007 1:03 AM

When you fetch the instruction you must apply the instruction to the address of the micro-code sequence in the ROM that will control how the instruction is executed. In a RISC machine, though you will prefer to execute an instruction in one machine cycle the machine cycle is usually comprised of a muti-phase clock. The various phases and edges of said clock trigger instruction latching and decoding early in the machine cycle with the execution of the necessary actions resulting from the decoded instruction data in the later portion of the machine cycle. Certain common tasks such as operand addressing and movement will occur mid-cycle in preparation for the operation and rendering of the result to some location, if required. So the microcode for one instruction may comprise several control sequences that determine data movement and what operations are taken on that data. Typically, a RISC machine will also have a few instructions that incur an additional machine cycle in which case the microcode for that instruction will be longer and there would need to be a provision to allow for that exception in the handling of the decoding and sequencing of instruction micro-code.

__________________
The hardest thing to overcome, is not knowing that you don't know.
Register to Reply
Anonymous Poster
#4

ntroller Find the Machine Code?

10/19/2007 1:07 AM

.

Register to Reply Score 1 for Off Topic
Anonymous Poster
#5

Re: Microcontroller Programming: How does the Controller Find the Machine Code?

10/19/2007 11:32 AM

The program counter actually holds the address of the instruction following the one being executed presently. The assembly code of the program, which is translated into machine language by the assembler, has a certain syntax, generally something like this: type of operation to be executed-address of operands (if applicable)-constant operands(if applicable)-memory address for writing result(if applicable). Each processor(ie. controller) has it's own set of intructions because the internal circuitry is unique. For example, a Motorola HC86** instruction looks like ADDA +operand address and memory address folowing. ADDA means add the number stored at the memory address given to contens of register A and put the result into memory at the address given. This particular 8 bit processor has close to 300 instructions if I rememebr correctly, more then 2^8. This is done through special instruction formats that tell the processor that a 16bit instruction follows. Again, I stress the fact that EACH PROCESSOR IS UNIQUE in this aspect. This is how the processor works. How can you acces that? Depends on the level of programming you are using. If you're writing the program in high-level like C++, you need not worry about all this...the compiler does all the dirty work for you. The advantage is shorter, easier to understand code. If you wish to program the processor directly, you must use low level assembly language. To do this, get the "data sheet" of the controller from the manufacturer; this should contain all instructions available on that particular model. After you are familiar with how to use them, you have to figure out how to write a program that suits your needs ie. I am getting these two inputs, where do I store them, how do I retrieve them, what do I want to do with them. The advantages of low-level programming iare better control over memory, much faster execution speed and for the skilled programmers ability to use full potential of the processor. I hope this was helpful..

Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#6

Re: Microcontroller Programming: How does the Controller Find the Machine Code?

10/22/2007 10:37 PM

Back in the '70s I worked with 6502 uP's with machine code and assembler. On power on (or reset) the computer would go to a specific address to fetch its first line of code. Lets say address FFF0H. If your code started at 0100H, you would make sure that at FFF0, you had the instruction JMP 0100 (jump to 0100).

My God!! I just realized that that was 30 years ago. Well that is how I remember it from the olden days.

Sincerely

Bill

Register to Reply
Register to Reply 6 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (2); cnpower (1); rcapper (1); Sciesis2 (1); Vulcan (1)

Previous in Forum: How do logic gates function?   Next in Forum: Simple Investigations for High School Students

Advertisement