ArticleslgStudy

computer science

Link register

Link register is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Link register rather than just read about it. In short: A link register (LR for short) is a register which holds the address to return to when a subroutine call completes. This is more efficient than the more traditional scheme of storing return addresses on a call stack, sometimes called a machine stack.

Key takeaways

  • Link register belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Link register to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Link register from memory before moving on to harder problems.

Reference excerpt

A link register (LR for short) is a register which holds the address to return to when a subroutine call completes. This is more efficient than the more traditional scheme of storing return addresses on a call stack, sometimes called a machine stack. The link register does not require the writes and reads of the memory containing the stack which can save a considerable percentage of execution time with repeated calls of small subroutines. The IBM POWER architecture, and its PowerPC and Power ISA successors, have a special-purpose link register, into which subroutine call instructions put the return address. In some other instruction sets, such as the ARM architectures, SPARC, and OpenRISC, subroutine call instructions put the return address into a specific general-purpose register, so that register is designated by the instruction set architecture as the link register. The ARMv7 architecture uses general-purpose register R14 as the link register, OpenRISC uses register r9, and SPARC uses "output register 7" or o7. In some others, such as PA-RISC, RISC-V, and the IBM System/360 and its successors, including z/Architecture, the subroutine call instruction can store the return address in any general-purpose register; a particular register is usually chosen, by convention, to be used as the link register. Some architectures have two link registers: a standard "branch link register" for most subroutine calls, and a special "interrupt link register" for interrupts. One of these is ARCv2 (ARC processors using version 2 of the ARCompact architecture), which uses general-purpose-registers r29 for the interrupt link register and r31 for the branch link register. References to "the link register" on such platforms will be referring to the branch link register. Earlier ARC processors based on the ARCompact and ARCtangent architectures had three link registers: two interrupt link registers (ILINK) and one branch link register (BLINK). The two interrupt link registers were ILINK1 (for level 1 (low priority) maskable interrupts), and ILINK2 (for level 2 (mid priority) maskable interrupts). In these architectures, r29 was used as the level 1 interrupt link register, r30 as the level 2 interrupt link register, and r31 as the branch link register. ILINK1 and ILINK2 were not accessible in user mode on the ARC 700 processors. The use of a link register, regardless of whether it is a dedicated register or a general-purpose register, allows for faster calls to leaf subroutines. When the subroutine is non-leaf, passing the return address in a register can still result in generation of more efficient code for thunks, e.g. for a subroutine whose sole purpose is to call another subroutine with arguments rearranged in some way. Other subroutines can benefit from the use of the link register because it can be saved in a batch with other callee-used registers—e.g. an ARM subroutine pushes registers 4-7 along with the link register, LR, by the single instruction STMDB SP!, {R4-R7, LR} pipelining all memory writes required.

References

Worked examples

Example 1 — a first encounter with Link register

Start with the simplest possible case. Write down what Link register claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Link register before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Link register ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Link register

In research
Link register appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Link register in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Link register is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer hardware stubs, Digital registers, so understanding it makes those chapters shorter.
In everyday life
Look for Link register outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Link register in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Link register means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Link register out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Link register in simple terms?

A link register (LR for short) is a register which holds the address to return to when a subroutine call completes. This is more efficient than the more traditional scheme of storing return addresses on a call stack, sometimes called a machine stack.

Why does Link register matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Link register?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Link register.

Tags

  • Computer hardware stubs
  • Digital registers

Keep exploring