Andes Workshop
https://forum.andestech.com/

Get PC (v3m)
https://forum.andestech.com/viewtopic.php?f=25&t=734
Page 1 of 1

Author:  cindy [ Wed Aug 28, 2013 3:26 pm ]
Post subject:  Get PC (v3m)

In programming guide, it describe how to get PC. (as following)

9.2. Get PC
While instruction “MFUSR rt5,PC” allows moving PC to the specified general purpose register rt5, it is not implemented in N1213 hardcore of CPU version 0x0C010003. Thus, a general way to get PC is “JAL 4”, which stored the address of next instruction into $lp. While this works fine, it does cause penalty on hardware branch prediction since it simply throws the whole prediction off balance.

but V3m doesn't support MFUSR instruction.
Please change to JAL 4, get $PC through $lp value.
note: If you want to preserve current $lp, please push $lp into stack.

Author:  ianfeng [ Mon Apr 28, 2014 7:30 pm ]
Post subject:  Re: Get PC (v3m)

Sample code:
For V3 toolchain:
Code:
   unsigned int ui_val;

   __asm__ ("MFUSR\t%0,$pc" : "=r" (ui_val) :);

For V3M toolchain:
$lp will be used, and it must be backuped and restored.
Code:
   unsigned int ui_val;

   __asm__ ("addi\t$r0,$lp,0\n\t" \
         "JAL 4\n\t" \
         "addi\t%0,$lp,0\n\t" \
         "addi\t$lp,$r0,0" : "=r" (ui_val) ::"$r0","$lp");

Page 1 of 1 All times are UTC + 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/