Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Instruction fetch from rom or ram memory?

Status
Not open for further replies.

Parth86

Member
hello everyone
Instruction should be fetch , decode and execute.
''Instruction fetch from memory''
I have read this statement many times but I did not understand which memory ROM or RAM memory
 
In your computer there is a "program counter" or some register that holds the current instruction address.
This current instruction address drives the address bus going to memory. (ROM or RAM or flash or ........)
The P.C. does not know what type of memory. It just knows it needs to get the next instruction.

There are many different kinds of computers!
The little PIC micros have the program and data memory as two totally different areas.

The Z80 computer has only one memory area that is both instructions and data. It is the job of the programmer to keep track of what area is data.
My first Z80 computer had a big memory board. I could add memory as I wanted.
>I had a 2048 of EEPROM for instructions.
>Then 32,000 of RAM where I could write programs and hold data as I chose.
>Then there was about 30,000 of memory space with no memory because I could not pay that much money.
 
vead.. All your questions tend to be extremely low level hardware questions... The trouble is we don't know whats in your head... The last time I looked you were creating a micro controller using an FPGA... Is this still the case... If not can you add which processor you are directing the question to.... Each hardware platform works differently.

Just tell us.. Its a Z80 or a Pic and we'll be far more help!!
 
yes you are correct , In my previous post I asked about 8051 microcontroller how they make. but Now I think i need to know how does micro controller work I am reading some datasheets
I have done some work I want to understand with this example

I am not sure but Think signal from the switch (input) goes input port which is addressed any other memory location in Ram memory
program in rom memory tell the processor to look at location and if the switch is open 0000 the location will hold 0000 data and If switch is closed 0001 location will hold 0001 data


RAM memory - ROM memory
location - address data
R0:8000 - 8000 0000 switch is open
R1:8006 - 8006 0001 switch is closed
!
!
! - ! !
R20 8010 0010

program contain both data and address in rom memory processor read the memory instruction 8000 0000

Decoder decode the instruction

processor do the arithmetic and logic operation

program tell the processor look at location and If switch is open 0000 the location 8000 will hold data 0000 and If switch is closed the location 8006 hold the data 0001

program counter execute instruction one by one

Instruction fetch- processor read the instruction from memory but there is two type of memory so first which one memory will be use rom ,or ram I mean during the fetch instruction , processor first read ROM or RAM memory?
 
I have uploaded image look at this image
processor deal with both memory

- ROM memory
address data
8000 - 0000 switch is open
8006 - 0001 switch is closed

RAM memory
location
R0:8000 switch is open
R1:8006 switch is closed

Instruction fetch- processor read the instruction from memory but there is two type of memory so first which one memory will be use rom ,or ram I mean during the fetch instruction , processor first read ROM or RAM memory?
 

Attachments

  • fig0-36.gif
    fig0-36.gif
    12.3 KB · Views: 260
Would that not depend on the Operating Systems program? The creator of the OS would decide which has priority?
 
You fetch the instruction from whichever memory has the instruction in it. Depending on your system architecture, it might be RAM or ROM.
 
It is like if you asked if cars use gasoline or diesel. It's impossible to tell, because some cars use gasoline and others use diesel.
 
Every one has said to you (I will say again) this depends on what type of computer!!!!

There are many different ways.

Here is one way. ROM has a address. RAM has a different address. Input / output had a third address. You (in this example) can not have ROM and RAM and I/O at the same 8000 address.
upload_2014-4-4_17-24-24.png

Here is a 8051 example.
There is a wire called PSEND that turns on the ROM and is used only to get a instruction.
There are wires READ and WRITE that talk to RAM and I/O. They are used for data and not instructions.
In this case you can have a instruction at 8000 and data at 8000 because they are really not at the same location.
Program 8000 is not the same as Data 8000. The address bus is 8000. But PSEND or READ determines which memory is turned on.
upload_2014-4-4_17-35-28.png

In the 8051 world we some times OR together the PSEN and READ lines together so the data memory and program memory are the same.

Here is a third type of computer. The ROM address and RAM address are different wires. The ROM data and the RAM data is different wires. Usually the I/O share with RAM. The I/O can be different.
In this case the data and instructions can be a different size. (8 bit data and 12 bit instructions) There is nothing in common with RAM and ROM. It is likely that a instruction and data are happening at the same time.
upload_2014-4-4_17-44-39.png
 
