def f():
print("Hello world")
f()
sh-5.1$ python3 example_1.py
Hello World
import dis
def f():
print("Hello World")
dis.dis(f)
sh-5.1$ python3 example_2.py
4 0 LOAD_GLOBAL 0 (print)
2 LOAD_CONST 1 ('Hello World')
4 CALL_FUNCTION 1
6 POP_TOP
8 LOAD_CONST 0 (None)
10 RETURN_VALUE
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
sh-5.1$ gcc -S example_3.c
sh-5.1$ cat example_3.s
.file "example_3.c"
.text
.section .rodata
.LC0:
.string "Hello World!"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.LC0, %edi
call puts
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 12.1.1 20220507 (Red Hat 12.1.1-1)"
.section .note.GNU-stack,"",@progbits
import dis.dis
def main():
l = [1, 2, 3]
return l[2]
dis.dis(main)
sh-5.1$ python3 example_4.py
4 0 BUILD_LIST 0
2 LOAD_CONST 1 ((1, 2, 3))
4 LIST_EXTEND 1
6 STORE_FAST 0 (l)
5 8 LOAD_FAST 0 (l)
10 LOAD_CONST 2 (2)
12 BINARY_SUBSCR
14 RETURN_VALUE
The clock cycle
https://viralinstruction.com/posts/hardware/
$ aplay /dev/mem
Telegram: t.me/cocoa1231
Email: cocoathepenguin@protonmail.com