2

I am trying to understand some snippet of assembler code:

       ".syntax unified\n"
"1:\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " CMP %[SystemCoreClock],%[clock16MHz]\n"
       " BEQ.n 2f\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
       " NOP\n"
"2:\n"
       " SUBS %0, %0, #1\n"
       " BNE.n 1b\n"
       ".syntax divided\n"

What is the meaning of "f" when program branch to label 2 in line:

" BEQ.n 2f\n"

and what is the difference when branch with "b" in line

" BNE.n 1b\n"
old_timer
  • 69,149
  • 8
  • 89
  • 168
Esato
  • 127
  • 1
  • 9
  • 3
    What machine/architecture/platform is this? Looks like MC68k but I'm not familiar with those suffixes. – unwind Sep 05 '17 at 12:44
  • 6
    As a guess, I'd say "f" means forwards, and "b" means backwards. These may also be hints to the CPU's branch predictor. Knowing what the architecture is would help. – Retr0id Sep 05 '17 at 12:46
  • 2
    If you are using AS, those are [Local symbols](ftp://ftp.gnu.org/old-gnu/Manuals/gas/html_chapter/as_5.html#SEC48). – Margaret Bloom Sep 05 '17 at 12:56
  • 1
    yes 2f = 2: looking forward the next one you find. 1b 1: looking backward. do some experiments and look at the disassembly. – old_timer Sep 05 '17 at 13:09
  • This is Cortex M4, ARMv7E-M architecture and I think you are right, it is looking like forwards and backwards hints to processor. – Esato Sep 05 '17 at 13:22
  • these are not hints to a branch predictor, how is the assembler/toolchain going to provide that hint? the cortex-ms use a cache to deal with branch prediction (rather than looking deep into the pipe, their pipes are tiny anyway) first pass no hit, save, second time if not evicted then a chance at fetching early or maybe it always fetches early, an interesting performance experiment now that I think about it... – old_timer Sep 05 '17 at 13:25

1 Answers1

2

It is a lazy programmer shortcut AFAIK specific to the gnu assembly language. (an assembly language is defined by the assembler, the program that reads it, there are many arm, mips, x86, etc assembly languages)

1:
2:
    b 1b
    b 2b
    b 1f
    b 2f
2:
    b 1b
    b 1f
1:
    nop
    nop

assemble then disassemble

00000000 <.text>:
   0:   eafffffe    b   0 <.text>
   4:   eafffffd    b   0 <.text>
   8:   ea000002    b   18 <.text+0x18>
   c:   eaffffff    b   10 <.text+0x10>
  10:   eafffffa    b   0 <.text>
  14:   eaffffff    b   18 <.text+0x18>
  18:   e1a00000    nop         ; (mov r0, r0)
  1c:   e1a00000    nop         ; (mov r0, r0)
old_timer
  • 69,149
  • 8
  • 89
  • 168