• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nicholas Kong

Question about Program Counter

6 posts in this topic

From what I read the Program Counter can hold the address of the current instruction or the next instruction.

 

1) Does that mean it can only hold one of the two at one time? If so, why is this?

 

I also read an instruction needs to get fetched, is the program counter doing the fetching too? I thought it was its job is to hold address of an instruction. blink.png

 

2) When an instruction gets fetched: what does it mean for a program counter to increased its stored value by 1? Is it as easy as adding the number 1 to this value?

 

3) Is the address of the instruction binary or hexadecimal? Is it encoded beforehand before the program counter fetches it?

 

4) If the program counter is holding the address of the next instruction, is the instruction register holding the address of the current instruction?

 

5) Who does the decoding of any of the two addresses of the instructions?

 

I am trying to make sense of both sources I read and it is pretty fuzzy of what is actually happening.

 

 

Source:

 

http://whatis.techtarget.com/definition/program-counter

 

http://stackoverflow.com/questions/15739489/program-counter-and-instruction-register

Edited by warnexus
0

Share this post


Link to post
Share on other sites
1) Does that mean it can only hold one of the two at one time? If so, why is this?
 
I also read an instruction needs to get fetched, is the program counter doing the fetching too? I thought it was its job is to hold address of an instruction. blink.png

It's 1 register, so it holds one value. When exactly it point to the next or current instruction depends on the architecture. Ostensibly it needs to point to the right instruction when that instruction is fetched, however.
 
2) When an instruction gets fetched: what does it mean for a program counter to increased its stored value by 1? Is it as easy as adding the number 1 to this value?
Yes, assuming that all instructions are the same size for a particular architecture. You can also look at it as increasing the PC by the size of an instruction, where the least significant bits are always 0 and therefore not represented in hardware.
 
3) Is the address of the instruction binary or hexadecimal? Is it encoded beforehand before the program counter fetches it?
There's no difference. binary and hexadecimal are details of how numbers are displayed, not how they are encoded, in this context. Binary can also be considered an encoding, but hexadecimal never is. Binary encoding might be contrasted with Binary coded decimals, but you probably won't need to know that.

4) If the program counter is holding the address of the next instruction, is the instruction register holding the address of the current instruction?
The instruction register would hold the value of the current instruction, like if it's an add or a load or whatever.
 
5) Who does the decoding of any of the two addresses of the instructions?
A block of transistors probably named for their role.
 

Also keep in mind that unless you're looking at a specific microprocessor, these concepts are pretty abstract, and may not exist physically in the same way. But they do model the behavior correctly. Edited by King Mir
2

Share this post


Link to post
Share on other sites

From what I read the Program Counter can hold the address of the current instruction or the next instruction.

1) Does that mean it can only hold one of the two at one time? If so, why is this?

The program counter and the accompanying notions of current and next instructions are abstractions, very useful to define what the various jump instructions do (choose the next instruction to execute, overriding the default of the one after the current instruction) but not necessarily related to how a processor actually works. Instructions can be executed out of order and simultaneously, making these concepts something that is merely emulated from the point of view of the program.
You can trust a processor to hold the address of an instruction it's fetching for as long as it's needed and then forget it, but there can be a queue of instruction addresses to fetch (possibly shared by multiple hardware threads or multiple cores) or something even more different from a program counter register.

I also read an instruction needs to get fetched, is the program counter doing the fetching too? I thought it was its job is to hold address of an instruction. blink.png

Fetching data from memory is the job of specialized hardware, including the instruction cache. Registers simply hold addresses, which are sent to the appropriate parts of the microprocessor.

2) When an instruction gets fetched: what does it mean for a program counter to increased its stored value by 1? Is it as easy as adding the number 1 to this value?

If you pretend the program is a sequence of instructions, you go to the next one; at the abstraction level of memory addresses you need to account for the length of encoded instructions, which is often variable.

3) Is the address of the instruction binary or hexadecimal? Is it encoded beforehand before the program counter fetches it?

Circuits and registers count in binary (high/low voltage); hexadecimal is only a human-friendly representation of binary numbers that, unlike decimal numbers, doesn't involve carry. But actually it's none of your business, the only addresses you need to read and write correctly are the ones in your program (which can have a far more complex structure with segments, offsets, implicit or discarded bits, etc.).

4) If the program counter is holding the address of the next instruction, is the instruction register holding the address of the current instruction?

The IR is an abstraction (what's the processor doing?) that doesn't correspond directly to microprocessor operation; the instructions being executed are represented implicitly in the configuration of what each register and execution unit do at each clock cycle. Moreover, what's executed is usually a sequence of low-level operations, not the complex instructions in the program.

5) Who does the decoding of any of the two addresses of the instructions?

Usually, dedicated address decoding units (hence the famous historical repurposing of the x86 LEA instruction to do arithmetic); on the cheap, the same ALUs used for general arithmetic (a lot slower). The result is the same, so it doesn't matter for the programmer.
1

Share this post


Link to post
Share on other sites
Just to clarify one thing: IP ("Instruction Pointer") is a synonym for PC ("Program Counter"), commonly used in the x86 architecture.

I think a lot of these issues would become clear if you were to learn the basics of assembly for some architecture. Is that what you are trying to do?
1

Share this post


Link to post
Share on other sites

Just to clarify one thing: IP ("Instruction Pointer") is a synonym for PC ("Program Counter"), commonly used in the x86 architecture.I think a lot of these issues would become clear if you were to learn the basics of assembly for some architecture. Is that what you are trying to do?


I do not mind learning more if it can be make sense of the r type load store and beq diagram. I am struggling to draw all 4 of them free hand in my computer architeture class. I need deep understanding before my mind can help me draw them
0

Share this post


Link to post
Share on other sites
A load gets an address from a register or immediate value, looks it up in memory, and puts the value found in a specified register.

A store gets an address from a register or immediate value and a value to store, and writes it to memory(or the write buffer if that's included in your model.)

Loads and stores can take many clock cycles more than any other instruction because they deal with memory.

BEQ, presumably branch on equal, reads a status register on the ALU, and if it's set appropriately, changes the instruction pointer to point to an offset specified by an immediate value.


It's hard to be more helpful without knowing the specific model your computer architecture course is using. So you should probably ask your professor or people who are familiar with that particular course and can see the assignments you're struggling with.

Just to clarify one thing: IP ("Instruction Pointer") is a synonym for PC ("Program Counter"), commonly used in the x86 architecture.

Yeah that was sloppy of me to use. I changed my above post not to mention IP. Edited by King Mir
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0