Showing register name on assembly

From time to time, I need to generate an assembly code from a C code to see how the compiler is generating stuff.

One of the problems I have is related to the assembly instructions that do not show register name, but just the number, which makes you confused related to literal and register names , as for example, when I generate an assembly for the following instructions, I see:

  • Move value 0 to the register 9
  • Move value of register 9 to register 3

li 9,0
mr 3,9

The problem becomes worse when you mix GPR (General Purpose Register) with VSX registers, as:

lxvd2x 0,10,9

If you do not know the Power Assembly instructions forms quite well, it is hard to map what is a immediate value, what is a GPR and what is a VSR.

If you are facing the same problem, the problem is that GCC has the option -mno-regnames as default.

In this case, I would recommend you using the GCC parameter -mregnames, which will dump registers differently than just the number, as %r for GPR and %vs for VSR registers. The code becomes much more human readable, as

li %r9,0
mr %r3,%r9

lxvd2x %vs0,%r10,%r9

2 thoughts on “Showing register name on assembly

  1. You can also use names inside an inline asm. In order to use it, just add another % in front of the named register, like asm (“li %%r9, 0 \n\t”), however, after a while you will note that inside an inline asm it mess with reading instead of improving it.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s