Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1b and 1f in GNU assembly

I am analyzing a linux exception code. By the way I can't understand gnu assembly syntax.

    svc_preempt:
    mov r8, lr
1:  bl  preempt_schedule_irq        @ irq en/disable is done inside
    ldr r0, [tsk, #TI_FLAGS]        @ get new tasks TI_FLAGS
    tst r0, #_TIF_NEED_RESCHED
    moveq   pc, r8              @ go again
    b   1b

In this code, I can see "b 1b", but I can't find "1b" label anywhere.

And,

#ifdef CONFIG_NEON
    adr r6, .LCneon_thumb_opcodes
    b   2f
#endif
call_fpe:
#ifdef CONFIG_NEON
    adr r6, .LCneon_arm_opcodes
2:
    ldr r7, [r6], #4            @ mask value
    cmp r7, #0              @ end mask?
    beq 1f
    and r8, r0, r7
    ldr r7, [r6], #4            @ opcode bits matching in mask
    cmp r8, r7              @ NEON instruction?
    bne 2b
    get_thread_info r10
    mov r7, #1
    strb    r7, [r10, #TI_USED_CP + 10] @ mark CP#10 as used
    strb    r7, [r10, #TI_USED_CP + 11] @ mark CP#11 as used
    b   do_vfp              @ let VFP handler handle this
1:

I can't find "2f" and "1f" label.

So, I wonder the meaning of "1b", "1f", "2f" and so on.

like image 952
user3247643 Avatar asked Dec 08 '14 07:12

user3247643


People also ask

What does B mean in assembly code?

The B instruction causes a branchto label . The BL instruction copies the address of the next instruction into r14 (lr, the link register), and causes a branch to label . Machine-level B and BL instructions have a range of ±32Mb from the address of the current instruction.

What does B do in assembly?

Branch (B) moves the PC to an address specified by a label. The label (“loop” in the example below) represents a section of code that you want the processor to execute next.

What does B do in MIPS?

b label Branch instruction Unconditionally branch to the instruction at the label. beq Rsrc1, Src2, label Branch on Equal Conditionally branch to the instruction at the label if the contents of register Rsrc1 equals Src2.

What is a 1 assembly language?

The 1: is a local symbol name; it's just a label. From the gas manual: Local Symbol Names. Local symbols help compilers and programmers use names temporarily.


Video Answer


1 Answers

Labels "xb" and "xf", where "x" is a number are a smart extension to the GNU assembly. It branches to the first found label "x" searching "forward" for "f" or "backward" for "b".

That means that in your first listing using "1b" as a target will search for "1" BEFORE the instruction that uses it. In the second listing "2f" will search for "2" AFTER the instruction that uses it, the "2b" at the end of this listing will then branch to the same "2", because it is BEFORE the instruction.

There may be multiple labels with numbers in your code.

See here - https://sourceware.org/binutils/docs-2.24/as/Symbol-Names.html#Symbol-Names - chapter "Local labels".

like image 139
Freddie Chopin Avatar answered Oct 06 '22 21:10

Freddie Chopin