Assembly Language Functions and Procedures

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

flashcard set

Earn XP

Description and Tags

Flashcards about functions and procedures in assembly language, including function structure, register usage, stack operations, and calling conventions.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

What are the benefits of using functions in programming?

Functions can greatly simplify programming tasks by providing abstraction, modularity, code reuse, readability, testability & validation, and maintainability.

2
New cards

What is a function?

A function is a stored subroutine that performs a specific task based on the parameters with which it is provided.

3
New cards

Why are procedures used in programming?

Complex operations can be performed by calling a procedure, making code easier to understand, manage, and reuse.

4
New cards

Is branching to a label considered a function?

Branching to a label is not a function; specific rules must be followed to implement a function.

5
New cards

Describe functions in terms of carrying out a mission.

Functions are assigned a secret mission, acquire necessary resources, perform the mission, leave no trace, and return safely to the point of origin.

6
New cards

What are the steps in function execution?

Caller stores arguments, transfers flow control to the callee, callee allocates memory, executes the function body, stores the result, deallocates memory, and returns control to the caller.

7
New cards

How do you perform a procedure call and return in assembly?

bl (branch and link) stores the address of the next instruction in the link register (lr) and then jumps to the ProcedureAddress; to return, mov pc, lr is used.

8
New cards

What are the registers used for procedure calls?

r0-r3 are argument registers, r0 is the return value register, and lr is the return address register.

9
New cards

What is stack memory?

Stack is a memory region used to store local state for functions, it is a dynamic memory region, and follows a LIFO structure.

10
New cards

What is the stack pointer?

The stack pointer (sp) starts at address 0x20020000 and is used to grow (decrease sp) and shrink (increase sp) the stack.

11
New cards

What is stored in the stack?

The stack is used to store preserved registers, local function variables, and input arguments to the function.

12
New cards

What are the different types of registers according to the assembly convention?

r4-r11 are saved registers, r12 is a temporary register, SP (r13) is the stack pointer, r0-r3 are argument registers, and LR (r14) is the return address register.

13
New cards

What is register spilling?

Moving the contents of registers to the main memory is called spilling registers.

14
New cards

How does the ARM stack grow?

The stack pointer (SP) points to the top of the stack, and the ARM stack grows down in memory.

15
New cards

What are the functions of push and pop instructions for the stack?

Push modifies sp to make space and saves registers in memory; pop restores sp and registers.

16
New cards

What are leaf procedures?

Leaf procedures are procedures that don’t call other procedures.

17
New cards

What is the effect of the instruction push {r4, r5, lr}?

The instruction push {r4, r5, lr} saves the contents of r4, r5, and lr onto the stack, decrementing the stack pointer.

18
New cards

What is the effect of the instruction pop {r4, r5, lr}?

The instruction pop {r4, r5, lr} restores the contents of r4, r5, and lr from the stack, incrementing the stack pointer.

19
New cards

Give examples of non-preserved registers

Examples of non-preserved registers include r0, r1, r2 and r3