It is like if you asked if cars use gasoline or diesel. It's impossible to tell, because some cars use gasoline and others use diesel.
Some cars are electric and I have seen some that burn wood to make steam. I have a small wind up car. There are cars that start at the top of a hill and gravity pulls them down hill. Some cars don't go anywhere. Some only go on steal rails. Some go underground. There are some types made to be pulled by a horse. And yet some people keep asking what makes a car go.

I hope the pictures help. There are many different types of computers that I have not talked about.
 
Maybe you should study some z80 projects.

This one has a bootloader code in ROM which is used to load the actual application code to RAM.
**broken link removed**
Google finds more if you are interested.
 
Last edited:
Hello everyone I want understand how does microcontroller work so I have done some homework

Instruction should be fetch, decode and execute
assembly code
Mov A, #2
Mov R1, #3
Add A, R1

lets say program convert into hexa code

8000 0101 1st Instruction
8001 1o01 2nd instruction
8002 0101 3rd Instruction

this hex code stored in to rom memory
address data
8000 0101
8001 1o01
8002 0101

location of data stored into RAM
location
8000
8001
8002

ok now we want to fetch 1st instruction

we now about accumulator register , decoder
Instruction 1st is 8000 0101 fetch from rom memory, decoder take the information and it will store the value in A register, processor send the request in Ram memory and it look location 8000 for data 0101

program counter execute instruction one by one
now 2nd instruction 8001 1001 fetch from rom memory decoder take instruction and it will store value into register R1 processor send request in ram memory and ram memory look location 8001 for data 1001

3rd instruction fetch from rom memory decoder decode instruction and tell the alu for addition
alu do addition and result will save in ram memory

In my above paragraph I think there are many wrong statement so please check out me and correct me
 
This depends on what computer you are using!!!
Assume 8 bit Instructions, 8 bit data, MovA, #2 means move this data to A.

Mov A, #2
Mov R1, #3
Add A, R1

8000 01 Instruction
8001 02 data
8002 1o Instruction
8003 03 data
8004 05 Instruction


There are many different types of moves:
Move this data #2: A=2
Move data at address 2: (8 bit) address 0002=5, now A=5
Move data at address 1020 (16 bit) address 1020=7, now A=7
Move data pointed at by (data pointer 2)
 
This depends on what computer you are using!!!
Assume 8 bit Instructions, 8 bit data, MovA, #2 means move this data to A.

Mov A, #2
Mov R1, #3
Add A, R1

8000 01 Instruction
8001 02 data
8002 1o Instruction
8003 03 data
8004 05 Instruction


There are many different types of moves:
Move this data #2: A=2
Move data at address 2: (8 bit) address 0002=5, now A=5
Move data at address 1020 (16 bit) address 1020=7, now A=7
Move data pointed at by (data pointer 2)
thanks for help I am asking about 8051 , when will ram memory use after decoding instruction or before decoding instruction. my main confusen is that I didn't understand when does processor used both memory. In your example where does we use Ram memory can you explain little bit with this example .
 
Last edited by a moderator:
MOVE with no RAM used!
MOVC A,@A+DPTR Move Code (ROM) address=Data Pointer + A register and put that data into A.
MOVC A,@A+PC Move Code (ROM) address=PC+1+A and put that data from ROM to A.
MOV A,R1 Moves data from Register1 to A.
MOV A,R2 Moves data from Register2 to A.
MOV R3,A
MOV R4,#data Moves data from Code space to R4, Data comes from right after the instruction.
example: address 8000=01110100b and 8001=data

These instructions use RAM!
MOV A,@R0 The value in R0 (8 bit) points to a RAM location.
MOV @R0,A The value in R0 (8 bit) points to a RAM location.
MOVX @DPTR,A The 16 bit DataPointer is used to point at RAM.
MOVX @R0,A The 8 bit Ro (or R1) is used to point at RAM. Address is 00R0
 
ok that means
port p0 is high , SETB , P0
clear port P1 CLEAR P1
for this two instruction ROM address will be used?
can we say that rom memory may be used ?

mov A, R1
mov A, R2

for this two instruction ram location will be used?
can we say ram memory may be used for this two Instruction ?
 
ok that means
port p0 is high , SETB , P0
clear port P1 CLEAR P1
for this two instruction ROM address will be used?
can we say that rom memory may be used ?

mov A, R1
mov A, R2

for this two instruction ram location will be used?
can we say ram memory may be used for this two Instruction ?

The instructions will be in rom (non-volatile) memory even when the instruction reads/writes variables from ram (at least in microcontrollers like PIC or AVR).
 
In other words, all instructions are stored in ROM. Some of them read or write from RAM.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top