Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

How to access the Program Counter of Nios II

Hey everybody. I'm a fairly new user using this board, however I come here to search for topics that can help solve my problems. Lately I have been successful finding these troubleshooting topics except for one.

I'm trying to access the Program Counter (PC) register of the Nios II Processor. Is there any available software function (C/C++ macro) that I'm able to access the program counter and store its value into a variable?

If this is not possible, then what other possible solutions that allows me to retrieve the value of the PC?

Thanks a lot

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Nios II provides the NEXTPC instruction that returns the PC of that instruction plus four.

    There doesn't appear to be a HAL macro available for using this

    instruction from C code. However, it is relatively easy to make one yourself.

    Just look at the examples in the HAL nios2.h file. It is located in your Nios II kit directory under components/altera_nios2/HAL/inc.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by james@May 30 2006, 10:13 AM

    nios ii provides the nextpc instruction that returns the pc of that instruction plus four.

    there doesn't appear to be a hal macro available for using this

    instruction from c code. however, it is relatively easy to make one yourself.

    just look at the examples in the hal nios2.h file. it is located in your nios ii kit directory under components/altera_nios2/hal/inc.

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=15686)

    --- quote end ---

    --- Quote End ---

    Thanks, I will certainly take a look at that