Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
276 words
1 minutes
Procedure_generally_means
procedure
In CPU and Operating Systems (OS), the word procedure generally means a sequence of instructions that performs a specific task.
In programming, a procedure is similar to a function or subroutine.
1. What is a procedure?
A procedure is a reusable block of code that:
- Performs a particular operation.
- Can be called from another part of a program.
- Executes its instructions.
- Returns control to the caller when finished.
For example, in C:
void print_hello(void) {
printf("Hello!\n");
}
int main(void) {
print_hello(); // Call procedure
return 0;
}Here, print_hello() is a procedure.
2. Procedure in CPU assembly
In x86-64 assembly, a procedure is commonly implemented as a function or subroutine.
section .text
global _start
_start:
call my_procedure
mov rax, 60
xor rdi, rdi
syscall
my_procedure:
mov rax, 10
mov rbx, 20
add rax, rbx
retExecution:
_start:
|
| call my_procedure
v
my_procedure:
|
| mov rax, 10
| mov rbx, 20
| add rax, rbx
| ret
|
v
_start: (continues after call)Important instructions:
| Instruction | Meaning |
|---|---|
call | Calls a procedure and saves the return address on the stack |
ret | Returns to the saved return address |
push | Saves a value on the stack |
pop | Restores a value from the stack |
3. Procedure vs. function vs. system call
| Term | Meaning |
|---|---|
| Procedure | A reusable sequence of instructions |
| Function | A callable block of code, often returning a value |
| Subroutine | Another name for a procedure |
| System call | A request from a program to the OS kernel for a service |
| Interrupt handler | A procedure executed in response to an interrupt |
4. Procedure in an operating system
In OS development, you might encounter procedures such as:
- Memory allocation procedure
- Process scheduling procedure
- Interrupt handling procedure
- Context switching procedure
- Page table management procedure
Key takeaway:
A procedure is essentially a sequence of instructions designed to perform a particular task. The CPU executes those instructions when the procedure is called.
In Rust, the closest equivalent is a function:
fn my_procedure() {
println!("Hello!");
}Procedure_generally_means
https://younghakim7.github.io/blog/posts/procedure_generally_means/