├── aarch64 ├── ex │ ├── temp │ ├── ex002_macros_and_instrumentation │ │ ├── ex002a_debug_log_demo │ │ │ ├── test.file │ │ │ └── run.sh │ │ ├── ex002c_extract_bin │ │ │ ├── binary_extractor │ │ │ └── run.sh │ │ ├── ex002d_extract_bin_macroless │ │ │ ├── binary_extractor │ │ │ └── run.sh │ │ ├── ex002e_extract_bin_functionless │ │ │ ├── binary_extractor │ │ │ └── run.sh │ │ ├── ex002b_cat │ │ │ └── run.sh │ │ └── README.md │ └── ex001_the_basics │ │ ├── ex001a_minimal_executable │ │ ├── temp │ │ ├── run2.sh │ │ └── run.sh │ │ ├── README.md │ │ ├── ex001b_blink │ │ └── run.sh │ │ └── ex001c_gpio_read │ │ └── run.sh ├── README.md └── lib │ ├── IO │ ├── STRLEN.S │ ├── LOG_FILE.S │ ├── LOG_TEXT.S │ ├── LOG_OCTAL.S │ ├── LOG_BINARY.S │ └── LOG_HEXADECIMAL.S │ └── SYS │ ├── HELPER.S │ ├── EXIT.S │ ├── UNLINK.S │ └── CHMOD.S ├── license ├── ex ├── sandbox │ ├── hexwriter │ │ ├── test.schizo │ │ └── run.sh │ ├── README.md │ ├── bisect │ │ └── run.sh │ ├── bmp │ │ └── run.sh │ ├── fbdev │ │ └── run.sh │ ├── OS_detect │ │ └── run.sh │ ├── OS_detect2 │ │ └── run.sh │ ├── memmapprint │ │ └── run.sh │ ├── mousecap │ │ └── run.sh │ ├── rand_syscall │ │ └── run.sh │ ├── segfault │ │ └── run.sh │ ├── bisect_v_newton │ │ └── run.sh │ ├── mulsd_vs_divsd │ │ └── run.sh │ ├── printfloat_bug │ │ └── run.sh │ ├── ex006b_capture_keypresses │ │ └── run.sh │ └── perspective_projections │ │ └── run.sh ├── ex001_minimal_executable │ ├── ex001a_c_equivalent │ │ ├── run.sh │ │ └── code.c │ ├── ex001c_minimal_elf │ │ └── run.sh │ ├── ex001b_first_asm_program │ │ ├── code.o │ │ ├── run.sh │ │ └── code.asm │ └── README.md ├── ex004_printing_strings │ ├── ex004a_c_equivalent │ │ ├── run.sh │ │ └── code.c │ ├── ex004d_nyancat │ │ └── run.sh │ ├── ex004c_buffered_writes │ │ └── run.sh │ ├── ex004b_writing_to_stdout │ │ └── run.sh │ └── README.md ├── ex034_instanced_geometry │ ├── README.md │ └── ex031a_solid_scene │ │ └── run.sh ├── ex013_floating_point_io │ ├── ex013c_multiple_input_files │ │ ├── by.this │ │ ├── multiply.this │ │ └── run.sh │ ├── ex013d_writing_to_csv │ │ ├── matrix.out │ │ └── run.sh │ ├── ex013b_parse_floats_csv │ │ ├── matrix.csv │ │ └── run.sh │ ├── ex013a_parse_floats │ │ └── run.sh │ └── README.md ├── ex025_stl_files │ ├── ex025a_stl_export │ │ ├── cross.stl │ │ └── run.sh │ ├── ex025b_stl_import │ │ ├── cross.stl │ │ └── run.sh │ └── README.md ├── ex030_postfix_notation │ ├── ex30b_evaluate_input_file │ │ ├── expressions.in │ │ └── run.sh │ ├── ex30a_evaluate_postfix │ │ └── run.sh │ └── README.md ├── ex002_syscalls_and_functions │ ├── ex002c_vector_sum │ │ └── run.sh │ ├── ex002a_terminating_executables │ │ └── run.sh │ ├── ex002b_exiting_via_function │ │ └── run.sh │ └── README.md ├── ex003_command_line_args_and_code_golf │ ├── ex003b_chmod_smaller │ │ └── run.sh │ ├── ex003d_touch_smaller │ │ └── run.sh │ ├── ex003e_rm_alternative │ │ └── run.sh │ ├── ex003f_rm_smaller │ │ └── run.sh │ ├── ex003a_chmod_alternative │ │ └── run.sh │ ├── ex003c_touch_alternative │ │ └── run.sh │ └── README.md ├── ex009_timing │ ├── ex009a_rdtsc │ │ └── run.sh │ ├── ex009f_sleep_delay │ │ └── run.sh │ ├── ex009c_gettimeofday_syscall │ │ └── run.sh │ ├── ex009b_tick_and_tock_in_cycles │ │ └── run.sh │ ├── ex009e_estimate_CPU_frequency │ │ └── run.sh │ ├── ex009d_tick_and_tock_in_microseconds │ │ └── run.sh │ └── README.md ├── ex006_user_input │ ├── ex006a_stdin │ │ └── run.sh │ ├── ex006c_game │ │ └── run.sh │ ├── ex006d_piped_stdin │ │ └── run.sh │ ├── ex006b_capture_keypresses │ │ └── run.sh │ └── README.md ├── ex016_trigonometry │ ├── ex016c_tan │ │ └── run.sh │ ├── ex016e_atan │ │ └── run.sh │ ├── ex016a_sin_and_cos │ │ └── run.sh │ ├── ex016d_plotting_tan │ │ └── run.sh │ ├── ex016b_plotting_sin_and_cos │ │ └── run.sh │ └── README.md ├── ex020_framebuffer │ ├── ex020e_flags │ │ └── run.sh │ ├── ex020f_3d_cube │ │ └── run.sh │ ├── ex020a_framebuffer_ioctl │ │ └── run.sh │ ├── ex020b_framebuffer_basics │ │ └── run.sh │ ├── ex020c_framebuffer_clear │ │ └── run.sh │ ├── ex020d_epilepsy_warning │ │ └── run.sh │ └── README.md ├── ex022_3d_graphics │ ├── ex022a_cube │ │ └── run.sh │ ├── ex022c_scene │ │ └── run.sh │ ├── ex022b_rendering_simplified │ │ └── run.sh │ └── README.md ├── ex008_randomness │ ├── ex008a_random_int │ │ └── run.sh │ ├── ex008b_random_int_array │ │ └── run.sh │ ├── ex008c_random_float │ │ └── run.sh │ ├── ex008e_deal_or_no_deal │ │ └── run.sh │ ├── ex008d_random_float_array │ │ └── run.sh │ ├── ex008f_cpu_support_and_getrandom_syscall │ │ └── run.sh │ └── README.md ├── ex029_HUD_interface │ ├── ex029b_hud_menu │ │ └── run.sh │ ├── ex029a_simple_hud │ │ └── run.sh │ └── README.md ├── ex007_fractions │ ├── ex007a_printing_floats │ │ └── run.sh │ ├── ex007b_scientific_floats │ │ └── run.sh │ ├── ex007c_printing_fixed │ │ └── run.sh │ ├── ex007d_floats_speedtest │ │ └── run.sh │ ├── ex007e_fixed_speedtest │ │ └── run.sh │ ├── ex007f_fraction_speedtest │ │ └── run.sh │ └── README.md ├── ex012_bitmap_images │ ├── ex012a_bitmap_basics │ │ └── run.sh │ ├── ex012c_filled_rectangles │ │ └── run.sh │ ├── ex012b_basic_drawing_operations │ │ └── run.sh │ └── README.md ├── ex017_root_finding │ ├── ex017b_secant_method │ │ └── run.sh │ ├── ex017c_newtons_method │ │ └── run.sh │ ├── ex017a_bisection_method │ │ └── run.sh │ └── README.md ├── ex018_LU_decomposition │ ├── ex018c_lu_solve │ │ └── run.sh │ ├── ex018a_matrix_types │ │ └── run.sh │ ├── ex018b_lu_step_by_step │ │ └── run.sh │ ├── ex018d_plu_decomposition │ │ └── run.sh │ └── README.md ├── ex021_mouse_input │ ├── ex021b_mouse_status │ │ └── run.sh │ ├── ex021c_mouse_cursor │ │ └── run.sh │ ├── ex021d_rotate_3d_model │ │ └── run.sh │ ├── ex021a_read_mouse_device │ │ └── run.sh │ └── README.md ├── ex023_rendering_text │ ├── ex023a_sample_text │ │ └── run.sh │ ├── ex023d_simple_gui │ │ └── run.sh │ ├── ex023b_alphabet_screensaver │ │ └── run.sh │ ├── ex023c_3d_text_annotations │ │ └── run.sh │ └── README.md ├── ex024_3d_graphics_cont │ ├── ex024a_points │ │ └── run.sh │ ├── ex024c_3d_faces │ │ └── run.sh │ ├── ex024b_sample_triangle │ │ └── run.sh │ ├── ex024d_3d_faces_improved │ │ └── run.sh │ └── README.md ├── ex031_trig_revisited │ ├── ex031a_sine_algs │ │ └── run.sh │ ├── ex031b_cosine_algs │ │ └── run.sh │ └── README.md ├── ex005_printing_integers │ ├── ex005a_printing_ints │ │ └── run.sh │ ├── ex005d_dumping_memory │ │ └── run.sh │ ├── ex005b_printing_registers │ │ └── run.sh │ ├── ex005c_printing_int_arrays │ │ └── run.sh │ └── README.md ├── ex010_matrix_basics │ ├── ex010a_creating_matrices │ │ └── run.sh │ ├── ex010b_manipulating_matrices │ │ └── run.sh │ ├── ex010c_basic_matrix_arithmetic │ │ └── run.sh │ ├── ex010d_multiplying_non_square_matrices │ │ └── run.sh │ └── README.md ├── ex011_memory_allocation │ ├── ex011a_alloc_and_free │ │ └── run.sh │ ├── ex011c_linked_list │ │ └── run.sh │ ├── ex011d_checking_for_leaks │ │ └── run.sh │ ├── ex011b_multiple_alloc_and_free │ │ └── run.sh │ └── README.md ├── ex014_scatter_plots │ ├── ex014a_basic_scatter_plot │ │ └── run.sh │ ├── ex014b_multiple_datasets │ │ └── run.sh │ ├── ex014d_drawing_pictures │ │ └── run.sh │ ├── ex014c_evaluating_functions │ │ └── run.sh │ └── README.md ├── ex015_data_reports │ ├── ex015a_financial_report │ │ └── run.sh │ ├── ex015b_cantilever_beam_bending │ │ └── run.sh │ └── README.md ├── ex026_3d_frames_FEA │ ├── ex026a_cantilever_problem │ │ └── run.sh │ ├── ex026b_ladder_problem │ │ └── run.sh │ └── README.md ├── ex027_integration │ ├── ex027a_trapezoidal_method │ │ └── run.sh │ ├── ex027b_gaussian_quadrature │ │ └── run.sh │ └── README.md ├── ex019_least_squares_regression │ ├── ex019a_linear_fit │ │ └── run.sh │ ├── ex019b_quadratic_fit │ │ └── run.sh │ └── README.md ├── ex028_perspective_projections │ ├── ex028a_solid_scene │ │ └── run.sh │ ├── ex028b_gradient_scene │ │ └── run.sh │ └── README.md ├── ex032_3d_scatterplots │ ├── ex032a_random_point_cloud │ │ └── run.sh │ ├── ex032b_multiple_datasets │ │ └── run.sh │ ├── ex032c_multiple_subplots │ │ └── run.sh │ └── README.md └── ex033_3d_curves_and_surfaces │ ├── ex033a_plot_3d_curve │ └── run.sh │ └── README.md ├── .gitignore ├── lib ├── sys │ ├── exit.asm │ ├── chmod.asm │ └── getenv.asm ├── io │ ├── print_buffer_reset.asm │ ├── strlen.asm │ ├── file_close.asm │ ├── file_delete.asm │ ├── bitmap │ │ ├── get_pixel.asm │ │ ├── set_filled_rect.asm │ │ ├── set_pixel.asm │ │ ├── set_polygon.asm │ │ ├── set_rect.asm │ │ ├── set_filled_polygon.asm │ │ ├── set_fill.asm │ │ └── set_foreground.asm │ ├── file_open.asm │ ├── read_chars.asm │ ├── print_ascii.asm │ ├── strcmp.asm │ ├── print_fraction.asm │ ├── framebuffer │ │ ├── framebuffer_clear.asm │ │ ├── framebuffer_flush.asm │ │ ├── framebuffer_mouse_init.asm │ │ └── framebuffer_hud_init.asm │ ├── print_string.asm │ ├── ansi_move_cursor.asm │ ├── print_buffer_flush_to_memory.asm │ ├── print_buffer_flush.asm │ ├── print_int_b.asm │ ├── print_int_o.asm │ ├── print_int_h_n_digits.asm │ ├── print_delimited_floats.asm │ ├── print_int_h.asm │ ├── print_fixed.asm │ ├── parse_int.asm │ ├── print_memory.asm │ ├── print_int_d.asm │ ├── print_stack.asm │ └── print_chars.asm ├── mem │ ├── memset.asm │ ├── strcopy.asm │ ├── find_byte_offset.asm │ ├── strcopy_null.asm │ ├── strsplit.asm │ ├── heap_eval.asm │ ├── heap_init.asm │ └── memcopy.asm ├── math │ ├── expressions │ │ ├── trig │ │ │ ├── sine_x87.asm │ │ │ ├── cosine_x87.asm │ │ │ └── sine_bhaskara.asm │ │ └── parse │ │ │ └── shunting_yard.asm │ ├── lin_alg │ │ ├── set_zero.asm │ │ ├── set_identity.asm │ │ ├── swap_matrix_rows.asm │ │ ├── copy_diagonal.asm │ │ ├── lu_solve.asm │ │ ├── inverse_2x2.asm │ │ ├── copy_lower_triangle.asm │ │ ├── copy_upper_triangle.asm │ │ ├── is_diagonal.asm │ │ ├── plu_solve.asm │ │ ├── is_upper_triangular.asm │ │ ├── is_lower_triangular.asm │ │ └── least_squares_regression.asm │ ├── matrix │ │ ├── matrix_set_all_values.asm │ │ ├── matrix_scale_in_place.asm │ │ ├── matrix_add_in_place.asm │ │ ├── matrix_subtract_in_place.asm │ │ ├── matrix_scale.asm │ │ ├── matrix_add.asm │ │ ├── matrix_subtract.asm │ │ ├── matrix_extract_row.asm │ │ ├── matrix_insert_row.asm │ │ ├── matrix_set_identity.asm │ │ ├── matrix_insert_column.asm │ │ ├── matrix_extract_column.asm │ │ ├── matrix_populate.asm │ │ └── matrix_transpose.asm │ ├── int │ │ ├── max_int.asm │ │ ├── min_int.asm │ │ └── packed_sum.asm │ ├── vector │ │ ├── distance_3.asm │ │ ├── dot_product.asm │ │ ├── cross_product.asm │ │ ├── dot_product_3.asm │ │ ├── normalize_3.asm │ │ ├── cross_product_3.asm │ │ ├── max_abs_float.asm │ │ └── perpendicularize_3.asm │ ├── rand │ │ ├── rand_int.asm │ │ ├── rand_float.asm │ │ ├── rand_int_array.asm │ │ └── rand_float_array.asm │ ├── parametric │ │ └── linear_space.asm │ ├── integration │ │ └── trapezoidal_method.asm │ └── root_finding │ │ ├── newtons_method.asm │ │ └── secant_method.asm ├── time │ ├── tick_cycles.asm │ ├── tock_cycles.asm │ ├── tick_time.asm │ ├── tock_time.asm │ └── sleep.asm ├── sort │ └── bubble_sort.asm ├── engr │ └── cad │ │ └── primitives │ │ └── put_cube.asm └── debug │ └── debug_master_start.asm ├── lab ├── template │ └── run.sh ├── lab006_ls │ └── run.sh ├── lab007_todo │ └── run.sh ├── lab005_hexdump │ └── run.sh ├── lab001_cramers_rule │ └── run.sh ├── lab004_countdown_timer │ └── run.sh ├── lab002_multiple_root_finding │ └── run.sh └── lab003_password_generator │ └── make.sh ├── clean_up.sh ├── find_segfault.sh └── make_bins.sh /aarch64/ex/temp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | public domain 2 | -------------------------------------------------------------------------------- /ex/sandbox/hexwriter/test.schizo: -------------------------------------------------------------------------------- 1 | 12345678 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | **binary 3 | **.map 4 | **.html 5 | **.svg 6 | log.file 7 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002a_debug_log_demo/test.file: -------------------------------------------------------------------------------- 1 | sdfsdfsdfsdf -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001a_c_equivalent/run.sh: -------------------------------------------------------------------------------- 1 | cc code.c -o binary 2 | ./binary 3 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/ex004a_c_equivalent/run.sh: -------------------------------------------------------------------------------- 1 | cc code.c -o binary 2 | ./binary 3 | -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001a_c_equivalent/code.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | while(1); 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /ex/ex034_instanced_geometry/README.md: -------------------------------------------------------------------------------- 1 | ## Instance Geometry 2 | 3 | In [ex031a](ex031a_solid_scene), .. 4 | 5 | -------------------------------------------------------------------------------- /ex/sandbox/README.md: -------------------------------------------------------------------------------- 1 | ## Sandbox 2 | 3 | Just a directory I use to play around with different ideas. 4 | 5 | -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001c_minimal_elf/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013c_multiple_input_files/by.this: -------------------------------------------------------------------------------- 1 | -4.2001e2;-1.3370e3;-1.7760e3;0;7.7912e0;1.2813e1;0;0;8.6768e-1 2 | -------------------------------------------------------------------------------- /ex/ex025_stl_files/ex025a_stl_export/cross.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/ex/ex025_stl_files/ex025a_stl_export/cross.stl -------------------------------------------------------------------------------- /ex/ex025_stl_files/ex025b_stl_import/cross.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/ex/ex025_stl_files/ex025b_stl_import/cross.stl -------------------------------------------------------------------------------- /ex/ex030_postfix_notation/ex30b_evaluate_input_file/expressions.in: -------------------------------------------------------------------------------- 1 | 5 5 + 2 | pi sin 3 | 33 2 / exp e + 5 * 4 | 144 sqrt 12 - 5 | 2 10 ^ 6 | 5 / 7 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013d_writing_to_csv/matrix.out: -------------------------------------------------------------------------------- 1 | 1.11000e0&2.22000e0&3.33000e0&-4.44000e0&-5.55000e0&-6.66000e0&7.77000e0&8.88000e0&9.99000e0 -------------------------------------------------------------------------------- /lib/sys/exit.asm: -------------------------------------------------------------------------------- 1 | %ifndef EXIT 2 | %define EXIT 3 | 4 | exit: ; void exit(byte {dil}); 5 | 6 | mov rax,SYS_EXIT 7 | syscall 8 | 9 | %endif 10 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/ex001a_minimal_executable/temp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/aarch64/ex/ex001_the_basics/ex001a_minimal_executable/temp -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001b_first_asm_program/code.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/ex/ex001_minimal_executable/ex001b_first_asm_program/code.o -------------------------------------------------------------------------------- /ex/ex002_syscalls_and_functions/ex002c_vector_sum/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013c_multiple_input_files/multiply.this: -------------------------------------------------------------------------------- 1 | -9.9997e-1,8.1881e-3,-4.8807e-4,-7.4797e-3,-9.3465e-1,-3.5550e-1,-3.3671e-3,-3.5549e-1,9.3468e-1 2 | -------------------------------------------------------------------------------- /ex/ex002_syscalls_and_functions/ex002a_terminating_executables/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex002_syscalls_and_functions/ex002b_exiting_via_function/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003b_chmod_smaller/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003d_touch_smaller/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003e_rm_alternative/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003f_rm_smaller/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003a_chmod_alternative/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/ex003c_touch_alternative/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | chmod +x binary 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/ex004a_c_equivalent/code.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | for (int i=0; i<1000000; i++) 5 | printf("i hate the antichrist "); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /lab/template/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002c_extract_bin/binary_extractor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/aarch64/ex/ex002_macros_and_instrumentation/ex002c_extract_bin/binary_extractor -------------------------------------------------------------------------------- /lab/lab006_ls/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /lab/lab007_todo/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013b_parse_floats_csv/matrix.csv: -------------------------------------------------------------------------------- 1 | 1.01,-2.02,3.03,-4.04,5.05,-6.06,7.07,-8.08,9.09,-10.10,11.11,-12.12,13.13,-14.14,15.15,-16.16,17.17,-18.18,19.19,-20.20,21.21,-22.22,23.23,-24.24 2 | -------------------------------------------------------------------------------- /lab/lab005_hexdump/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/bisect/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/bmp/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/fbdev/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /lab/lab001_cramers_rule/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /lab/lab004_countdown_timer/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/OS_detect/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/OS_detect2/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/hexwriter/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/memmapprint/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/mousecap/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/rand_syscall/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/segfault/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /lab/lab002_multiple_root_finding/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002d_extract_bin_macroless/binary_extractor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/aarch64/ex/ex002_macros_and_instrumentation/ex002d_extract_bin_macroless/binary_extractor -------------------------------------------------------------------------------- /ex/ex009_timing/ex009a_rdtsc/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/bisect_v_newton/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/mulsd_vs_divsd/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/printfloat_bug/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002e_extract_bin_functionless/binary_extractor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmdi/SCHIZONE/HEAD/aarch64/ex/ex002_macros_and_instrumentation/ex002e_extract_bin_functionless/binary_extractor -------------------------------------------------------------------------------- /ex/ex006_user_input/ex006a_stdin/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex006_user_input/ex006c_game/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/ex016c_tan/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/ex016e_atan/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020e_flags/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex022_3d_graphics/ex022a_cube/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex022_3d_graphics/ex022c_scene/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex006_user_input/ex006d_piped_stdin/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008a_random_int/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex009_timing/ex009f_sleep_delay/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020f_3d_cube/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex025_stl_files/ex025a_stl_export/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex025_stl_files/ex025b_stl_import/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex029_HUD_interface/ex029b_hud_menu/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/ex006b_capture_keypresses/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/sandbox/perspective_projections/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/ex004d_nyancat/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007a_printing_floats/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007b_scientific_floats/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007c_printing_fixed/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007d_floats_speedtest/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007e_fixed_speedtest/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008b_random_int_array/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008c_random_float/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008e_deal_or_no_deal/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex009_timing/ex009c_gettimeofday_syscall/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex012_bitmap_images/ex012a_bitmap_basics/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/ex016a_sin_and_cos/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/ex016d_plotting_tan/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex017_root_finding/ex017b_secant_method/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex017_root_finding/ex017c_newtons_method/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex018_LU_decomposition/ex018c_lu_solve/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex021_mouse_input/ex021b_mouse_status/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex021_mouse_input/ex021c_mouse_cursor/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex021_mouse_input/ex021d_rotate_3d_model/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex023_rendering_text/ex023a_sample_text/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex023_rendering_text/ex023d_simple_gui/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex024_3d_graphics_cont/ex024a_points/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex024_3d_graphics_cont/ex024c_3d_faces/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex029_HUD_interface/ex029a_simple_hud/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex031_trig_revisited/ex031a_sine_algs/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex031_trig_revisited/ex031b_cosine_algs/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/ex004c_buffered_writes/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex005_printing_integers/ex005a_printing_ints/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex005_printing_integers/ex005d_dumping_memory/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex006_user_input/ex006b_capture_keypresses/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex007_fractions/ex007f_fraction_speedtest/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008d_random_float_array/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex009_timing/ex009b_tick_and_tock_in_cycles/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex009_timing/ex009e_estimate_CPU_frequency/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex010_matrix_basics/ex010a_creating_matrices/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex011_memory_allocation/ex011a_alloc_and_free/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex011_memory_allocation/ex011c_linked_list/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex012_bitmap_images/ex012c_filled_rectangles/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013a_parse_floats/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013d_writing_to_csv/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex014_scatter_plots/ex014a_basic_scatter_plot/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex014_scatter_plots/ex014b_multiple_datasets/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex014_scatter_plots/ex014d_drawing_pictures/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex015_data_reports/ex015a_financial_report/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex017_root_finding/ex017a_bisection_method/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex018_LU_decomposition/ex018a_matrix_types/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex018_LU_decomposition/ex018b_lu_step_by_step/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020a_framebuffer_ioctl/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020b_framebuffer_basics/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020c_framebuffer_clear/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/ex020d_epilepsy_warning/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex021_mouse_input/ex021a_read_mouse_device/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex022_3d_graphics/ex022b_rendering_simplified/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex024_3d_graphics_cont/ex024b_sample_triangle/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex026_3d_frames_FEA/ex026a_cantilever_problem/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex026_3d_frames_FEA/ex026b_ladder_problem/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex027_integration/ex027a_trapezoidal_method/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex027_integration/ex027b_gaussian_quadrature/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex031_trig_revisited/README.md: -------------------------------------------------------------------------------- 1 | ## Trig Revisited 2 | 3 | In [ex031a](ex031a_sine_algs), a buffet of sine approximation algorithms compared in terms of speed and accuracy. 4 | 5 | In [ex031b](ex031b_cosine_algs), same but for cosine. 6 | 7 | -------------------------------------------------------------------------------- /ex/ex034_instanced_geometry/ex031a_solid_scene/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/ex001a_minimal_executable/run2.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp # assemble the code into object file 2 | 3 | ../../ex002_basic_functions/ex002d_extract_bin_macroless/binary_extractor temp binary 4 | 5 | ./binary # execute binary 6 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/ex004b_writing_to_stdout/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex005_printing_integers/ex005b_printing_registers/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex005_printing_integers/ex005c_printing_int_arrays/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex009_timing/ex009d_tick_and_tock_in_microseconds/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex010_matrix_basics/ex010b_manipulating_matrices/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex010_matrix_basics/ex010c_basic_matrix_arithmetic/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex011_memory_allocation/ex011d_checking_for_leaks/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013b_parse_floats_csv/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex014_scatter_plots/ex014c_evaluating_functions/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex015_data_reports/ex015b_cantilever_beam_bending/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/ex016b_plotting_sin_and_cos/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex018_LU_decomposition/ex018d_plu_decomposition/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex019_least_squares_regression/ex019a_linear_fit/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex023_rendering_text/ex023b_alphabet_screensaver/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex023_rendering_text/ex023c_3d_text_annotations/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex024_3d_graphics_cont/ex024d_3d_faces_improved/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex028_perspective_projections/ex028a_solid_scene/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex032_3d_scatterplots/ex032a_random_point_cloud/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex032_3d_scatterplots/ex032b_multiple_datasets/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex032_3d_scatterplots/ex032c_multiple_subplots/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex033_3d_curves_and_surfaces/ex033a_plot_3d_curve/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex011_memory_allocation/ex011b_multiple_alloc_and_free/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex012_bitmap_images/ex012b_basic_drawing_operations/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/ex013c_multiple_input_files/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex019_least_squares_regression/ex019b_quadratic_fit/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex028_perspective_projections/ex028b_gradient_scene/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex030_postfix_notation/ex30a_evaluate_postfix/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary "pi sin" 4 | -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001b_first_asm_program/run.sh: -------------------------------------------------------------------------------- 1 | nasm -felf64 code.asm 2 | ld code.o -o binary #-s # uncomment '-s' to strip symbols 3 | strip -R .comment binary # uncomment this to strip symbols 4 | # and useless version info 5 | ./binary 6 | -------------------------------------------------------------------------------- /ex/ex008_randomness/ex008f_cpu_support_and_getrandom_syscall/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex010_matrix_basics/ex010d_multiplying_non_square_matrices/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary 4 | -------------------------------------------------------------------------------- /ex/ex027_integration/README.md: -------------------------------------------------------------------------------- 1 | ## Integration 2 | 3 | In [ex027a](ex027a_trapezoidal_method), we estimate an integral using the trapezoidal method. 4 | 5 | In [ex027b](ex027b_gaussian_quadrature), we estimate the same integral using Gaussian quadrature. 6 | 7 | -------------------------------------------------------------------------------- /ex/ex029_HUD_interface/README.md: -------------------------------------------------------------------------------- 1 | ## HUD Interface 2 | 3 | In [ex029a](ex029a_simple_hud), we compute and plot the framerate, mouse position, and simple button on a rendered 3D scene. 4 | 5 | In [ex029b](ex029b_hud_menu), we implement a simple menu on a rendered 3D scene. 6 | -------------------------------------------------------------------------------- /ex/ex030_postfix_notation/ex30b_evaluate_input_file/run.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../../ -I ../../../lib/sys/`uname` -o binary code.asm 2 | ../../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | ./binary expressions.in answers.out 4 | -------------------------------------------------------------------------------- /ex/ex019_least_squares_regression/README.md: -------------------------------------------------------------------------------- 1 | ## Least Squares Regression 2 | 3 | In [ex019a](ex019a_linear_fit), we use least squares to fit a line to a dataset and plot it. 4 | 5 | In [ex019b](ex019b_quadratic_fit), we use least squares to fit a parabola to a dataset and plot it. 6 | -------------------------------------------------------------------------------- /lab/lab003_password_generator/make.sh: -------------------------------------------------------------------------------- 1 | nasm -f bin -I ../../ -I ../../lib/sys/`uname` -o binary code.asm 2 | ../../bin/make_executable binary # run ./make_bins.sh to generate this, or use "chmod +x binary" 3 | # ./binary # commented out because this binary takes a command line argument 4 | -------------------------------------------------------------------------------- /ex/ex032_3d_scatterplots/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Scatterplots 2 | 3 | In [ex032a](ex032a_random_point_cloud), we render points that are scattered about. 4 | 5 | In [ex032b](ex032b_multiple_datasets), we render multiple datasets. 6 | 7 | In [ex032c](ex032b_multiple_subplots), we render multiple subplots. 8 | -------------------------------------------------------------------------------- /ex/ex017_root_finding/README.md: -------------------------------------------------------------------------------- 1 | ## Root Finding 2 | 3 | In [ex017a](ex017a_bisection_method), we find a root using a bisection method. 4 | 5 | In [ex017b](ex017b_secant_method), we find a root using a secant method. 6 | 7 | In [ex017c](ex017c_newtons_method), we find a root using Newton's method. 8 | -------------------------------------------------------------------------------- /ex/ex015_data_reports/README.md: -------------------------------------------------------------------------------- 1 | ## Data Reports 2 | 3 | In [ex015a](ex015a_financial_report), we generate a sample financial report, illustrating the basics of reports. 4 | 5 | In [ex015b](ex015b_cantilever_beam_bending), we generate a sample structural analysis report, illustrating the basics of reports. 6 | -------------------------------------------------------------------------------- /clean_up.sh: -------------------------------------------------------------------------------- 1 | # clean up everything but the source code 2 | find . -name 'binary' -delete 3 | find . -name 'myfile.map' -delete 4 | find . -name '*.bmp' -delete 5 | find . -name '*.svg' -delete 6 | find . -name '*.html' -delete 7 | rm -f -R bin 8 | rm -f ex/ex001_minimal_executable/ex001b_first_asm_program/code.o 9 | -------------------------------------------------------------------------------- /ex/ex025_stl_files/README.md: -------------------------------------------------------------------------------- 1 | ## STL Files 2 | 3 | Note: need to run some of these examples as super user for permissions on the mouse device. 4 | 5 | In [ex025a](ex025a_stl_export), we export a 3D geometry to an .stl file. 6 | 7 | In [ex025b](ex025b_stl_import), we import a 3D geometry from an .stl file. 8 | 9 | -------------------------------------------------------------------------------- /ex/ex030_postfix_notation/README.md: -------------------------------------------------------------------------------- 1 | ## Postfix Notation 2 | 3 | In [ex030a](ex030a_evaluate_postfix), we parse and resolve a mathematic expression in Reverse Polish Notation. 4 | 5 | In [ex030b](ex030b_evaluate_input_file), we parse and resolve mathematic expressions passed via input file into output file. 6 | 7 | -------------------------------------------------------------------------------- /aarch64/README.md: -------------------------------------------------------------------------------- 1 | # SCHIZONE aarch64 2 | 3 | Minimal scientific computing via Arm64, particularly for Raspberry Pi (Zero 2W). 4 | 5 | ## Episodes 6 | | DATE | TOPIC | VIDEO | 7 | | :---: | :---: | :---: | 8 | | APR 26, 2025 | [The Basics](ex/ex001_the_basics) | [EP. 033](https://youtu.be/WsQZMo61WOI) | 9 | 10 | -------------------------------------------------------------------------------- /ex/ex026_3d_frames_FEA/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Frames FEA 2 | 3 | Note: need to run these examples as super user for permissions on the mouse device. 4 | 5 | In [ex026a](ex026a_cantilever_problem), we analyze and plot a 3D cantilever beam. 6 | 7 | In [ex026b](ex026b_ladder_problem), we analyze and plot a 3D ladder frame. 8 | 9 | -------------------------------------------------------------------------------- /ex/ex033_3d_curves_and_surfaces/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Curves and Surfaces 2 | 3 | In [ex033a](ex033a_plot_3d_curve), we render a 3D curve. 4 | 5 | In [ex033b](ex033b_plot_3d_surface), we render a 3D surface, inspired by ex032b. 6 | 7 | In [ex033c](ex033c_multi_plot_3d), we render a 3D scatterplot, curve, and surface. 8 | 9 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/README.md: -------------------------------------------------------------------------------- 1 | ## the basics 2 | 3 | In [ex001a](ex001a_minimal_executable), we implement a minimal working ELF & program header and executable that loops forever. 4 | 5 | In [ex001b](ex001b_blink), we blink an LED on & off on GPIO pin 19. 6 | 7 | In [ex001c](ex001c_gpio_read), we poll an input level on GPIO pin 19. 8 | 9 | -------------------------------------------------------------------------------- /ex/ex028_perspective_projections/README.md: -------------------------------------------------------------------------------- 1 | ## Perspective Projections 2 | 3 | In [ex028a](ex028a_solid_scene), we render a scene consisting of objects with solid-color faces to illustrate a perspective rendering setup. 4 | 5 | In [ex028b](ex028b_gradient_scene), we adapt the above to handle a scene consisting of objects with gradient-colored faces. 6 | -------------------------------------------------------------------------------- /lib/io/print_buffer_reset.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_BUFFER_RESET 2 | %define PRINT_BUFFER_RESET 3 | 4 | print_buffer_reset: 5 | ; void print_buffer_reset(void); 6 | ; Clears the PRINT_BUFFER. 7 | 8 | push rax 9 | 10 | xor rax,rax 11 | mov [PRINT_BUFFER_LENGTH],rax ; reset print_buffer_length to 0 12 | 13 | pop rax 14 | 15 | ret ; return 16 | 17 | %endif 18 | -------------------------------------------------------------------------------- /ex/ex014_scatter_plots/README.md: -------------------------------------------------------------------------------- 1 | ## Scatter Plots 2 | 3 | In [ex014a](ex014a_basic_scatter_plot), we generate a basic SVG scatter plot. 4 | 5 | In [ex014b](ex014b_multiple_datasets), we plot 2 sets of data on the same plot. 6 | 7 | In [ex014c](ex014c_evaluating_functions), we plot some evaluated polynomial. 8 | 9 | In [ex014d](ex014d_drawing_pictures), we draw a picture. 10 | -------------------------------------------------------------------------------- /lib/mem/memset.asm: -------------------------------------------------------------------------------- 1 | %ifndef MEMSET 2 | %define MEMSET 3 | 4 | memset: 5 | ; void memset(void* {rdi}, char {sil}, ulong {rdx}); 6 | ; Sets {rdx} bytes starting at address {rdi} to the byte value in {sil}. 7 | 8 | push rdi 9 | push rdx 10 | 11 | .loop: 12 | mov byte [rdi],sil 13 | inc rdi 14 | dec rdx 15 | jnz .loop 16 | 17 | pop rdx 18 | pop rdi 19 | ret 20 | 21 | %endif 22 | -------------------------------------------------------------------------------- /ex/ex012_bitmap_images/README.md: -------------------------------------------------------------------------------- 1 | ## Bitmap Images 2 | 3 | In [ex012a](ex012a_bitmap_basics), we generate a sample bitmap image. 4 | 5 | In [ex012b](ex012b_basic_drawing_operations), we implement and test functions to draw pixels, lines, and circles, as well as algorithms to fill parts of the image and query pixel colors. 6 | 7 | In [ex012c](ex012c_filled_rectangles), we draw a filled rectangle. 8 | -------------------------------------------------------------------------------- /ex/ex013_floating_point_io/README.md: -------------------------------------------------------------------------------- 1 | ## Floating Point IO 2 | 3 | In [ex013a](ex013a_parse_floats), we parse strings into floats. 4 | 5 | In [ex013b](ex013b_parse_floats_csv), we parse strings into floats from a csv file. 6 | 7 | In [ex013c](ex013c_multiple_input_files), we interact with several floating point files. 8 | 9 | In [ex013d](ex013d_writing_to_csv), we write a csv output file. 10 | -------------------------------------------------------------------------------- /lib/math/expressions/trig/sine_x87.asm: -------------------------------------------------------------------------------- 1 | %ifndef SINE_X87 2 | %define SINE_X87 3 | 4 | ; double {xmm0} sine_x87(double {xmm0}); 5 | ; Returns approximation of sine({xmm0}) in {xmm0} using the FPU. 6 | 7 | align 64 8 | sine_x87: 9 | 10 | movsd [.value],xmm0 11 | fld qword [.value] 12 | fsin 13 | fstp qword [.value] 14 | movsd xmm0,[.value] 15 | ret 16 | 17 | .value: 18 | dq 0.0 19 | 20 | %endif 21 | 22 | -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/ex001b_first_asm_program/code.asm: -------------------------------------------------------------------------------- 1 | global _start ; exposes a locally defined _start function 2 | ; to the entire program 3 | 4 | section .text ; section of binary dedicated for instructions 5 | 6 | _start: ; address label representing the entry point 7 | ; for our program 8 | 9 | jmp _start ; jump to label above (execute this instruction 10 | ; again, looping forever) 11 | -------------------------------------------------------------------------------- /lib/math/expressions/trig/cosine_x87.asm: -------------------------------------------------------------------------------- 1 | %ifndef COSINE_X87 2 | %define COSINE_X87 3 | 4 | ; double {xmm0} cosine_x87(double {xmm0}); 5 | ; Returns approximation of cosine({xmm0}) in {xmm0} using the FPU. 6 | 7 | align 64 8 | cosine_x87: 9 | 10 | movsd [.value],xmm0 11 | fld qword [.value] 12 | fcos 13 | fstp qword [.value] 14 | movsd xmm0,[.value] 15 | ret 16 | 17 | .value: 18 | dq 0.0 19 | 20 | %endif 21 | 22 | -------------------------------------------------------------------------------- /lib/io/strlen.asm: -------------------------------------------------------------------------------- 1 | %ifndef STRLEN 2 | %define STRLEN 3 | 4 | strlen: 5 | ; int {rax} strlen(char* {rdi}); 6 | ; Returns in {rax} the length of null-terminated char array starting at 7 | ; {rdi}. 8 | 9 | mov rax,-1 ; set strlen counter to -1 10 | 11 | .loop: 12 | inc rax ; increase the counter by 1 13 | cmp byte [rdi+rax],0 ; check if the byte is null 14 | jne .loop ; if not, try the next one 15 | 16 | ret 17 | 18 | %endif 19 | -------------------------------------------------------------------------------- /lib/math/lin_alg/set_zero.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_ZERO 2 | %define SET_ZERO 3 | 4 | set_zero: 5 | ; void set_zero(double* {rdi}, uint {rsi}); 6 | ; Sets {rsi}x{rsi} matrix at address {rdi} to zeros. 7 | 8 | push rdi 9 | push rsi 10 | push rax 11 | 12 | imul rsi,rsi 13 | xor rax,rax 14 | 15 | .loop: 16 | mov [rdi],rax 17 | add rdi,8 18 | dec rsi 19 | jnz .loop 20 | 21 | pop rax 22 | pop rsi 23 | pop rdi 24 | 25 | ret 26 | 27 | %endif 28 | -------------------------------------------------------------------------------- /ex/ex023_rendering_text/README.md: -------------------------------------------------------------------------------- 1 | ## Rendering Text 2 | 3 | Note: need to run these examples as super user for permissions on the mouse device. 4 | 5 | In [ex023a](ex023a_sample_text), we render a some text to the framebuffer. 6 | 7 | In [ex023b](ex023b_alphabet_screensaver), we channel God through RNG. 8 | 9 | In [ex023c](ex023c_3d_text_annotations), we annotate a 3D model with text. 10 | 11 | In [ex023d](ex023d_simple_gui), a simple sample GUI. 12 | -------------------------------------------------------------------------------- /ex/ex022_3d_graphics/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Graphics 2 | 3 | Note: need to run these examples as super user for permissions on the mouse device. 4 | 5 | In [ex022a](ex022a_cube), we render a cube. Mouse left click and drag to rotate, right click and drag to pan, and middle click and drag to zoom. 6 | 7 | In [ex022b](ex022b_rendering_simplified), we render a cross in a more general way. 8 | 9 | In [ex022c](ex022c_scene), we setup a scene with multiple wireframes to render. 10 | 11 | -------------------------------------------------------------------------------- /ex/ex016_trigonometry/README.md: -------------------------------------------------------------------------------- 1 | ## Trigonometry 2 | 3 | In [ex016a](ex016a_sin_and_cos), we evaluate sine and cosine using a Taylor Series. 4 | 5 | In [ex016b](ex016b_plotting_sin_and_cos), we generate a plot of sine and cosine. 6 | 7 | In [ex016c](ex016c_tan), we evaluate tangent using a partial fraction expansion. 8 | 9 | In [ex016d](ex016d_plotting_tan), we plot the tangent function. 10 | 11 | In [ex016e](ex016e_atan), we evaluate arctangent in two different ways. 12 | 13 | 14 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/ex001b_blink/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp # assemble the code into object file 2 | 3 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 4 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 5 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 6 | 7 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 8 | 9 | rm temp* # remove temporary boomer object file 10 | chmod +x binary # make binary executable 11 | ./binary # execute binary 12 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/ex001c_gpio_read/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp # assemble the code into object file 2 | 3 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 4 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 5 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 6 | 7 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 8 | 9 | rm temp* # remove temporary boomer object file 10 | chmod +x binary # make binary executable 11 | ./binary # execute binary 12 | -------------------------------------------------------------------------------- /aarch64/ex/ex001_the_basics/ex001a_minimal_executable/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp # assemble the code into object file 2 | 3 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 4 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 5 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 6 | 7 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 8 | 9 | rm temp* # remove temporary boomer object file 10 | chmod +x binary # make binary executable 11 | ./binary # execute binary 12 | -------------------------------------------------------------------------------- /ex/ex006_user_input/README.md: -------------------------------------------------------------------------------- 1 | ## User Input 2 | 3 | In [ex006a](ex006a_stdin), we read and parse newline-buffered input from stdin. 4 | 5 | In [ex006b](ex006b_capture_keypresses), we toggle the terminal into raw mode, and handle certain keypresses without newline-buffering. 6 | 7 | In [ex006c](ex006c_game), we implement a game that takes user keypress input and reads from a high-score file. 8 | 9 | In [ex006d](ex006d_piped_stdin), we handle input that is passed into our program via stdin from the command line. 10 | -------------------------------------------------------------------------------- /lib/mem/strcopy.asm: -------------------------------------------------------------------------------- 1 | %ifndef STRCOPY 2 | %define STRCOPY 3 | 4 | strcopy: 5 | ; void strcopy(char* {rdi}, char* {rsi}); 6 | ; copies null-terminated string pointed to by {rsi} to buffer at {rdi} 7 | 8 | push rdi 9 | push rsi 10 | push rdx 11 | 12 | .loop: ; copy 1 byte at a time (slow but simple algorithm) 13 | mov dl,[rsi] 14 | test dl,dl 15 | jz .done 16 | mov [rdi], dl 17 | inc rsi 18 | inc rdi 19 | jmp .loop 20 | 21 | .done: 22 | pop rdx 23 | pop rsi 24 | pop rdi 25 | ret 26 | 27 | %endif 28 | -------------------------------------------------------------------------------- /ex/ex024_3d_graphics_cont/README.md: -------------------------------------------------------------------------------- 1 | ## 3D Graphics (cont.) 2 | 3 | Note: need to run these examples as super user for permissions on the mouse device. 4 | 5 | In [ex024a](ex024a_points), we render a point datatype in 3D. 6 | 7 | In [ex024b](ex024b_sample_triangle), we render a basic colored triangle. 8 | 9 | In [ex024c](ex024c_3d_faces), we render a set of faces in 3D. Can you see the problem 10 | 11 | In [ex024d](ex024d_3d_faces_improved), we render a set of faces in 3D, accounting for distance from the viewer. 12 | 13 | -------------------------------------------------------------------------------- /lib/io/file_close.asm: -------------------------------------------------------------------------------- 1 | %ifndef FILE_CLOSE 2 | %define FILE_CLOSE 3 | 4 | file_close: 5 | ; int {rax} file_close(int {rdi}); 6 | ; Closes file with file descriptor {rdi}. Returns 0/-1 in {rax} on 7 | ; success/fail. 8 | 9 | ; save clobbered registers 10 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 11 | 12 | mov rax,SYS_CLOSE ; set {rax} to close syscall 13 | syscall ; execute close syscall 14 | 15 | ; restore clobbered registers 16 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 17 | 18 | ret ; return 19 | 20 | %endif 21 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002b_cat/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp -I ../../../lib # assemble the code into object file 2 | 3 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 4 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 5 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 6 | 7 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 8 | 9 | rm temp* # remove temporary boomer object file 10 | chmod +x binary # make binary executable 11 | ./binary # execute binary 12 | -------------------------------------------------------------------------------- /ex/ex010_matrix_basics/README.md: -------------------------------------------------------------------------------- 1 | ## Matrix Basics 2 | 3 | In [ex010a](ex010a_creating_matrices), we explore some different ways to populate matrices. 4 | 5 | In [ex010b](ex010b_manipulating_matrices), we explore some different ways to manipulate matrices (inserting/extracting rows/columns, transpose, etc). 6 | 7 | In [ex010c](ex010c_basic_matrix_arithmetic), we implement some basic matrix math operations (add, subtract, scale, multiply, etc). 8 | 9 | In [ex010d](ex010d_multiplying_non_square_matrices), we do a little multiplication. 10 | -------------------------------------------------------------------------------- /lib/time/tick_cycles.asm: -------------------------------------------------------------------------------- 1 | %ifndef TICK_CYCLES 2 | %define TICK_CYCLES 3 | 4 | tick_cycles: 5 | ; uint {rax} tick_cycles(void); 6 | ; Returns timestamp counter value in {rax} and saves it at 7 | ; [tick_cycles.tick]. 8 | 9 | push rdx 10 | 11 | lfence ; force all instructions to finish 12 | rdtsc ; read timestamp counter into {edx}:{eax} 13 | shl rdx,32 14 | or rax,rdx ; slide {edx} into high part of {rax} 15 | 16 | mov [tick_cycles.tick],rax 17 | 18 | pop rdx 19 | 20 | ret 21 | 22 | .tick: 23 | dq 0 24 | 25 | %endif 26 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002a_debug_log_demo/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp -I ../../../lib # assemble the code into object file 2 | 3 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 4 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 5 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 6 | 7 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 8 | 9 | rm temp* # remove temporary boomer object file 10 | chmod +x binary # make binary executable 11 | ./binary # execute binary 12 | -------------------------------------------------------------------------------- /lib/io/file_delete.asm: -------------------------------------------------------------------------------- 1 | %ifndef FILE_DELETE 2 | %define FILE_DELETE 3 | 4 | file_delete: 5 | ; int {rax} file_delete(char* {rdi}); 6 | ; Unlinks (deletes) file at path in char array at {rdi}. Returns 0/-1 in 7 | ; {rax} on success/fail. 8 | 9 | ; save clobbered registers 10 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 11 | 12 | mov rax,SYS_UNLINK ; set {rax} to unlink syscall 13 | syscall ; execute unlink syscall 14 | 15 | ; restore clobbered registers 16 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 17 | 18 | ret ; return 19 | 20 | %endif 21 | -------------------------------------------------------------------------------- /ex/ex020_framebuffer/README.md: -------------------------------------------------------------------------------- 1 | ## Framebuffer 2 | 3 | In [ex020a](ex020a_framebuffer_ioctl), we query the framebuffer size. 4 | 5 | In [ex020b](ex020b_framebuffer_basics), we manually render a simple graphic to the screen using the framebuffer device. 6 | 7 | In [ex020c](ex020c_framebuffer_clear), we use function calls to render a cleared screen. 8 | 9 | In [ex020d](ex020d_epilepsy_warning), we induce seizures. 10 | 11 | In [ex020e](ex020e_flags), we make a flag screensaver. 12 | 13 | In [ex020f](ex020f_3d_cube), we render a 3D spinning cube. 14 | -------------------------------------------------------------------------------- /ex/ex011_memory_allocation/README.md: -------------------------------------------------------------------------------- 1 | ## Memory Allocation 2 | 3 | In [ex011a](ex011a_alloc_and_free), we allocate and free a chunk of memory, and we evaluate the impact we had on the heap. 4 | 5 | In [ex011b](ex011b_multiple_alloc_and_free), we allocate and free several chunks of memory, and we evaluate the impact we had on the heap. 6 | 7 | In [ex011c](ex011c_linked_list), we implement a very simple linked-list structure using our DIY heap. 8 | 9 | In [ex011d](ex011d_checking_for_leaks), we investigate the status of our heap, checking for potential leaks. 10 | -------------------------------------------------------------------------------- /ex/ex018_LU_decomposition/README.md: -------------------------------------------------------------------------------- 1 | ## LU Decomposition 2 | 3 | In [ex018a](ex018a_matrix_types), we check for upper triangular, lower triangular, and diagonal matrices. 4 | 5 | In [ex018b](ex018b_lu_step_by_step), we implement each step of an LU decomposition to solve a linear system. 6 | 7 | In [ex018c](ex018c_lu_solve), we implement a function to automatically solve a linear system with LU decomposition. 8 | 9 | In [ex018d](ex018d_plu_decomposition), we implement a function to automatically solve a linear system with permuted/pivotted LU decomposition. 10 | -------------------------------------------------------------------------------- /lib/io/bitmap/get_pixel.asm: -------------------------------------------------------------------------------- 1 | %ifndef GET_PIXEL 2 | %define GET_PIXEL 3 | 4 | get_pixel: 5 | ; int {eax} get_pixel(void* {rdi}, int {esi}, int {edx}, int {ecx}, int {r8d}); 6 | ; Gets pixel value at ({ecx},{r8d}) (from (0,0) @ top-left) in ARGB data 7 | ; array starting at {rdi} for an {esi}x{edx} (WxH) image and returns the 8 | ; value in {eax}. 9 | 10 | push rdx 11 | 12 | sub rdx,r8 13 | dec rdx 14 | imul rdx,rsi 15 | add rdx,rcx 16 | shl rdx,2 ; offset to pixel address 17 | 18 | mov eax, dword [rdi+rdx] 19 | 20 | pop rdx 21 | 22 | ret ; return 23 | 24 | %endif 25 | -------------------------------------------------------------------------------- /lib/io/file_open.asm: -------------------------------------------------------------------------------- 1 | %ifndef FILE_OPEN 2 | %define FILE_OPEN 3 | 4 | file_open: 5 | ; int {rax} file_open(char* {rdi}, int {rsi}, int {rdx}); 6 | ; Opens file in path {rdi} with {rsi} flags and permissions {rdx} 7 | ; Returns file descriptor in {rax} on success, -1 on fail. 8 | 9 | ; save clobbered registers 10 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 11 | 12 | mov rax,SYS_OPEN ; set {rax} to open syscall 13 | syscall ; execute open syscall 14 | 15 | ; restore clobbered registers 16 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 17 | 18 | ret ; return 19 | 20 | %endif 21 | -------------------------------------------------------------------------------- /lib/mem/find_byte_offset.asm: -------------------------------------------------------------------------------- 1 | %ifndef FIND_BYTE_OFFSET 2 | %define FIND_BYTE_OFFSET 3 | 4 | find_byte_offset: 5 | ; int {rax} find_byte_offset(void* {rdi}, char {sil}, uint {rdx}); 6 | ; Searches {rdx} bytes of memory starting at address {rdi} for the 7 | ; byte in {sil}. If found, returns the offset to this byte in memory 8 | ; in {rax}. Otherwise, returns -1 in {rax}. 9 | 10 | push rdx 11 | xor rax,rax 12 | .loop: 13 | cmp byte [rdi+rax],sil 14 | je .done 15 | inc rax 16 | dec rdx 17 | jnz .loop 18 | mov rax,-1 19 | .done: 20 | pop rdx 21 | ret 22 | 23 | %endif 24 | -------------------------------------------------------------------------------- /lib/mem/strcopy_null.asm: -------------------------------------------------------------------------------- 1 | %ifndef STRCOPY_NULL 2 | %define STRCOPY_NULL 3 | 4 | strcopy_null: 5 | ; void strcopy_null(char* {rdi}, char* {rsi}); 6 | ; Copies null-terminated string pointed to by {rsi} to buffer at {rdi}, 7 | ; followed by a null-byte. 8 | 9 | push rdi 10 | push rsi 11 | push rdx 12 | 13 | .loop: ; copy 1 byte at a time (slow but simple algorithm) 14 | mov dl,[rsi] 15 | test dl,dl 16 | jz .done 17 | mov [rdi],dl 18 | inc rsi 19 | inc rdi 20 | jmp .loop 21 | 22 | .done: 23 | mov [rdi],dl 24 | pop rdx 25 | pop rsi 26 | pop rdi 27 | ret 28 | 29 | %endif 30 | -------------------------------------------------------------------------------- /lib/mem/strsplit.asm: -------------------------------------------------------------------------------- 1 | %ifndef STRSPLIT 2 | %define STRSPLIT 3 | 4 | strsplit: 5 | ; void strsplit(char* {rdi}, char* {rsi}, char {dl}); 6 | ; Copies string (terminated by splitting character in {dl} 7 | ; pointed to by {rsi} to buffer at {rdi}. 8 | 9 | push rdi 10 | push rsi 11 | push rax 12 | 13 | .loop: ; copy 1 byte at a time (slow but simple algorithm) 14 | mov al,[rsi] 15 | cmp al,dl 16 | je .done 17 | cmp al,0 18 | je .done 19 | mov [rdi], al 20 | inc rsi 21 | inc rdi 22 | jmp .loop 23 | 24 | .done: 25 | pop rax 26 | pop rsi 27 | pop rdi 28 | ret 29 | 30 | %endif 31 | -------------------------------------------------------------------------------- /ex/ex001_minimal_executable/README.md: -------------------------------------------------------------------------------- 1 | ## Creating a Minimal Executable 2 | 3 | In these examples we will explore a minimal executable created in various ways. 4 | 5 | In [ex001a](ex001a_c_equivalent), we write a C program that loops infinitely. This is compiled (and linked) using a C compiler. 6 | 7 | In [ex001b](ex001b_first_asm_program), we write the same functionality into a minimal assembly source file. This is assembled using NASM and linked using a linker (ld). 8 | 9 | In [ex001c](ex001c_minimal_elf), we eschew the linker and generate the minimal ELF executable binary directly in NASM. 10 | -------------------------------------------------------------------------------- /ex/ex021_mouse_input/README.md: -------------------------------------------------------------------------------- 1 | ## Mouse Input 2 | 3 | Note: need to run these examples as super user for permissions on the mouse device. 4 | 5 | In [ex021a](ex021a_read_mouse_device), we parse raw data from the mouse device. 6 | 7 | In [ex021b](ex021b_mouse_status), we implement and access a data structure to track mouse status (and draw a basic cursor to the screen). 8 | 9 | In [ex021c](ex021c_mouse_cursor), we go thru the process of drawing a cursor on top of a screen (and tracking mouse input to draw lines). 10 | 11 | In [ex021d](ex021d_rotate_3d_cube), we grab mouse input to rotate a 3D cube. 12 | -------------------------------------------------------------------------------- /lib/sys/chmod.asm: -------------------------------------------------------------------------------- 1 | %ifndef CHMOD 2 | %define CHMOD 3 | 4 | chmod: 5 | ; int {rax} chmod(char* {rdi}, long {rsi}); 6 | ; Sets permissions of file with path indicated by null-terminated char 7 | ; array at address in {rdi} to the value in the low 9 bits of {rsi}. 8 | ; Returns 0/-1 in {rax} on success/fail. 9 | 10 | ; save clobbered registers 11 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 12 | 13 | mov rax,SYS_CHMOD ; set {rax} to chmod syscall 14 | syscall ; execute chmod syscall 15 | 16 | ; restore clobbered registers 17 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 18 | 19 | ret 20 | 21 | %endif 22 | -------------------------------------------------------------------------------- /lib/io/read_chars.asm: -------------------------------------------------------------------------------- 1 | %ifndef READ_CHARS 2 | %define READ_CHARS 3 | 4 | read_chars: 5 | ; int {rax} read_chars(int {rdi}, char* {rsi}, int {rdx}); 6 | ; Reads {rdx} chars from file descriptor {rdi} into buffer at {rsi}. 7 | ; Returns number of bytes read in {rax}, 0 indicates end of file, 8 | ; and -1 indicates error. 9 | 10 | ; save clobbered registers 11 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 12 | 13 | mov rax,SYS_READ ; set {rax} to read syscall 14 | syscall ; execute read syscall 15 | 16 | ; restore clobbered registers 17 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 18 | 19 | ret ; return 20 | 21 | %endif 22 | -------------------------------------------------------------------------------- /lib/time/tock_cycles.asm: -------------------------------------------------------------------------------- 1 | %ifndef TOCK_CYCLES 2 | %define TOCK_CYCLES 3 | 4 | ; dependency 5 | %include "lib/time/tick_cycles.asm" 6 | 7 | tock_cycles: 8 | ; uint {rax} tock_cycles(void); 9 | ; Returns difference between current and saved timestamp counter value 10 | ; at [tick_cycles.tick] in {rax}. 11 | 12 | push rdx 13 | 14 | lfence ; force all instructions to finish 15 | rdtsc ; read timestamp counter into {edx}:{eax} 16 | shl rdx,32 17 | or rax,rdx ; slide {edx} into high part of {rax} 18 | 19 | sub rax,[tick_cycles.tick] ; subtract off saved value 20 | 21 | pop rdx 22 | 23 | ret 24 | 25 | %endif 26 | -------------------------------------------------------------------------------- /ex/ex002_syscalls_and_functions/README.md: -------------------------------------------------------------------------------- 1 | ## Syscalls 2 | 3 | In [ex002a](ex002a_terminating_executables), we terminate an executable for the first time, returning a value. Use `echo $?` to see the returned value, after program execution. 4 | 5 | In [ex002b](ex002b_exiting_via_function), we repeat the above, but using a function call. Use `echo $?` to see the returned value, after program execution. 6 | 7 | In [ex002c](ex002c_vector_sum), we compute the sum of elements of a vector, as an example involving a few other common x86-64 asm instructions and NASM syntax elements. Use `echo $?` to see the returned value, after program execution. 8 | -------------------------------------------------------------------------------- /lib/math/lin_alg/set_identity.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_IDENTITY 2 | %define SET_IDENTITY 3 | 4 | %include "lib/math/lin_alg/set_zero.asm" 5 | 6 | set_identity: 7 | ; void set_identity(double* {rdi}, uint {rsi}); 8 | ; Sets {rsi}x{rsi} matrix at address {rdi} to identity. 9 | 10 | call set_zero 11 | 12 | push rdi 13 | push rsi 14 | push rax 15 | push rcx 16 | 17 | mov rcx,rsi 18 | shl rsi,3 19 | add rsi,8 20 | mov rax,[.one] 21 | 22 | .loop: 23 | mov [rdi],rax 24 | add rdi,rsi 25 | dec rcx 26 | jnz .loop 27 | 28 | pop rcx 29 | pop rax 30 | pop rsi 31 | pop rdi 32 | 33 | ret 34 | 35 | .one: 36 | dq 1.0 37 | 38 | %endif 39 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_set_all_values.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SET_ALL_VALUES 2 | %define MATRIX_SET_ALL_VALUES 3 | 4 | matrix_set_all_values: 5 | ; void matrix_set_all_values(double* {rdi}, uint {rsi}, double {xmm0}); 6 | ; Sets {rsi} elements of the double-precision floating point 7 | ; matrix beginning at {rdi} to the low 8-byte double in {xmm0}. 8 | 9 | push rdi 10 | push rsi 11 | 12 | .loop: ; loop over {rsi} elements 13 | movsd [rdi],xmm0 ; set one value at a time (should be improved) 14 | add rdi,8 15 | dec rsi 16 | jnz .loop ; loop until finished 17 | 18 | pop rsi 19 | pop rdi 20 | 21 | ret ; return 22 | 23 | %endif 24 | -------------------------------------------------------------------------------- /lib/io/print_ascii.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_ASCII 2 | %define PRINT_ASCII 3 | 4 | print_ascii: 5 | ; void print_ascii(int {rdi}, char {sil}); 6 | ; Writes (non-buffered) the single byte in {sil} to file descriptor {rdi}. 7 | 8 | ; save clobbered registers 9 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 10 | push rsi 11 | push rdx 12 | 13 | mov byte [.character],sil 14 | mov rsi,.character 15 | mov dl,1 16 | mov al,SYS_WRITE 17 | syscall 18 | 19 | ; restore clobbered registers 20 | pop rdx 21 | pop rsi 22 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 23 | 24 | ret 25 | 26 | .character: ; memory slot for byte to print 27 | db 0 28 | 29 | %endif 30 | -------------------------------------------------------------------------------- /lib/io/strcmp.asm: -------------------------------------------------------------------------------- 1 | %ifndef STRCMP 2 | %define STRCMP 3 | 4 | strcmp: 5 | ; bool {rax} strcmp(char* {rdi}, char* {rsi}); 6 | ; Compares 2 null-terminated strings and returns 1 if they're equal. 7 | 8 | push rdi 9 | push rsi 10 | 11 | ; precheck for nafnaf case 12 | mov al,byte [rdi] 13 | or al,byte [rsi] 14 | jz .success 15 | 16 | .loop: 17 | mov al,byte [rdi] 18 | cmp byte [rsi],al 19 | jne .fail 20 | or al,byte [rsi] 21 | jz .success 22 | inc rdi 23 | inc rsi 24 | jmp .loop 25 | 26 | .fail: 27 | xor rax,rax 28 | jmp .exit 29 | .success: 30 | mov rax,1 31 | .exit: 32 | pop rsi 33 | pop rdi 34 | 35 | ret 36 | 37 | %endif 38 | -------------------------------------------------------------------------------- /ex/ex005_printing_integers/README.md: -------------------------------------------------------------------------------- 1 | ## Printing Integers 2 | 3 | In [ex005a](ex005a_printing_ints), we implement a variety of print functions to handle binary, hexadecimal, and decimal integers. 4 | 5 | In [ex005b](ex005b_printing_registers), we implement a debugging tool to dump register values in binary, octal, hexadecimal, and decimal (very cool btw). 6 | 7 | In [ex005c](ex005c_printing_int_arrays), we implement a debugging tool to dump 2D quadword arrays in binary, octal, hexadecimal, and decimal. 8 | 9 | In [ex005d](ex005d_dumping_memory), we implement a debugging tool to dump the stack and memory in binary, octal, hexadecimal, and decimal. 10 | -------------------------------------------------------------------------------- /lib/io/print_fraction.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_FRACTION 2 | %define PRINT_FRACTION 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_int_d.asm" 7 | 8 | print_fraction: 9 | ; void print_fraction(int {rdi}, int {rsi}, int {rdx}); 10 | ; Prints "{rsi}/{rdx}" to file descriptor {rdi}. 11 | 12 | push rsi 13 | push rdx 14 | 15 | ; print numerator 16 | call print_int_d 17 | 18 | ; print "/" 19 | mov rsi,.grammar 20 | mov rdx,1 21 | call print_chars 22 | 23 | ; print denominator 24 | mov rsi,[rsp+0] 25 | call print_int_d 26 | 27 | pop rdx 28 | pop rsi 29 | 30 | ret ; return 31 | 32 | .grammar: 33 | db `/` 34 | 35 | %endif 36 | -------------------------------------------------------------------------------- /lib/io/framebuffer/framebuffer_clear.asm: -------------------------------------------------------------------------------- 1 | %ifndef FRAMEBUFFER_CLEAR 2 | %define FRAMEBUFFER_CLEAR 3 | 4 | %include "lib/io/framebuffer/framebuffer_init.asm" 5 | 6 | framebuffer_clear: 7 | ; void framebuffer_clear(uint {rdi}); 8 | ; Sets the entire frame to the 32-bit ARGB color defined in {rdi}. 9 | 10 | push rsi 11 | push rcx 12 | 13 | ; loop thru all pixels in framebuffer and set color 14 | mov rcx,[framebuffer_init.framebuffer_size] 15 | shr rcx,2 16 | mov rsi,[framebuffer_init.framebuffer_address] 17 | 18 | .loop: 19 | mov dword [rsi],edi 20 | add rsi,4 21 | dec rcx 22 | jnz .loop 23 | 24 | .end: 25 | pop rcx 26 | pop rsi 27 | 28 | ret 29 | 30 | %endif 31 | -------------------------------------------------------------------------------- /lib/sort/bubble_sort.asm: -------------------------------------------------------------------------------- 1 | %ifndef BUBBLE SORT 2 | %define BUBBLE_SORT 3 | 4 | bubble_sort: 5 | ; void bubble_sort(void* {rdi}, uint {rsi}); 6 | ; Sorts {rsi} elements at {rdi} in ascending order. 7 | 8 | cmp rsi,1 9 | jle .ret 10 | 11 | push rdi 12 | push rax 13 | push rcx 14 | 15 | xor rcx,rcx 16 | .loop: 17 | mov rax,[rdi] 18 | cmp rax,[rdi+8] 19 | jle .no_swap 20 | .swap: 21 | push [rdi+8] 22 | mov [rdi+8],rax 23 | pop [rdi] 24 | cmp rcx,0 25 | je .no_swap 26 | dec rcx 27 | jmp .check_loop 28 | .no_swap: 29 | inc rcx 30 | .check_loop: 31 | cmp rcx,rsi 32 | jb .loop 33 | 34 | pop rcx 35 | pop rax 36 | pop rdi 37 | .ret: 38 | ret 39 | 40 | %endif 41 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/README.md: -------------------------------------------------------------------------------- 1 | ## macros and instrumentation 2 | 3 | In [ex002a](ex002a_debug_log_demo), we demonstrate the basic debug logging process. 4 | 5 | In [ex002b](ex002b_cat), we implement a basic `cat` executable with reduced functionality. 6 | 7 | In [ex002c](ex002c_extract_bin), we eschew the clumsy and unportable `xxd` process for stripping the useful parts out of our boomer GNU-assembled object file by creating one ourselves. 8 | 9 | In [ex002d](ex002d_extract_bin_macroless), we redo the previous without the bloated macros, to save space. 10 | 11 | In [ex002e](ex002e_extract_bin_functionless), we redo the previous without trivial function calls. 12 | -------------------------------------------------------------------------------- /find_segfault.sh: -------------------------------------------------------------------------------- 1 | N=$(sudo dmesg | grep -E segfault | tail -1 | awk '{for(i=1;i<=NF;i++) if ($i=="ip") print $(i+1)}') 2 | 3 | next_addr=0; 4 | next_label=0; 5 | 6 | tail -n +34 "mem.map" | while read line; 7 | do 8 | prev_addr=$next_addr 9 | prev_label=$next_label 10 | next_addr=`echo $line | cut -f2 -d' '` 11 | next_label=`echo $line | cut -f3 -d' '` 12 | if [[ "0x$next_addr" -eq "0x$N" ]]; then 13 | printf "\ncringe @ address 0x$N\n\twhich is @ $next_label\n\n" 14 | break 15 | elif [[ "0x$next_addr" -ge "0x$N" ]]; then 16 | printf "\ncringe @ address 0x$N\n\twhich is between 0x$prev_addr ($prev_label)\n\tand 0x$next_addr ($next_label)\n\n" 17 | break 18 | fi 19 | done 20 | 21 | 22 | -------------------------------------------------------------------------------- /ex/ex004_printing_strings/README.md: -------------------------------------------------------------------------------- 1 | ## Printing Strings 2 | 3 | In [ex004a](ex004a_c_equivalent), we see how C's printf buffers output (check the numbers of syscalls with 'strace -c ./binary' on Linux or 'truss -c ./binary' on FreeBSD). 4 | 5 | In [ex004b](ex004b_writing_to_stdout), we use a syscall to write something to stdout in assembly. Check the number of syscalls to do it this way. Not a good solution. 6 | 7 | In [ex004c](ex004c_buffered_writes), we implement functions for buffered writes. Check the number of syscalls to do it this way. Now we can match the C implementation. 8 | 9 | In [ex004d](ex004d_nyancat), we implement an alternative to "cat". Worse in every way (except filesize and understandability). 10 | -------------------------------------------------------------------------------- /lib/io/print_string.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_STRING 2 | %define PRINT_STRING 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_string: 8 | ; void print_string(int {rdi}, char* {rsi}); 9 | ; Writes null-terminated char array starting at {rsi} to file 10 | ; descriptor {rdi}. 11 | 12 | push rdx ; save register 13 | 14 | ; calculate the length of the null-terminated string 15 | mov rdx,-1 ; set strlen counter to -1 16 | .print_string_loop: 17 | inc rdx ; increase the counter by 1 18 | cmp byte [rsi+rdx],0 ; check if the byte is null 19 | jne .print_string_loop ; if not, try the next one 20 | 21 | call print_chars 22 | 23 | pop rdx ; restore register 24 | 25 | ret 26 | 27 | %endif 28 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002c_extract_bin/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp -I ../../../lib # assemble the code into object file 2 | #as code.asm -o temp -I ../../../lib --defsym VERBOSE_LOGS=1 # assemble but verbose 3 | 4 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 5 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 6 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 7 | 8 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 9 | 10 | #rm temp* # remove temporary boomer object file 11 | chmod +x binary # make binary executable 12 | 13 | ./binary temp binary_extractor # use the binary extractor to create the binary extractor (wow epic) 14 | 15 | #rm binary 16 | 17 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002d_extract_bin_macroless/run.sh: -------------------------------------------------------------------------------- 1 | as code.asm -o temp -I ../../../lib # assemble the code into object file 2 | #as code.asm -o temp -I ../../../lib --defsym VERBOSE_LOGS=1 # assemble but verbose 3 | 4 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 5 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 6 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 7 | 8 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 9 | 10 | #rm temp* # remove temporary boomer object file 11 | chmod +x binary # make binary executable 12 | 13 | ./binary temp binary_extractor # use the binary extractor to create the binary extractor (wow epic) 14 | 15 | rm binary 16 | -------------------------------------------------------------------------------- /aarch64/ex/ex002_macros_and_instrumentation/ex002e_extract_bin_functionless/run.sh: -------------------------------------------------------------------------------- 1 | #as code.asm -o temp -I ../../../lib # assemble the code into object file 2 | as code.asm -o temp -I ../../../lib --defsym VERBOSE_LOGS=1 # assemble but verbose 3 | 4 | bytes=$(xxd -p -l8 -g4 -s 160 -e temp) 5 | bytes_trimmed="${bytes:19:8}${bytes:10:8}" 6 | bytes_to_end=$((16#${bytes_trimmed}+120)) # extract code size from binary 7 | 8 | xxd -p -s 64 -l "$bytes_to_end" temp | xxd -r -p > binary # cut off the boomer-bytes 9 | 10 | #rm temp* # remove temporary boomer object file 11 | chmod +x binary # make binary executable 12 | 13 | ./binary temp binary_extractor # use the binary extractor to create the binary extractor (wow epic) 14 | 15 | rm binary temp 16 | -------------------------------------------------------------------------------- /lib/time/tick_time.asm: -------------------------------------------------------------------------------- 1 | %ifndef TICK_TIME 2 | %define TICK_TIME 3 | 4 | tick_time: 5 | ; uint {rax} tick_time(void); 6 | ; Returns timestamp (microseconds) in {rax} and saves it at 7 | ; [tick_time.tick]. 8 | 9 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 10 | push rdi 11 | push rsi 12 | 13 | ; syscall for current timestamp 14 | mov rax,SYS_GETTIMEOFDAY 15 | mov rdi,tick_time.tick 16 | xor rsi,rsi 17 | syscall 18 | 19 | ; get current timestamp_microseconds in {rax} 20 | mov rax,[tick_time.tick] 21 | mov rdi,1000000 22 | imul rax,rdi 23 | add rax,[tick_time.tick+8] 24 | 25 | pop rsi 26 | pop rdi 27 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 28 | 29 | ret 30 | 31 | .tick: 32 | dq 0 ; seconds 33 | dq 0 ; microseconds 34 | 35 | %endif 36 | -------------------------------------------------------------------------------- /lib/mem/heap_eval.asm: -------------------------------------------------------------------------------- 1 | %ifndef HEAP_EVAL 2 | %define HEAP_EVAL 3 | 4 | heap_eval: 5 | ; ulong {rax}, ulong {rdx} heap_eval(void); 6 | ; Returns number of allocated bytes on heap in {rax} and number of 7 | ; allocated chunks in {rdx}. 8 | 9 | push rdi 10 | push rsi 11 | 12 | xor rax,rax ; zero counter for allocated bytes 13 | xor rdx,rdx ; zero counter for allocated chunks 14 | 15 | mov rdi,HEAP_START_ADDRESS ; start at beginning of heap 16 | 17 | .loop: 18 | mov rsi,[rdi] 19 | test rsi,1 20 | jz .unallocated 21 | dec rsi 22 | add rax,rsi 23 | inc rdx 24 | .unallocated: 25 | add rdi,rsi 26 | add rdi,16 27 | cmp rdi,(HEAP_START_ADDRESS+HEAP_SIZE) 28 | jl .loop 29 | 30 | pop rsi 31 | pop rdi 32 | 33 | ret ; leave 34 | 35 | %endif 36 | -------------------------------------------------------------------------------- /lib/io/ansi_move_cursor.asm: -------------------------------------------------------------------------------- 1 | %ifndef ANSI_MOVE_CURSOR 2 | %define ANSI_MOVE_CURSOR 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_int_d.asm" 7 | 8 | ansi_move_cursor: 9 | ; void ansi_move_cursor(int {rdi}, int {rsi}, int {rdx}); 10 | ; Moves cursor to position ({rsi},{rdx}) in file descriptor {rdi}. 11 | 12 | push rsi 13 | push rdx 14 | 15 | mov rsi,.code 16 | mov rdx,2 17 | call print_chars 18 | 19 | mov rsi,[rsp] 20 | call print_int_d 21 | 22 | mov rsi,.code+2 23 | mov rdx,1 24 | call print_chars 25 | 26 | mov rsi,[rsp+8] 27 | call print_int_d 28 | 29 | mov rsi,.code+3 30 | mov rdx,1 31 | call print_chars 32 | 33 | pop rdx 34 | pop rsi 35 | 36 | ret 37 | 38 | .code: 39 | db `\e[;H` 40 | 41 | %endif 42 | -------------------------------------------------------------------------------- /lib/mem/heap_init.asm: -------------------------------------------------------------------------------- 1 | %ifndef HEAP_INIT 2 | %define HEAP_INIT 3 | 4 | heap_init: 5 | ; void heap_init(void); 6 | ; Initializes a heap of HEAP_SIZE at HEAP_START_ADDRESS (values set for 7 | ; the preprocessor). HEAP_SIZE should be a multiple of 16. 8 | 9 | cmp byte [.heap_initialized],0 10 | jne .ret 11 | 12 | push rdi 13 | 14 | ; set header long 15 | mov rdi,(HEAP_SIZE-16) ; take 8 bytes for each the header and footer 16 | mov [HEAP_START_ADDRESS],rdi ; set header long 17 | 18 | ; set footer long 19 | add rdi,2 ; 2nd bit set to 1 to indicate footer 20 | mov [HEAP_START_ADDRESS+HEAP_SIZE-8],rdi ; set footer long 21 | 22 | mov dil,1 23 | mov byte [.heap_initialized],dil 24 | 25 | pop rdi 26 | .ret: 27 | ret 28 | 29 | .heap_initialized: 30 | db 0 31 | 32 | %endif 33 | -------------------------------------------------------------------------------- /lib/io/print_buffer_flush_to_memory.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_BUFFER_FLUSH_TO_MEMORY 2 | %define PRINT_BUFFER_FLUSH_TO_MEMORY 3 | 4 | %include "lib/mem/memcopy.asm" 5 | %include "lib/io/print_buffer_reset.asm" 6 | 7 | print_buffer_flush_to_memory: 8 | ; void print_buffer_flush_to_memory(void* {rdi}); 9 | ; Flushes the PRINT_BUFFER to memory address {rdi}. 10 | 11 | ; save clobbered registers 12 | push rsi 13 | push rdx 14 | 15 | mov rsi,PRINT_BUFFER ; save address of first character in {rsi} 16 | mov rdx,[PRINT_BUFFER_LENGTH] ; set {rdx} to number of bytes in buffer 17 | call memcopy ; copy print buffer to target 18 | 19 | call print_buffer_reset ; reset print buffer 20 | 21 | ; restore clobbered registers 22 | pop rdx 23 | pop rsi 24 | 25 | ret ; return 26 | 27 | %endif 28 | -------------------------------------------------------------------------------- /lib/math/int/max_int.asm: -------------------------------------------------------------------------------- 1 | %ifndef MAX_INT 2 | %define MAX_INT 3 | 4 | max_int: 5 | ; long {rax}, ulong {rdx} max_int(ulong {rdi}, long* {rsi}, long {rdx}); 6 | ; Identifies max of {rdi} signed longs starting at {rsi}. 7 | ; Additional offset between elements in {rdx}. 8 | ; Returns max in {rax} and first index of max in {rdx}. 9 | 10 | push rdi 11 | push rsi 12 | push rcx 13 | push r8 14 | 15 | mov r8,rdx 16 | mov rax,[rsi] 17 | xor rcx,rcx 18 | xor rdx,rdx 19 | cmp rdi,1 20 | jbe .done 21 | 22 | .loop: 23 | dec rdi 24 | jz .done 25 | add rsi,8 26 | add rsi,r8 27 | inc rcx 28 | cmp rax,[rsi] 29 | jle .loop 30 | mov rax,[rsi] 31 | mov rdx,rcx 32 | jmp .loop 33 | 34 | .done: 35 | pop r8 36 | pop rcx 37 | pop rsi 38 | pop rdi 39 | ret ; return 40 | 41 | %endif 42 | -------------------------------------------------------------------------------- /lib/math/int/min_int.asm: -------------------------------------------------------------------------------- 1 | %ifndef MIN_INT 2 | %define MIN_INT 3 | 4 | min_int: 5 | ; long {rax}, ulong {rdx} max_int(ulong {rdi}, long* {rsi}, long {rdx}); 6 | ; Identifies min of {rdi} signed longs starting at {rsi}. 7 | ; Additional offset between elements in {rdx}. 8 | ; Returns min in {rax} and first index of min in {rdx}. 9 | 10 | push rdi 11 | push rsi 12 | push rcx 13 | push r8 14 | 15 | mov r8,rdx 16 | mov rax,[rsi] 17 | xor rcx,rcx 18 | xor rdx,rdx 19 | cmp rdi,1 20 | jbe .done 21 | 22 | .loop: 23 | dec rdi 24 | jz .done 25 | add rsi,8 26 | add rsi,r8 27 | inc rcx 28 | cmp rax,[rsi] 29 | jge .loop 30 | mov rax,[rsi] 31 | mov rdx,rcx 32 | jmp .loop 33 | 34 | .done: 35 | pop r8 36 | pop rcx 37 | pop rsi 38 | pop rdi 39 | ret ; return 40 | 41 | %endif 42 | -------------------------------------------------------------------------------- /lib/math/int/packed_sum.asm: -------------------------------------------------------------------------------- 1 | %ifndef PACKED_SUM 2 | %define PACKED_SUM 3 | 4 | packed_sum: 5 | ; long {rax} packed_sum(long {rdi}, long* {rsi}); 6 | ; computes the sum of {rdi} packed signed longs starting at {rsi} 7 | 8 | push rdi ; save registers 9 | push rsi 10 | 11 | xor rax,rax ; init running sum to zero 12 | cmp rdi,1 ; check for at least 1 number to add 13 | jb .done ; if less than 1 number, don't bother 14 | 15 | .loop: 16 | add rax,[rsi] ; add the value at the address in {rsi} to running sum 17 | add rsi,8 ; move the {rsi} pointer ahead by 8 bytes 18 | dec rdi ; decrement {rdi} to track the number of numbers left 19 | jnz .loop ; if {rdi} is not yet zero, repeat the loop 20 | 21 | .done: 22 | pop rsi ; restore registers 23 | pop rdi 24 | ret ; return 25 | 26 | %endif 27 | -------------------------------------------------------------------------------- /ex/ex008_randomness/README.md: -------------------------------------------------------------------------------- 1 | ## Randomness 2 | 3 | In [ex008a](ex008a_random_int), we generate a random integer using the `rdrand` instruction. 4 | 5 | In [ex008b](ex008b_random_int_array), we generate an array of random integers. 6 | 7 | In [ex008c](ex008c_random_float), we generate a random float using the `rdrand` instruction. 8 | 9 | In [ex008d](ex008d_random_float_array), we generate an array of random floats. 10 | 11 | In [ex008e](ex008e_deal_or_no_deal), we recreate the game show "Deal or No Deal" using random integers. 12 | 13 | In [ex008f](ex008f_cpu_support_and_getrandom_syscall), we use the `cpuid` instruction to test for cpu support of the `rdrand` and `rdseed` instructions. We also implement an alternative using the `GETRANDOM` syscall, although it is nonstandard on FreeBSD. 14 | 15 | -------------------------------------------------------------------------------- /lib/math/lin_alg/swap_matrix_rows.asm: -------------------------------------------------------------------------------- 1 | %ifndef SWAP_MATRIX_ROWS 2 | %define SWAP_MATRIX_ROWS 3 | 4 | swap_matrix_rows: 5 | ; void swap_matrix_rows(double* {rdi}, double* {rsi}, uint {rdx}); 6 | ; Swaps {rdx} double elements starting at {rsi} with those at {rdi}. 7 | 8 | push rdi 9 | push rsi 10 | push rdx 11 | sub rsp,32 12 | movdqu [rsp+0],xmm0 13 | movdqu [rsp+16],xmm1 14 | 15 | .loop: ; could definitely do this more efficiently 16 | ; instead of one double at a time, but yolo 17 | 18 | movsd xmm0,[rsi] 19 | movsd xmm1,[rdi] 20 | movsd [rdi],xmm0 21 | movsd [rsi],xmm1 22 | 23 | add rdi,8 24 | add rsi,8 25 | dec rdx 26 | jnz .loop 27 | 28 | movdqu xmm0,[rsp+0] 29 | movdqu xmm1,[rsp+16] 30 | add rsp,32 31 | pop rdx 32 | pop rsi 33 | pop rdi 34 | 35 | ret 36 | 37 | %endif 38 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_scale_in_place.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SCALE_IN_PLACE 2 | %define MATRIX_SCALE_IN_PLACE 3 | 4 | matrix_scale_in_place: 5 | ; void matrix_scale_in_place(double* {rdi}, long {rsi}, double {xmm0}); 6 | ; Scales {rsi} elements of the double-precision floating point 7 | ; matrix beginning at {rdi} by the low 8-byte scalar in {xmm0}. 8 | 9 | push rdi 10 | push rsi 11 | sub rsp,16 12 | movdqu [rsp],xmm1 13 | 14 | .loop: ; loop over {rsi} elements 15 | movsd xmm1,[rdi] ; grab element from matrix 16 | mulsd xmm1,xmm0 ; scale element by {xmm0} 17 | movsd [rdi],xmm1 ; drop in back in the matrix 18 | add rdi,8 19 | dec rsi 20 | jnz .loop ; loop until finished 21 | 22 | movdqu xmm1,[rsp] 23 | add rsp,16 24 | pop rsi 25 | pop rdi 26 | 27 | ret ; return 28 | 29 | %endif 30 | -------------------------------------------------------------------------------- /lib/math/lin_alg/copy_diagonal.asm: -------------------------------------------------------------------------------- 1 | %ifndef COPY_DIAGONAL 2 | %define COPY_DIAGONAL 3 | 4 | copy_diagonal: 5 | ; void copy_diagonal(double* {rdi}, double* {rsi}, uint {rdx}); 6 | ; Copies diagonal of {rdx}x{rdx} matrix at address {rsi} to matrix 7 | ; at address {rdi}. Overwrites the diagonals of the destination matrix. 8 | 9 | push rdi 10 | push rsi 11 | push rax 12 | push rdx 13 | push rcx 14 | 15 | mov rcx,rdx 16 | shl rcx,3 17 | imul rdx,rcx 18 | add rdx,rsi ; {rsi} points beyond source matrix 19 | add rcx,8 ; {rcx} contains byte-distance between diagonal elements 20 | 21 | .loop: 22 | mov rax,[rsi] 23 | mov [rdi],rax 24 | add rdi,rcx 25 | add rsi,rcx 26 | cmp rsi,rdx 27 | jb .loop 28 | 29 | pop rcx 30 | pop rdx 31 | pop rax 32 | pop rsi 33 | pop rdi 34 | 35 | ret 36 | 37 | %endif 38 | -------------------------------------------------------------------------------- /lib/math/vector/distance_3.asm: -------------------------------------------------------------------------------- 1 | %ifndef DISTANCE_3 2 | %define DISTANCE_3 3 | 4 | distance_3: 5 | ; double {xmm0} distance_3(double* {rdi}, double* {rsi}); 6 | ; Returns distance between two 3x1 positions starting at addresses 7 | ; {rdi} and {rsx}. 8 | 9 | sub rsp,32 10 | movdqu [rsp+0],xmm1 11 | movdqu [rsp+16],xmm2 12 | 13 | ; x-component 14 | movsd xmm0,[rdi+0] 15 | subsd xmm0,[rsi+0] 16 | mulsd xmm0,xmm0 17 | 18 | ; y-component 19 | movsd xmm1,[rdi+8] 20 | subsd xmm1,[rsi+8] 21 | mulsd xmm1,xmm1 22 | 23 | ; z-component 24 | movsd xmm2,[rdi+16] 25 | subsd xmm2,[rsi+16] 26 | mulsd xmm2,xmm2 27 | 28 | ; compute distance 29 | addsd xmm0,xmm1 30 | addsd xmm0,xmm2 31 | sqrtsd xmm0,xmm0 32 | 33 | movdqu xmm1,[rsp+0] 34 | movdqu xmm2,[rsp+16] 35 | add rsp,32 36 | 37 | ret ; return 38 | 39 | %endif 40 | -------------------------------------------------------------------------------- /lib/engr/cad/primitives/put_cube.asm: -------------------------------------------------------------------------------- 1 | %ifndef PUT_CUBE 2 | %define PUT_CUBE 3 | 4 | put_cube: 5 | ; void* {rax} put_cube(double {xmm0}); 6 | ; Generates a cube primitive of side length {xmm0} and returns 7 | ; the cube address in {rax}. NULL returned on error. 8 | 9 | ; sample cube primitive data structure 10 | %if 0 11 | .cube_primitive: 12 | dq 13 | 14 | %endif 15 | 16 | 17 | 18 | 19 | .vertices: 20 | dq -0.5,-0.5,-0.5 21 | dq 0.5,-0.5,-0.5 22 | dq 0.5,0.5,-0.5 23 | dq -0.5,0.5,-0.5 24 | dq -0.5,-0.5,0.5 25 | dq 0.5,-0.5,0.5 26 | dq 0.5,0.5,0.5 27 | dq -0.5,0.5,0.5 28 | 29 | .edges: 30 | dq 0,1,0x0 31 | dq 1,2,0x0 32 | dq 2,3,0x0 33 | dq 3,0,0x0 34 | dq 4,5,0x0 35 | dq 5,6,0x0 36 | dq 6,7,0x0 37 | dq 7,4,0x0 38 | 39 | .faces: 40 | dq 0,2,1,0x0 41 | dq 0,3,2,0x0 42 | dq 4,5,6,0x0 43 | dq 4,6,7,0x0 44 | 45 | 46 | %endif 47 | -------------------------------------------------------------------------------- /ex/ex003_command_line_args_and_code_golf/README.md: -------------------------------------------------------------------------------- 1 | ## Command Line Args and Code Golf 2 | 3 | In [ex003a](ex003a_chmod_alternative), we implement a simple function to make a file executable. The file is provided as a command line argument. 4 | 5 | In [ex003b](ex003b_chmod_smaller), we repeat the above, but use some techniques to shave off a few bytes. 6 | 7 | In [ex003c](ex003c_touch_alternative), we implement a simple function to create a file. The file is provided as a command line argument. 8 | 9 | In [ex003d](ex003d_touch_smaller), we repeat the above, but use some techniques to shave off a few bytes. 10 | 11 | In [ex003e](ex003e_rm_alternative), we implement a simple function to delete a file. The file is provided as a command line argument. 12 | 13 | In [ex003f](ex003f_rm_smaller), we repeat the above, but use some techniques to shave off a few bytes. 14 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_add_in_place.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_ADD_IN_PLACE 2 | %define MATRIX_ADD_IN_PLACE 3 | 4 | matrix_add_in_place: 5 | ; void matrix_add_in_place(double* {rdi}, double* {rsi}, long {rdx}); 6 | ; Adds {rdx} elements of the double-precision floating point 7 | ; matrix beginning at {rsi} to the one starting at {rdi}. 8 | 9 | push rdi 10 | push rsi 11 | push rdx 12 | sub rsp,16 13 | movdqu [rsp],xmm0 14 | 15 | .loop: ; loop over {rdx} elements 16 | movsd xmm0,[rsi] ; grab element from second matrix 17 | addsd xmm0,[rdi] ; add it to element from first matrix 18 | movsd [rdi],xmm0 ; move it to the first matrix 19 | add rsi,8 ; go onto next element 20 | add rdi,8 21 | dec rdx 22 | jnz .loop ; loop until finished 23 | 24 | movdqu xmm0,[rsp] 25 | add rsp,16 26 | pop rdx 27 | pop rsi 28 | pop rdi 29 | 30 | ret ; return 31 | 32 | %endif 33 | -------------------------------------------------------------------------------- /lib/math/vector/dot_product.asm: -------------------------------------------------------------------------------- 1 | %ifndef DOT_PRODUCT 2 | %define DOT_PRODUCT 3 | 4 | dot_product: 5 | ; double {xmm0} dot_product(double* {rdi}, double* {rsi}, uint {rdx}); 6 | ; Computes the dot product of two {rdx}x1 vectors starting at addresses 7 | ; {rdi} and {rsi}. 8 | 9 | push rdi 10 | push rsi 11 | push rdx 12 | sub rsp,16 13 | movdqu [rsp],xmm1 14 | 15 | pxor xmm0,xmm0 ; initialize running sum to zero 16 | 17 | .loop: ; loop over {rdx} elements, one by one :( 18 | movsd xmm1,[rsi] ; grab element from second matrix 19 | mulsd xmm1,[rdi] ; multiply by element from first matrix 20 | addsd xmm0,xmm1 ; add it to the running sum 21 | add rsi,8 ; go onto next element 22 | add rdi,8 23 | dec rdx 24 | jnz .loop ; loop until finished 25 | 26 | movdqu xmm1,[rsp] 27 | add rsp,16 28 | pop rdx 29 | pop rsi 30 | pop rdi 31 | 32 | ret ; return 33 | 34 | %endif 35 | -------------------------------------------------------------------------------- /ex/ex009_timing/README.md: -------------------------------------------------------------------------------- 1 | ## Timing 2 | 3 | In [ex009a](ex009a_rdtsc), we check for `rdtsc` support and use it to count the number of reference cycles that have elapsed. 4 | 5 | In [ex009b](ex009b_tick_and_tock_in_cycles), we create `tick_cycles` and `tock_cycles` functions to measure the passage of time (think MATLAB) in reference cycles. 6 | 7 | In [ex009c](ex009c_gettimeofday_syscall), we use the `GETTIMEOFDAY` syscall to check the current timestamp (with microsecond "accuracy"). 8 | 9 | In [ex009d](ex009d_tick_and_tock_in_microseconds), we create `tick_time` and `tock_time` functions to measure the passage of time (think MATLAB) in microseconds. 10 | 11 | In [ex009e](ex009e_estimate_CPU_frequency), we use our two sets of `tick` functions to estimate the clock rate of our CPU. 12 | 13 | In [ex009f](ex009f_sleep_delay), we implement a function to sleep a desired amount of microseconds. 14 | -------------------------------------------------------------------------------- /lib/io/framebuffer/framebuffer_flush.asm: -------------------------------------------------------------------------------- 1 | %ifndef FRAMEBUFFER_FLUSH 2 | %define FRAMEBUFFER_FLUSH 3 | 4 | %include "lib/io/framebuffer/framebuffer_init.asm" 5 | 6 | framebuffer_flush: 7 | ; void framebuffer_flush(void); 8 | ; Immediately flushes the content of the current frame to the screen. 9 | 10 | push rdi 11 | push rsi 12 | push rdx 13 | push rax 14 | 15 | ; write frame to framebuffer 16 | mov rax,SYS_WRITE 17 | movzx rdi,byte [framebuffer_init.framebuffer_file_descriptor] 18 | mov rsi,[framebuffer_init.framebuffer_address] 19 | mov rdx,[framebuffer_init.framebuffer_size] 20 | syscall 21 | 22 | ; go back to top of the framebuffer 23 | mov rax,SYS_LSEEK 24 | movzx rdi,byte [framebuffer_init.framebuffer_file_descriptor] 25 | xor rsi,rsi 26 | mov rdx,SYS_SEEK_SET 27 | syscall 28 | 29 | pop rax 30 | pop rdx 31 | pop rsi 32 | pop rdi 33 | 34 | ret 35 | 36 | %endif 37 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_subtract_in_place.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SUBTRACT_IN_PLACE 2 | %define MATRIX_SUBTRACT_IN_PLACE 3 | 4 | matrix_subtract_in_place: 5 | ; void matrix_subtract_in_place(double* {rdi}, double* {rsi}, long {rdx}); 6 | ; Subtracts {rdx} elements of the double-precision floating point 7 | ; matrix beginning at {rsi} from the one starting at {rdi}. 8 | 9 | push rdi 10 | push rsi 11 | push rdx 12 | sub rsp,16 13 | movdqu [rsp],xmm0 14 | 15 | .loop: ; loop over {rdx} elements 16 | movsd xmm0,[rdi] ; grab element from first matrix 17 | subsd xmm0,[rsi] ; subtract off element from second matrix 18 | movsd [rdi],xmm0 ; move it to the first matrix 19 | add rsi,8 ; go onto next element 20 | add rdi,8 21 | dec rdx 22 | jnz .loop ; loop until finished 23 | 24 | movdqu xmm0,[rsp] 25 | add rsp,16 26 | pop rdx 27 | pop rsi 28 | pop rdi 29 | 30 | ret ; return 31 | 32 | %endif 33 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_scale.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SCALE 2 | %define MATRIX_SCALE 3 | 4 | matrix_scale: 5 | ; void matrix_scale(double* {rdi}, double* {rsi}, uint {rdx}, double {xmm0}); 6 | ; Scales {rdx} elements of the double-precision floating point 7 | ; matrix beginning at {rsi} by the low 8-byte scalar in {xmm0} and 8 | ; places the result in the matrix beginning at {rdi}. 9 | 10 | push rdi 11 | push rsi 12 | push rdx 13 | sub rsp,16 14 | movdqu [rsp],xmm1 15 | 16 | .loop: ; loop over {rdx} elements 17 | movsd xmm1,[rsi] ; grab element from source matrix 18 | mulsd xmm1,xmm0 ; scale it 19 | movsd [rdi],xmm1 ; save the result in the destination matrix 20 | add rsi,8 ; go onto next element 21 | add rdi,8 22 | dec rdx 23 | jnz .loop ; loop until finished 24 | 25 | movdqu xmm1,[rsp] 26 | add rsp,16 27 | pop rdx 28 | pop rsi 29 | pop rdi 30 | 31 | ret ; return 32 | 33 | %endif 34 | -------------------------------------------------------------------------------- /lib/math/rand/rand_int.asm: -------------------------------------------------------------------------------- 1 | %ifndef RAND_INT 2 | %define RAND_INT 3 | 4 | rand_int: 5 | ; signed long {rax} rand_int(signed long {rdi}, signed long {rsi}); 6 | ; Returns in {rax} a random integer between {rdi} and {rsi} such that 7 | ; {rdi}<={rax}<={rsi}. 8 | 9 | push rdi 10 | push rsi 11 | push rdx 12 | 13 | inc rsi ; increase upper bound by 1 14 | 15 | .loop: 16 | rdrand rax ; random 64-bit value in {rax} 17 | jnc .loop ; this doesn't seem to be necessary, but we will put it 18 | ; anyway. wait for the carry flag to be set, 19 | ; indicating we have a valid random number in {rax} 20 | 21 | xor rdx,rdx ; zero out high bits for divisionn 22 | sub rsi,rdi ; range of possible values in {rsi} 23 | div rsi ; overflow remainder in {rdx} 24 | add rdi,rdx ; adjust remainder to start of range 25 | 26 | mov rax,rdi ; final value back in {rax} 27 | 28 | pop rdx 29 | pop rsi 30 | pop rdi 31 | 32 | ret ; return 33 | 34 | %endif 35 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_add.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_ADD 2 | %define MATRIX_ADD 3 | 4 | matrix_add: 5 | ; void matrix_add(double* {rdi}, double* {rsi}, double* {rdx}, uint {rcx}); 6 | ; Adds {rcx} elements of the double-precision floating point 7 | ; matrix beginning at {rsi} to the one starting at {rdx} and places the 8 | ; result in the matrix beginning at {rdi}. 9 | 10 | push rdi 11 | push rsi 12 | push rdx 13 | push rcx 14 | sub rsp,16 15 | movdqu [rsp],xmm0 16 | 17 | .loop: ; loop over {rcx} elements 18 | movsd xmm0,[rdx] ; grab element from second matrix 19 | addsd xmm0,[rsi] ; add it to the first matrix 20 | movsd [rdi],xmm0 ; save the result in the destination matrix 21 | add rsi,8 ; go onto next element 22 | add rdi,8 23 | add rdx,8 24 | dec rcx 25 | jnz .loop ; loop until finished 26 | 27 | movdqu xmm0,[rsp] 28 | add rsp,16 29 | pop rcx 30 | pop rdx 31 | pop rsi 32 | pop rdi 33 | 34 | ret ; return 35 | 36 | %endif 37 | -------------------------------------------------------------------------------- /aarch64/lib/IO/STRLEN.S: -------------------------------------------------------------------------------- 1 | .IFNDEF STRLEN 2 | .EQU STRLEN,1 3 | 4 | /////////////////////////////////////////////////////////////////////////////// 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | .MACRO _STRLEN STRING_POINTER 8 | SUB SP, SP, 32 9 | STR LR, [SP,16] 10 | STP X1, X2, [SP,0] 11 | 12 | MOV X0, \STRING_POINTER 13 | BL STRLEN 14 | 15 | LDR LR, [SP,16] 16 | LDP X1, X2, [SP,0] 17 | ADD SP, SP, 32 18 | .ENDM 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | /////////////////////////////////////////////////////////////////////////////// 22 | 23 | STRLEN:// {W0} STRLEN({X0}); 24 | // RETURNS DISTANCE TO NULL BYTE FROM {X0} 25 | 26 | ADD X0, X0, LOAD_ADDRESS 27 | MOV W2, 0 28 | 29 | 1: 30 | LDRB W1, [X0] 31 | CMP W1, 0 32 | B.EQ 2f 33 | 34 | ADD W2, W2, 1 35 | ADD X0, X0, 1 36 | B 1b 37 | 38 | 2: 39 | MOV W0, W2 40 | RET 41 | 42 | .ENDIF 43 | -------------------------------------------------------------------------------- /lib/math/vector/cross_product.asm: -------------------------------------------------------------------------------- 1 | %ifndef CROSS_PRODUCT 2 | %define CROSS_PRODUCT 3 | 4 | ;TODO 5 | 6 | cross_product: 7 | ; void cross_product(double* {rdi}, double* {rsi}, double* {rdx}, uint {rcx}); 8 | ; Computes the cross product of two {rcx}x1 vectors starting at addresses 9 | ; {rsi} and {rdx} and places the result starting at address {rdi}. 10 | 11 | push rdi 12 | push rsi 13 | push rdx 14 | sub rsp,16 15 | movdqu [rsp],xmm1 16 | 17 | pxor xmm0,xmm0 ; initialize running sum to zero 18 | 19 | .loop: ; loop over {rdx} elements, one by one :( 20 | movsd xmm1,[rsi] ; grab element from second matrix 21 | mulsd xmm1,[rdi] ; multiply by element from first matrix 22 | addsd xmm0,xmm1 ; add it to the running sum 23 | add rsi,8 ; go onto next element 24 | add rdi,8 25 | dec rdx 26 | jnz .loop ; loop until finished 27 | 28 | movdqu xmm1,[rsp] 29 | add rsp,16 30 | pop rdx 31 | pop rsi 32 | pop rdi 33 | 34 | ret ; return 35 | 36 | %endif 37 | -------------------------------------------------------------------------------- /ex/ex007_fractions/README.md: -------------------------------------------------------------------------------- 1 | ## Representing Fractions 2 | 3 | In [ex007a](ex007a_printing_floats), we test out a routine to print a diverse set of double-precision floating-point numbers, including special cases. 4 | 5 | In [ex007b](ex007b_scientific_floats), we repeat the above with scientific notation. 6 | 7 | In [ex007c](ex007c_printing_fixed), we test out a routine to print fixed-point numbers. 8 | 9 | In [ex007d](ex007d_floats_speedtest), we test the speed of floating-point with a 100,000,000 iterations of a bisection algorithm to compute sqrt(2). (Note, the main attraction of floats comes from having hardware implementation and parallelizability.) 10 | 11 | In [ex007e](ex007e_fixed_speedtest), we test the speed of fixed-point with a 100,000,000 iterations of a bisection algorithm to compute sqrt(2). 12 | 13 | In [ex007f](ex007f_fraction_speedtest), we test the speed of fractions with a 100,000,000 iterations of a bisection algorithm to compute sqrt(2). 14 | 15 | -------------------------------------------------------------------------------- /lib/io/print_buffer_flush.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_BUFFER_FLUSH 2 | %define PRINT_BUFFER_FLUSH 3 | 4 | print_buffer_flush: 5 | ; void print_buffer_flush(int {rdi}); 6 | ; Flushes the PRINT_BUFFER to file descriptor {rdi}. 7 | 8 | ; save clobbered registers 9 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 10 | push rsi 11 | push rdx 12 | push rax 13 | 14 | mov rsi,PRINT_BUFFER ; save address of first character in {rsi} 15 | .b: 16 | mov rdx,[PRINT_BUFFER_LENGTH] ; set {rdx} to number of bytes in buffer 17 | .a: 18 | mov rax,SYS_WRITE ; set {rax} to write syscall 19 | syscall ; execute write syscall 20 | xor rax,rax 21 | mov [PRINT_BUFFER_LENGTH],rax ; reset print_buffer_length to 0 22 | 23 | ; restore clobbered registers 24 | pop rax 25 | pop rdx 26 | pop rsi 27 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 28 | 29 | ret ; return 30 | 31 | PRINT_BUFFER_LENGTH: ; the number of bytes in the buffer 32 | dq 0 ; initially 0, but increased by print functions 33 | 34 | %endif 35 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_subtract.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SUBTRACT 2 | %define MATRIX_SUBTRACT 3 | 4 | matrix_subtract: 5 | ; void matrix_subtract(double* {rdi}, double* {rsi}, double* {rdx}, uint {rcx}); 6 | ; Subtracts {rcx} elements of the double-precision floating point 7 | ; matrix beginning at {rdx} from the one starting at {rsi} and places the 8 | ; result in the matrix beginning at {rdi}. 9 | 10 | push rdi 11 | push rsi 12 | push rdx 13 | push rcx 14 | sub rsp,16 15 | movdqu [rsp],xmm0 16 | 17 | .loop: ; loop over {rcx} elements 18 | movsd xmm0,[rsi] ; grab element from first matrix 19 | subsd xmm0,[rdx] ; subtract element from the second matrix 20 | movsd [rdi],xmm0 ; save the result in the destination matrix 21 | add rsi,8 ; go onto next element 22 | add rdi,8 23 | add rdx,8 24 | dec rcx 25 | jnz .loop ; loop until finished 26 | 27 | movdqu xmm0,[rsp] 28 | add rsp,16 29 | pop rcx 30 | pop rdx 31 | pop rsi 32 | pop rdi 33 | 34 | ret ; return 35 | 36 | %endif 37 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_extract_row.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_EXTRACT_ROW 2 | %define MATRIX_EXTRACT_ROW 3 | 4 | matrix_extract_row: 5 | ; void matrix_extract_row(double* {rdi}, double* {rsi}, uint {rdx}, uint {rcx}); 6 | ; Extracts row {rcx} of {ANY}x{rdx} double-precision floating point matrix 7 | ; starting at {rsi} into 1x{rdx} vector at address {rdi}. 8 | 9 | ; NOTE: should work on matrices of any 8-byte datatype. 10 | 11 | push rdi 12 | push rsi 13 | push rdx 14 | push rcx 15 | push rax 16 | 17 | shl rcx,3 18 | imul rcx,rdx ; adjust {rdi} to point to the intended row 19 | add rsi,rcx ; of the source matrix 20 | 21 | .loop: 22 | mov rax,[rsi] ; grab source element 23 | mov [rdi],rax ; drop into destination element 24 | 25 | add rsi,8 ; go to next element of source matrix 26 | add rdi,8 ; go to next element of destination vector 27 | 28 | dec rdx ; loop until out of columns 29 | jnz .loop 30 | 31 | pop rax 32 | pop rcx 33 | pop rdx 34 | pop rsi 35 | pop rdi 36 | 37 | ret ; return 38 | 39 | %endif 40 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_insert_row.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_INSERT_ROW 2 | %define MATRIX_INSERT_ROW 3 | 4 | matrix_insert_row: 5 | ; void matrix_insert_row(double* {rdi}, double* {rsi}, uint {rdx}, uint {rcx}); 6 | ; Inserts a 1x{rdx} double-precision floating point vector at {rsi} into 7 | ; row {rcx} of {ANY}x{rdx} matrix starting at address {rdi}. 8 | 9 | ; NOTE: should work on matrices of any 8-byte datatype. 10 | 11 | push rdi 12 | push rsi 13 | push rdx 14 | push rcx 15 | push rax 16 | 17 | shl rcx,3 18 | imul rcx,rdx ; adjust {rdi} to point to the intended row 19 | add rdi,rcx ; of the destination matrix 20 | 21 | .loop: 22 | mov rax,[rsi] ; grab source element 23 | mov [rdi],rax ; drop into destination element 24 | 25 | add rsi,8 ; go to next element of source vector 26 | add rdi,8 ; go to next element of destination matrix 27 | 28 | dec rdx ; loop until out of columns 29 | jnz .loop 30 | 31 | pop rax 32 | pop rcx 33 | pop rdx 34 | pop rsi 35 | pop rdi 36 | 37 | ret ; return 38 | 39 | %endif 40 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_filled_rect.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_FILLED_RECT 2 | %define SET_FILLED_RECT 3 | 4 | ; dependency 5 | %include "lib/io/bitmap/set_line.asm" 6 | 7 | set_filled_rect: 8 | ; void set_filled_rect(void* {rdi}, int {rsi}, int {edx}, int {ecx}, 9 | ; int {r8d}, int {r9d}, int {r10d}, int {r11d}); 10 | ; Draws rectangle from ({r8d},{r9d}) to ({r10d},{r11d}) (from (0,0) 11 | ; @ top-left) in ARGB data array starting at {rdi} for an 12 | ; {edx}x{ecx} (WxH) image with a fill color in the low 32 bits of {rsi}. 13 | 14 | push r8 15 | push r9 16 | push r10 17 | push r11 18 | push rax 19 | 20 | cmp r11,r9 21 | je .ret 22 | jg .top_down 23 | mov rax,-1 24 | jmp .start 25 | .top_down: 26 | mov rax,1 27 | .start: 28 | 29 | mov r11,r9 30 | 31 | ; loop thru all rows 32 | .loop: 33 | 34 | call set_line 35 | 36 | add r9,rax 37 | add r11,rax 38 | 39 | cmp r9,[rsp+8] 40 | jne .loop 41 | 42 | call set_line 43 | 44 | .ret: 45 | pop rax 46 | pop r11 47 | pop r10 48 | pop r9 49 | pop r8 50 | ret 51 | 52 | %endif 53 | -------------------------------------------------------------------------------- /aarch64/lib/IO/LOG_FILE.S: -------------------------------------------------------------------------------- 1 | .IFNDEF LOG_FILE 2 | .EQU LOG_FILE,1 3 | 4 | .INCLUDE "SYS/LINUX/SYSCALLS.S" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | .IFDEF VERBOSE_LOGS 10 | 11 | .MACRO _LOG_FILE PATH 12 | 13 | SUB SP,SP,48 14 | STP X0,X1,[SP,32] 15 | STP X2,X3,[SP,16] 16 | STR X8,[SP,0] 17 | 18 | MOV W3, SYS_DEFAULT_PERMISSIONS // mode 19 | MOV W2, (SYS_READ_WRITE+SYS_CREATE_FILE+SYS_TRUNCATE) // flags 20 | MOV X1, \PATH 21 | ADD X1, X1, LOAD_ADDRESS // position independent LDR basically 22 | MOV X0, SYS_AT_FDCWD // dirfd = AT_FDCWD (current directory) 23 | MOV W8, SYS_OPEN 24 | SVC 0 25 | 26 | MOV X1,LOG_FILE_DESCRIPTOR 27 | ADD X1,X1,LOAD_ADDRESS 28 | STR W0,[X1] 29 | 30 | LDP X0,X1,[SP,32] 31 | LDP X2,X3,[SP,16] 32 | LDR X8,[SP,0] 33 | ADD SP,SP,48 34 | 35 | .ENDM 36 | 37 | .ENDIF 38 | 39 | LOG_FILE_DESCRIPTOR: 40 | .WORD SYS_STDOUT 41 | 42 | 43 | .ENDIF 44 | -------------------------------------------------------------------------------- /lib/mem/memcopy.asm: -------------------------------------------------------------------------------- 1 | %ifndef MEMCOPY 2 | %define MEMCOPY 3 | 4 | memcopy: 5 | ; void memcopy(long* {rdi}, long* {rsi}, ulong {rdx}); 6 | ; Copies {rdx} bytes from {rsi} to {rdi}. 7 | 8 | push rdi 9 | push rsi 10 | push rdx 11 | push rax 12 | 13 | cmp rdx,8 ; if less than 8 bytes 14 | jb .loop_by_1 ; goto smaller loop 15 | 16 | .loop_by_8: ; copy 8 bytes at a time 17 | mov rax, [rsi] 18 | mov [rdi],rax 19 | add rsi,8 ; goto next element of source 20 | add rdi,8 ; goto next element of destination 21 | sub rdx,8 22 | cmp rdx,8 23 | jge .loop_by_8 ; loop until <8 bytes remaining 24 | 25 | ; could add extra instructions here for a slight speedup 26 | 27 | test rdx,rdx ; if we were an exact multiple of 8 28 | jz .done ; skip to end 29 | 30 | .loop_by_1: ; copy 1 byte at a time 31 | mov al, byte [rsi] 32 | mov byte [rdi], al 33 | inc rdi 34 | inc rsi 35 | dec rdx 36 | jnz .loop_by_1 ; loop until 0 bytes remaining 37 | 38 | .done: 39 | pop rax 40 | pop rdx 41 | pop rsi 42 | pop rdi 43 | 44 | ret 45 | 46 | %endif 47 | -------------------------------------------------------------------------------- /aarch64/lib/SYS/HELPER.S: -------------------------------------------------------------------------------- 1 | .IFNDEF HELPER 2 | .EQU HELPER,1 3 | 4 | /////////////////////////////////////////////////////////////////////////////// 5 | /////////////////////////////////////////////////////////////////////////////// 6 | 7 | .EQU VOLATILE_LENGTH,160 8 | 9 | .MACRO _PUSH_VOLATILES // THIS IS BECAUSE ARM IS TRASH AND GNU IS TRASH 10 | // AND BOOMERS ARE TRASH 11 | SUB SP, SP, VOLATILE_LENGTH 12 | STP LR, X0, [SP,0] 13 | STP X1, X2, [SP,16] 14 | STP X3, X4, [SP,32] 15 | STP X5, X6, [SP,48] 16 | STP X7, X8, [SP,64] 17 | STP X9, X10, [SP,80] 18 | STP X11, X12, [SP,96] 19 | STP X13, X14, [SP,112] 20 | STP X15, X16, [SP,128] 21 | STP X17, X18, [SP,144] 22 | .ENDM 23 | 24 | .MACRO _POP_VOLATILES // SAME STORY 25 | LDP LR, X0, [SP,0] 26 | LDP X1, X2, [SP,16] 27 | LDP X3, X4, [SP,32] 28 | LDP X5, X6, [SP,48] 29 | LDP X7, X8, [SP,64] 30 | LDP X9, X10, [SP,80] 31 | LDP X11, X12, [SP,96] 32 | LDP X13, X14, [SP,112] 33 | LDP X15, X16, [SP,128] 34 | LDP X17, X18, [SP,144] 35 | ADD SP, SP, VOLATILE_LENGTH 36 | .ENDM 37 | 38 | .ENDIF 39 | -------------------------------------------------------------------------------- /lib/math/lin_alg/lu_solve.asm: -------------------------------------------------------------------------------- 1 | %ifndef LU_SOLVE 2 | %define LU_SOLVE 3 | 4 | ; dependencies 5 | %include "lib/math/lin_alg/lu_decomposition.asm" 6 | %include "lib/math/lin_alg/forward_substitution.asm" 7 | %include "lib/math/lin_alg/backward_substitution.asm" 8 | 9 | lu_solve: 10 | ; void {rax} lu_solve(double* {rdi}, double* {rsi}, double* {rdx}, uint {rcx}); 11 | ; Solves linear system for square {rcx}x{rcx} double-precision matrix A at {rsi} 12 | ; and {rcx}x1 right-hand-side vector b at {rdx} into resultant {rcx}x1 vector at 13 | ; {rdi}. 14 | 15 | push r8 16 | push rdi 17 | push rsi 18 | 19 | ; perform LU_decomposition in-place 20 | ; so Ax=b=(LU)x=b 21 | mov rdi,rsi ; address of A 22 | mov rsi,rcx ; size of A matrix (# rows) 23 | call lu_decomposition 24 | 25 | pop rsi 26 | pop rdi 27 | 28 | ; forward substitution to find (Ux) from L(Ux)=b 29 | mov r8,2 30 | call forward_substitution 31 | 32 | ; backward substitution to find x from Ux=(Ux) 33 | xor r8,r8 34 | call backward_substitution 35 | 36 | pop r8 37 | ret 38 | 39 | %endif 40 | -------------------------------------------------------------------------------- /lib/time/tock_time.asm: -------------------------------------------------------------------------------- 1 | %ifndef TOCK_TIME 2 | %define TOCK_TIME 3 | 4 | ; dependency 5 | %include "lib/time/tick_time.asm" 6 | 7 | tock_time: 8 | ; uint {rax} tock_time(void); 9 | ; Returns microseconds that have elapsed since last call of 10 | ; tick_time in {rax}. 11 | 12 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 13 | push rdi 14 | push rsi 15 | push rdx 16 | 17 | ; save previous timestamp microseconds in {rdx} 18 | mov rdx,[tick_time.tick] 19 | mov rdi,1000000 20 | imul rdx,rdi 21 | add rdx,[tick_time.tick+8] 22 | 23 | ; syscall for current timestamp 24 | mov rax,SYS_GETTIMEOFDAY 25 | mov rdi,tock_time.tock 26 | xor rsi,rsi 27 | syscall 28 | 29 | ; get current timestamp_microseconds in {rax} 30 | mov rax,[tock_time.tock] 31 | mov rdi,1000000 32 | imul rax,rdi 33 | add rax,[tock_time.tock+8] 34 | 35 | ; compute the elapsed microseconds 36 | sub rax,rdx 37 | 38 | pop rdx 39 | pop rsi 40 | pop rdi 41 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 42 | 43 | ret 44 | 45 | .tock: 46 | dq 0 ; seconds 47 | dq 0 ; microseconds 48 | 49 | %endif 50 | -------------------------------------------------------------------------------- /lib/io/framebuffer/framebuffer_mouse_init.asm: -------------------------------------------------------------------------------- 1 | %ifndef FRAMEBUFFER_MOUSE_INIT 2 | %define FRAMEBUFFER_MOUSE_INIT 3 | 4 | %include "lib/io/file_open.asm" 5 | %include "lib/io/framebuffer/framebuffer_init.asm" 6 | 7 | framebuffer_mouse_init: 8 | ; void framebuffer_mouse_init(void); 9 | ; Initializes data structures to track the current mouse position and 10 | ; state. Requires that the "framebuffer" already be in use. 11 | ; No error handling. 12 | 13 | push rdi 14 | push rsi 15 | push rdx 16 | push rax 17 | 18 | xor al,al 19 | mov [.mouse_state],al 20 | 21 | mov rdi,.filename 22 | mov rsi,SYS_READ_WRITE 23 | mov rdx,SYS_DEFAULT_PERMISSIONS 24 | call file_open 25 | mov [.file_descriptor],al ; save file descriptor 26 | 27 | pop rax 28 | pop rdx 29 | pop rsi 30 | pop rdi 31 | 32 | ret 33 | 34 | .filename: 35 | db `/dev/input/mice\0` 36 | 37 | .file_descriptor: 38 | db 0 39 | 40 | .mouse_x: ; from left 41 | dd 0 42 | 43 | .mouse_y: ; from top 44 | dd 0 45 | 46 | .mouse_state: ; bit 0 = left, 1 = right, 2 = middle 47 | db 0 48 | 49 | %endif 50 | -------------------------------------------------------------------------------- /lib/math/vector/dot_product_3.asm: -------------------------------------------------------------------------------- 1 | %ifndef DOT_PRODUCT_3 2 | %define DOT_PRODUCT_3 3 | 4 | dot_product_3: 5 | ; double {xmm0} dot_product_3(double* {rdi}, double* {rsi}); 6 | ; Computes the dot product of two 3x1 vectors starting at addresses 7 | ; {rdi} and {rsi}. 8 | 9 | sub rsp,32 10 | movdqu [rsp+0],xmm1 11 | movdqu [rsp+16],xmm2 12 | 13 | ; first component into the dot product 14 | movsd xmm0,[rdi] ; first element of vector 1 15 | mulsd xmm0,[rsi] ; first element of vector 2 16 | 17 | ; second component into the dot product 18 | movsd xmm1,[rdi+8] ; second element of vector 1 19 | mulsd xmm1,[rsi+8] ; second element of vector 2 20 | 21 | ; third component into the dot product 22 | movsd xmm2,[rdi+16] ; third element of vector 1 23 | mulsd xmm2,[rsi+16] ; third element of vector 2 24 | 25 | ; add everything together 26 | addsd xmm1,xmm2 ; add second and third dots together 27 | addsd xmm0,xmm1 ; sum everything into {xmm0} 28 | 29 | movdqu xmm1,[rsp+0] 30 | movdqu xmm2,[rsp+16] 31 | add rsp,32 32 | 33 | ret ; return 34 | 35 | %endif 36 | -------------------------------------------------------------------------------- /lib/math/vector/normalize_3.asm: -------------------------------------------------------------------------------- 1 | %ifndef NORMALIZE_3 2 | %define NORMALIZE_3 3 | 4 | normalize_3: 5 | ; void normalize_3(double* {rdi}); 6 | ; Normalizes the 3x1 double vector starting at {rdi} in-place. 7 | 8 | sub rsp,48 9 | movdqu [rsp],xmm0 10 | movdqu [rsp+16],xmm1 11 | movdqu [rsp+32],xmm2 12 | 13 | ; compute vector magnitude 14 | movsd xmm0,[rdi] 15 | mulsd xmm0,xmm0 16 | movsd xmm1,[rdi+8] 17 | mulsd xmm1,xmm1 18 | movsd xmm2,[rdi+16] 19 | mulsd xmm2,xmm2 20 | addsd xmm0,xmm1 21 | addsd xmm0,xmm2 22 | sqrtsd xmm0,xmm0 23 | movsd xmm1,[.one] 24 | divsd xmm1,xmm0 25 | 26 | ; scale first component 27 | movsd xmm0,[rdi] 28 | mulsd xmm0,xmm1 29 | movsd [rdi],xmm0 30 | 31 | ; scale second component 32 | movsd xmm0,[rdi+8] 33 | mulsd xmm0,xmm1 34 | movsd [rdi+8],xmm0 35 | 36 | ; scale third component 37 | movsd xmm0,[rdi+16] 38 | mulsd xmm0,xmm1 39 | movsd [rdi+16],xmm0 40 | 41 | movdqu xmm0,[rsp] 42 | movdqu xmm1,[rsp+16] 43 | movdqu xmm2,[rsp+32] 44 | add rsp,48 45 | 46 | ret ; return 47 | 48 | .one: 49 | dq 1.0 50 | 51 | %endif 52 | -------------------------------------------------------------------------------- /lib/sys/getenv.asm: -------------------------------------------------------------------------------- 1 | %ifndef GETENV 2 | %define GETENV 3 | 4 | getenv: 5 | ; char* {rax} getenv(char* {rdi}, void* {rsi}); 6 | ; Searches stack for null-terminated environment variable starting at 7 | ; {rdi} and returns address of null-terminated entry at {rax}. Program 8 | ; entry argc address passed in {rsi}. Returns NULL {rax} on fail. 9 | 10 | push rsi 11 | push rdx 12 | push rcx 13 | 14 | mov rax,[rsi] 15 | add rax,2 16 | shl rax,3 17 | add rsi,rax ; {rsi} points to first environment variable address 18 | 19 | .outer_loop: 20 | mov rcx,rdi 21 | mov rdx,[rsi] 22 | 23 | .inner_loop: 24 | cmp byte [rcx],0 25 | je .success 26 | 27 | mov al,byte [rcx] 28 | cmp byte [rdx],al 29 | jne .inner_loop_fail 30 | 31 | inc rcx 32 | inc rdx 33 | jmp .inner_loop 34 | 35 | .inner_loop_fail: 36 | add rsi,8 37 | cmp qword [rsi],0 38 | je .fail 39 | jmp .outer_loop 40 | 41 | .fail: 42 | xor rax,rax 43 | jmp .exit 44 | 45 | .success: 46 | mov rax,rdx 47 | inc rax 48 | 49 | .exit: 50 | pop rcx 51 | pop rdx 52 | pop rsi 53 | 54 | ret 55 | 56 | %endif 57 | -------------------------------------------------------------------------------- /lib/io/framebuffer/framebuffer_hud_init.asm: -------------------------------------------------------------------------------- 1 | %ifndef FRAMEBUFFER_HUD_INIT 2 | %define FRAMEBUFFER_HUD_INIT 3 | 4 | %include "lib/mem/heap_alloc.asm" 5 | %include "lib/io/framebuffer/framebuffer_init.asm" 6 | 7 | framebuffer_hud_init: 8 | ; void* {rax} framebuffer_hud_init(void); 9 | ; Initializes an intermediate buffer for the hud to be rendered to. 10 | ; Automatically pulls relevant details from framebuffer. 11 | ; Returns address to hudbuffer (null on error). 12 | 13 | push rdi 14 | 15 | mov rdi,[framebuffer_init.framebuffer_size] 16 | call heap_alloc 17 | mov [.hudbuffer_address],rax ; save hudbuffer address 18 | 19 | pop rdi 20 | 21 | ret 22 | 23 | .hudbuffer_address: 24 | dq 0 25 | 26 | .hud_enabled: 27 | db 0 28 | .hud: 29 | .hud_head: 30 | dq 0 31 | .hud_tail: 32 | dq 0 33 | 34 | %if 0 ; TO ENABLE HUD 35 | 36 | mov al,1 37 | mov [framebuffer_hud_init.hud_enabled],al 38 | 39 | mov rax,.HUD_STARTING_ELEMENT 40 | mov [framebuffer_hud_init.hud_head],rax 41 | 42 | mov rax,.HUD_ENDING_ELEMENT 43 | mov [framebuffer_hud_init.hud_tail],rax 44 | 45 | %endif 46 | 47 | %endif 48 | -------------------------------------------------------------------------------- /aarch64/lib/SYS/EXIT.S: -------------------------------------------------------------------------------- 1 | .IFNDEF EXIT 2 | 3 | /////////////////////////////////////////////////////////////////////////////// 4 | /////////////////////////////////////////////////////////////////////////////// 5 | 6 | .MACRO _EXIT NUMBER // NUMBER OR REGISTER 7 | MOV W0, \NUMBER 8 | BL EXIT 9 | .ENDM 10 | 11 | .IFDEF VERBOSE_LOGS 12 | 13 | .INCLUDE "IO/LOG_TEXT.S" 14 | .INCLUDE "IO/LOG_DECIMAL.S" 15 | 16 | 1: 17 | .ASCII "EXITING WITH CODE: \n" 18 | 19 | .ENDIF 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | /////////////////////////////////////////////////////////////////////////////// 23 | 24 | .ALIGN 2 25 | 26 | EXIT: // VOID EXIT({B0}); 27 | 28 | .IFDEF VERBOSE_LOGS 29 | SUB SP,SP,16 30 | STR W0,[SP] 31 | _LOG_TEXT 1b 19 32 | LDR W0,[SP] 33 | AND W0,W0,0XFF 34 | _LOG_DECIMAL X0 35 | _LOG_TEXT (1b+19),1 // TODO: MAYBE REPLACE WITH LOG_CHAR OR LOG_BYTE 36 | LDR W0,[SP] 37 | ADD SP,SP,16 // UNNECESSARY 38 | .ENDIF 39 | 40 | MOV W8, SYS_EXIT 41 | SVC 0 42 | 43 | RET 44 | 45 | .ENDIF 46 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_set_identity.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_SET_IDENTITY 2 | %define MATRIX_SET_IDENTITY 3 | 4 | matrix_set_identity: 5 | ; void matrix_set_identity(double* {rdi}, uint {rsi}, uint {rdx}); 6 | ; Sets {rsi}x{rdx} double-precision floating point matrix beginning 7 | ; at {rdi} to an identity matrix. 8 | 9 | push rdi 10 | push rsi 11 | push rcx 12 | sub rsp,32 13 | movdqu [rsp+16],xmm1 14 | movdqu [rsp],xmm0 15 | 16 | pxor xmm0,xmm0 ; {xmm0}=0 17 | movsd xmm1,[.one] ; {xmm1}=1 18 | 19 | mov rcx,rdx ; {rcx}=number of columns 20 | movsd [rdi],xmm1 ; set first diagonal 21 | add rdi,8 22 | dec rsi 23 | 24 | .next_diagonal: 25 | movsd [rdi],xmm0 ; place off-diagonal element 26 | add rdi,8 27 | dec rcx 28 | jnz .next_diagonal ; loop for {rcx}+1 elements 29 | 30 | mov rcx,rdx 31 | movsd [rdi],xmm1 ; place diagonal element 32 | add rdi,8 33 | dec rsi ; loop for {rsi} rows 34 | jnz .next_diagonal 35 | 36 | movdqu xmm1,[rsp+16] 37 | movdqu xmm0,[rsp] 38 | add rsp,32 39 | pop rcx 40 | pop rsi 41 | pop rdi 42 | 43 | ret ; return 44 | 45 | .one: 46 | dq 1.0 47 | 48 | %endif 49 | -------------------------------------------------------------------------------- /lib/math/vector/cross_product_3.asm: -------------------------------------------------------------------------------- 1 | %ifndef CROSS_PRODUCT_3 2 | %define CROSS_PRODUCT_3 3 | 4 | cross_product_3: 5 | ; void cross_product_3(double* {rdi}, double* {rsi}, double* {rdx}); 6 | ; Computes the cross product of two 3x1 vectors starting at addresses 7 | ; {rsi} and {rdx} and places the result starting at address {rdi}. 8 | 9 | sub rsp,64 10 | movdqu [rsp+0],xmm0 11 | movdqu [rsp+16],xmm1 12 | movdqu [rsp+32],xmm2 13 | movdqu [rsp+48],xmm3 14 | 15 | movsd xmm0,[rsi+8] 16 | mulsd xmm0,[rdx+16] 17 | movsd xmm1,[rsi+16] 18 | mulsd xmm1,[rdx+8] 19 | subsd xmm0,xmm1 20 | movsd xmm2,xmm0 21 | 22 | movsd xmm0,[rsi+16] 23 | mulsd xmm0,[rdx+0] 24 | movsd xmm1,[rsi+0] 25 | mulsd xmm1,[rdx+16] 26 | subsd xmm0,xmm1 27 | movsd xmm3,xmm0 28 | 29 | movsd xmm0,[rsi+0] 30 | mulsd xmm0,[rdx+8] 31 | movsd xmm1,[rsi+8] 32 | mulsd xmm1,[rdx+0] 33 | subsd xmm0,xmm1 34 | 35 | movsd [rdi+0],xmm2 36 | movsd [rdi+8],xmm3 37 | movsd [rdi+16],xmm0 38 | 39 | movdqu xmm0,[rsp+0] 40 | movdqu xmm1,[rsp+16] 41 | movdqu xmm2,[rsp+32] 42 | movdqu xmm3,[rsp+48] 43 | add rsp,64 44 | 45 | ret ; return 46 | 47 | %endif 48 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_insert_column.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_INSERT_COLUMN 2 | %define MATRIX_INSERT_COLUMN 3 | 4 | matrix_insert_column: 5 | ; void matrix_insert_column(double* {rdi}, double* {rsi}, uint {rdx}, 6 | ; uint {rcx}, uint {r8}); 7 | ; Inserts a {rdx}x1 double-precision floating point vector at {rsi} 8 | ; into column {r8} of {rdx}x{rcx} matrix starting at address {rdi}. 9 | 10 | ; NOTE: should work on matrices of any 8-byte datatype. 11 | 12 | push rdi 13 | push rsi 14 | push rdx 15 | push rcx 16 | push rax 17 | push r8 18 | 19 | shl r8,3 ; convert target column into byte offset 20 | add rdi,r8 ; adjust {rdi} to column offset {r8} 21 | 22 | shl rcx,3 ; adjust {rcx} to indicate byte-width of matrix 23 | 24 | .loop: 25 | mov rax,[rsi] ; grab source element 26 | mov [rdi],rax ; drop into destination element 27 | 28 | add rsi,8 ; go to next element of source vector 29 | add rdi,rcx ; go to next element of destination matrix 30 | 31 | dec rdx ; loop until out of rows 32 | jnz .loop 33 | 34 | pop r8 35 | pop rax 36 | pop rcx 37 | pop rdx 38 | pop rsi 39 | pop rdi 40 | 41 | ret ; return 42 | 43 | %endif 44 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_extract_column.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_EXTRACT_COLUMN 2 | %define MATRIX_EXTRACT_COLUMN 3 | 4 | matrix_extract_column: 5 | ; void matrix_extract_column(double* {rdi}, double* {rsi}, uint {rdx}, 6 | ; uint {rcx}, uint {r8}); 7 | ; Extracts a {rdx}x1 double-precision floating point vector at {rdi} 8 | ; from column {r8} of {rdx}x{rcx} matrix starting at address {rsi}. 9 | 10 | ; NOTE: should work on matrices of any 8-byte datatype. 11 | 12 | push rdi 13 | push rsi 14 | push rdx 15 | push rcx 16 | push rax 17 | push r8 18 | 19 | shl r8,3 ; convert target column into byte offset 20 | add rsi,r8 ; adjust {rsi} to column offset {r8} 21 | 22 | shl rcx,3 ; adjust {rcx} to indicate byte-width of matrix 23 | 24 | .loop: 25 | mov rax,[rsi] ; grab source element 26 | mov [rdi],rax ; drop into destination element 27 | 28 | add rsi,rcx ; go to next element of source matrix 29 | add rdi,8 ; go to next element of destination vector 30 | 31 | dec rdx ; loop until out of rows 32 | jnz .loop 33 | 34 | pop r8 35 | pop rax 36 | pop rcx 37 | pop rdx 38 | pop rsi 39 | pop rdi 40 | 41 | ret ; return 42 | 43 | %endif 44 | -------------------------------------------------------------------------------- /lib/math/lin_alg/inverse_2x2.asm: -------------------------------------------------------------------------------- 1 | %ifndef INVERSE_2x2 2 | %define INVERSE_2x2 3 | 4 | inverse_2x2: 5 | ; void inverse_2x2(double* {rdi}, double* {rsi}); 6 | ; Inverts the 2x2 matrix of double at address {rsi} into the 2x2 matrix at address {rdi}. 7 | 8 | ; save registers 9 | sub rsp,32 10 | movdqu [rsp+0],xmm0 11 | movdqu [rsp+16],xmm1 12 | 13 | ; compute determinant 14 | movsd xmm0,[rsi] 15 | mulsd xmm0,[rsi+24] 16 | movsd xmm1,[rsi+8] 17 | mulsd xmm1,[rsi+16] 18 | subsd xmm0,xmm1 19 | movsd xmm1,[.one] 20 | divsd xmm1,xmm0 ; {xmm1} contains 1/determinant 21 | 22 | ; element 1,1 23 | movsd xmm0,[rsi+24] 24 | mulsd xmm0,xmm1 25 | movsd [rdi],xmm0 26 | 27 | ; element 1,2 28 | pxor xmm0,xmm0 29 | subsd xmm0,[rsi+8] 30 | mulsd xmm0,xmm1 31 | movsd [rdi+8],xmm0 32 | 33 | ; element 2,1 34 | pxor xmm0,xmm0 35 | subsd xmm0,[rsi+16] 36 | mulsd xmm0,xmm1 37 | movsd [rdi+16],xmm0 38 | 39 | ; element 2,2 40 | movsd xmm0,[rsi] 41 | mulsd xmm0,xmm1 42 | movsd [rdi+24],xmm0 43 | 44 | ; restore registers 45 | movdqu xmm0,[rsp+0] 46 | movdqu xmm1,[rsp+16] 47 | add rsp,32 48 | 49 | ret 50 | 51 | .one: 52 | dq 1.0 53 | 54 | %endif 55 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_pixel.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_PIXEL 2 | %define SET_PIXEL 3 | 4 | set_pixel: 5 | ; void set_pixel(void* {rdi}, int {rsi}, int {edx}, int {ecx}, 6 | ; int {r8d}, int {r9d}); 7 | ; Sets pixel at ({r8d},{r9d}) (from (0,0) @ top-left) in ARGB data 8 | ; array starting at {rdi} for an {edx}x{ecx} (WxH) image to the 9 | ; value in {esi}. The 32nd bit of {rsi} indicates the y stacking direction: 10 | ; 0 for bottom-to-top formats (bmp) and 1 for top-to-bottom (framebuffer). 11 | ; Silently skips any pixel outside the image. 12 | 13 | cmp r8d,0 14 | jl .skip 15 | cmp r9d,0 16 | jl .skip 17 | cmp r8d,edx 18 | jge .skip 19 | cmp r9d,ecx 20 | jge .skip 21 | 22 | push rcx 23 | push rax 24 | 25 | mov rax,rsi 26 | shr rax,32 27 | test rax,1 28 | jnz .framebuffer_stacking 29 | 30 | .bitmap_stacking: 31 | sub rcx,r9 32 | dec rcx 33 | jmp .rejoin 34 | .framebuffer_stacking: 35 | mov rcx,r9 36 | .rejoin: 37 | imul rcx,rdx 38 | add rcx,r8 39 | shl rcx,2 ; offset to pixel address 40 | 41 | mov rax,0xFFFFFFFF 42 | and rax,rsi 43 | 44 | mov [rdi+rcx], dword eax 45 | 46 | pop rax 47 | pop rcx 48 | .skip: 49 | ret ; return 50 | 51 | %endif 52 | -------------------------------------------------------------------------------- /lib/math/rand/rand_float.asm: -------------------------------------------------------------------------------- 1 | %ifndef RAND_FLOAT 2 | %define RAND_FLOAT 3 | 4 | rand_float: 5 | ; double {xmm0} rand_float(double {xmm0}, double {xmm1}); 6 | ; Returns in {xmm0} a random double-precision floating point value such 7 | ; that {xmm0 (input)} <= {xmm0 (output)} <= {xmm1}. 8 | 9 | sub rsp,40 10 | movdqu [rsp+24],xmm2 11 | movdqu [rsp+8],xmm1 12 | mov [rsp+0],rax 13 | 14 | .loop: 15 | rdrand rax ; random 64-bit value in {rax} 16 | jnc .loop ; this doesn't seem to be necessary, but we will put it 17 | ; anyway. wait for the carry flag to be set, 18 | ; indicating we have a valid random number in {rax} 19 | 20 | shr rax,1 ; positives only 21 | subsd xmm1,xmm0 ; range in {xmm1} 22 | cvtsi2sd xmm2,rax ; random 64-bit value in {xmm2} 23 | mulsd xmm2,[.tiny] ; convert our number with a very small increment 24 | 25 | mulsd xmm1,xmm2 ; extend the float over the entire range 26 | addsd xmm0,xmm1 ; offset the float by the minimum value 27 | 28 | movdqu xmm2,[rsp+24] 29 | movdqu xmm1,[rsp+8] 30 | mov rax,[rsp+0] 31 | add rsp,40 32 | 33 | ret ; return 34 | 35 | .tiny: 36 | dq 0x3c00000000000000 ; (1/2)^63 to convert our int to float 37 | 38 | %endif 39 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_polygon.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_POLYGON 2 | %define SET_POLYGOM 3 | 4 | ; dependency 5 | %include "lib/io/bitmap/set_line.asm" 6 | 7 | set_polygon: 8 | ; void set_polygon(void* {rdi}, int {rsi}, int {edx}, int {ecx}, 9 | ; double* {r8}, int {r9}); 10 | ; Draws polygon with {r9} vertices in 2*{r9} length long (8-byte) int array at {r8} 11 | ; to ARGB data array starting at {rdi} for an 12 | ; {edx}x{ecx} (WxH) image with a fill color in the low 32 bits of {rsi}. 13 | 14 | push r8 15 | push r9 16 | push r10 17 | push r11 18 | push r12 19 | push r13 20 | push rax 21 | 22 | cmp r9,1 23 | jle .ret 24 | 25 | mov r12,r8 26 | mov r13,r9 27 | 28 | ; last shall be first 29 | mov rax,r13 30 | shl rax,4 31 | add rax,r13 32 | mov r8,[r12] 33 | mov r9,[r12+8] 34 | mov r10,[rax] 35 | mov r11,[rax+8] 36 | call set_line 37 | 38 | dec r13 39 | 40 | ; loop thru all rows 41 | .loop: 42 | mov r8,[r12+0] 43 | mov r9,[r12+8] 44 | mov r10,[r12+16] 45 | mov r11,[r12+24] 46 | call set_line 47 | add r12,16 48 | dec r13 49 | jnz .loop 50 | 51 | .ret: 52 | pop rax 53 | pop r13 54 | pop r12 55 | pop r11 56 | pop r10 57 | pop r9 58 | pop r8 59 | ret 60 | 61 | %endif 62 | -------------------------------------------------------------------------------- /aarch64/lib/IO/LOG_TEXT.S: -------------------------------------------------------------------------------- 1 | .IFNDEF LOG_TEXT 2 | .EQU LOG_TEXT,1 3 | 4 | .INCLUDE "IO/LOG_FILE.S" 5 | .INCLUDE "IO/STRLEN.S" 6 | .INCLUDE "SYS/HELPER.S" 7 | 8 | /////////////////////////////////////////////////////////////////////////////// 9 | /////////////////////////////////////////////////////////////////////////////// 10 | 11 | .MACRO _LOG_TEXT TEXT NUM_BYTES 12 | SUB SP, SP, 32 13 | STP LR, X0, [SP,16] 14 | STP X1, X2, [SP,0] 15 | 16 | MOV W2, \NUM_BYTES 17 | MOV X1, \TEXT 18 | BL LOG_TEXT 19 | 20 | LDP LR, X0, [SP,16] 21 | LDP X1, X2, [SP,0] 22 | ADD SP, SP, 32 23 | .ENDM 24 | 25 | .MACRO _LOG_NULL_TERM_STRING TEXT 26 | 27 | SUB SP, SP, 32 28 | STP X0, LR, [SP,16] 29 | STP X1, X2, [SP,0] 30 | 31 | _STRLEN \TEXT 32 | 33 | MOV W2, W0 34 | MOV X1, \TEXT 35 | BL LOG_TEXT 36 | 37 | LDP X0, LR, [SP,16] 38 | LDP X1, X2, [SP,0] 39 | ADD SP, SP, 32 40 | 41 | .ENDM 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | /////////////////////////////////////////////////////////////////////////////// 45 | 46 | LOG_TEXT:// {W0} LOG_TEXT({X1}, {W2}); 47 | 48 | LDR W0, LOG_FILE_DESCRIPTOR 49 | ADD X1, X1, LOAD_ADDRESS 50 | MOV W8, SYS_WRITE 51 | SVC 0 52 | RET 53 | 54 | .ENDIF 55 | -------------------------------------------------------------------------------- /lib/math/rand/rand_int_array.asm: -------------------------------------------------------------------------------- 1 | %ifndef RAND_INT_ARRAY 2 | %define RAND_INT_ARRAY 3 | 4 | rand_int_array: 5 | ; void rand_int_array(long* {rdi}, int {rsi}, uint {rdx}, 6 | ; signed long {rcx}, signed long {r8}); 7 | ; Places {rdx} random integers in an array starting at {rdi} with 8 | ; ({rsi}+8) bytes between elements. The random values will satisfy 9 | ; {rcx}<={value}<={r8}. 10 | 11 | push rdi 12 | push rsi 13 | push rdx 14 | push r8 15 | push r9 16 | 17 | mov r9,rdx ; store counter in {r9} 18 | inc r8 ; increase upper bound by 1 19 | sub r8,rcx ; range of possible values in {r8} 20 | 21 | .loop: 22 | rdrand rax ; random 64-bit value in {rax} 23 | jnc .loop ; don't seem to need this, but might as well put it 24 | ; (carry flag indicates we are done generating number) 25 | 26 | xor rdx,rdx ; zero out high bits for divisionn 27 | div r8 ; overflow remainder in {rdx} 28 | add rdx,rcx ; adjust remainder to start of range 29 | 30 | mov [rdi],rdx ; place random integer into array 31 | add rdi,8 ; go onto next array target 32 | add rdi,rsi ; extra offset between elements 33 | 34 | dec r9 35 | jnz .loop 36 | 37 | pop r9 38 | pop r8 39 | pop rdx 40 | pop rsi 41 | pop rdi 42 | 43 | ret ; return 44 | 45 | %endif 46 | -------------------------------------------------------------------------------- /lib/time/sleep.asm: -------------------------------------------------------------------------------- 1 | %ifndef SLEEP 2 | %define SLEEP 3 | 4 | sleep: 5 | ; void sleep(uint {rdi}); 6 | ; Sleeps for at least {rdi} microseconds. 7 | 8 | SYS_PUSH_SYSCALL_CLOBBERED_REGISTERS 9 | push rdi 10 | push rsi 11 | push rdx 12 | push r15 13 | 14 | ; save delay in {r15} 15 | mov r15,rdi 16 | 17 | ; syscall for current timestamp 18 | mov rax,SYS_GETTIMEOFDAY 19 | mov rdi,sleep.tick 20 | xor rsi,rsi 21 | syscall 22 | 23 | ; get current timestamp_microseconds in {rdx} 24 | mov rdx,[sleep.tick] 25 | mov rdi,1000000 26 | imul rdx,rdi 27 | add rdx,[sleep.tick+8] 28 | 29 | ; adjust {r15} to the targeted timestamp microsecond 30 | add r15,rdx 31 | 32 | .loop: 33 | 34 | ; syscall for current timestamp 35 | mov rax,SYS_GETTIMEOFDAY 36 | mov rdi,sleep.tick 37 | xor rsi,rsi 38 | syscall 39 | 40 | ; get current timestamp_microseconds in {rax} 41 | mov rax,[sleep.tick] 42 | mov rdi,1000000 43 | imul rax,rdi 44 | add rax,[sleep.tick+8] 45 | 46 | ; loop until we hit the target timestamp 47 | cmp rax,r15 48 | jl .loop 49 | 50 | pop r15 51 | pop rdx 52 | pop rsi 53 | pop rdi 54 | SYS_POP_SYSCALL_CLOBBERED_REGISTERS 55 | 56 | ret 57 | 58 | .tick: 59 | dq 0 ; seconds 60 | dq 0 ; microseconds 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /lib/io/print_int_b.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_INT_B 2 | %define PRINT_INT_B 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_int_b: 8 | ; void print_int_b(int {rdi}, int {rsi}); 9 | ; Prints binary value in {rsi} to file descriptor {rdi}. 10 | 11 | push rax 12 | push rbp 13 | push rsi 14 | push rdx 15 | 16 | mov rbp,rsp ; save base stack pointer 17 | 18 | ; value is kept in {rsi} and low bits are shifted off, one by one 19 | 20 | ; do all arithmetic in {rax} 21 | 22 | .loop: 23 | 24 | mov al,sil 25 | and al,1 26 | add al,48 ; {al} now contains ascii '0' or '1' corresponding 27 | ; to lowest bit of {rsi} 28 | dec rsp 29 | mov [rsp],al ; move this ascii value into next slot on stack 30 | 31 | shr rsi,1 ; go on to next lowest bit 32 | 33 | test rsi,rsi ; loop until nothing nonzero left 34 | jnz .loop 35 | 36 | ; move leading '0b' onto stack 37 | 38 | dec rsp 39 | mov [rsp],byte 98 40 | 41 | dec rsp 42 | mov [rsp],byte 48 43 | 44 | ; get ready to print 45 | 46 | mov rdx,rbp 47 | sub rdx,rsp ; {rdx} will be length of number in bytes 48 | 49 | mov rsi,rsp ; address of top of red zone 50 | 51 | call print_chars ; print out bytes 52 | 53 | mov rsp,rbp ; restore the stack pointer 54 | 55 | pop rdx 56 | pop rsi 57 | pop rbp 58 | pop rax 59 | 60 | ret ; return 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /lib/io/print_int_o.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_INT_O 2 | %define PRINT_INT_O 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_int_o: 8 | ; void print_int_o(int {rdi}, int {rsi}); 9 | ; Prints octal value in {rsi} to file descriptor {rdi}. 10 | 11 | push rax 12 | push rbp 13 | push rsi 14 | push rdx 15 | 16 | mov rbp,rsp ; save base stack pointer 17 | 18 | ; value is kept in {rsi} and low bits are shifted off, three by three 19 | 20 | ; do all arithmetic in {rax} 21 | 22 | .loop: 23 | 24 | mov al,sil 25 | and al,7 ; {al} contains low nibble of {rsi} 26 | add al,48 ; {al} now correctly contains ascii "0"-"7" 27 | 28 | dec rsp 29 | mov [rsp],al ; move this ascii value into next slot on stack 30 | 31 | shr rsi,3 ; go on to next lowest bit 32 | 33 | test rsi,rsi ; loop until nothing nonzero left 34 | jnz .loop 35 | 36 | ; move leading '0o' onto stack 37 | 38 | dec rsp 39 | mov [rsp],byte 111 40 | 41 | dec rsp 42 | mov [rsp],byte 48 43 | 44 | ; get ready to print 45 | 46 | mov rdx,rbp 47 | sub rdx,rsp ; {rdx} will be length of number in bytes 48 | 49 | mov rsi,rsp ; address of top of red zone 50 | 51 | call print_chars ; print out bytes 52 | 53 | mov rsp,rbp ; restore stack pointer 54 | 55 | pop rdx 56 | pop rsi 57 | pop rbp 58 | pop rax 59 | 60 | ret ; return 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /lib/io/print_int_h_n_digits.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_INT_H_N_DIGITS 2 | %define PRINT_INT_H_N_DIGITS 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_int_h_n_digits: 8 | ; void print_int_h_n_digits(int {rdi}, int {rsi}, uint {rdx}); 9 | ; Prints low {rdx} digits of hexadecimal value in {rsi} to 10 | ; file descriptor {rdi} without leading '0x'. 11 | 12 | push rax 13 | push rbp 14 | push rsi 15 | push rdx 16 | 17 | mov rbp,rsp ; save base stack pointer 18 | 19 | ; value is kept in {rsi} and low bits are shifted off, four by four 20 | 21 | ; do all arithmetic in {rax} 22 | 23 | .loop: 24 | 25 | mov al,sil 26 | and al,15 ; {al} contains low nibble of {rsi} 27 | add al,48 ; {al} now correctly contains ascii "0"-"9" 28 | 29 | cmp al,57 30 | jle .insert_byte 31 | add al,39 ; adjust {al} for ascii "a"-"f" 32 | .insert_byte: 33 | dec rsp 34 | mov [rsp],al ; move this ascii value into next slot on stack 35 | 36 | shr rsi,4 ; go on to next lowest bit 37 | 38 | dec rdx ; loop until out of digits 39 | jnz .loop 40 | 41 | ; get ready to print 42 | 43 | mov rdx,rbp 44 | sub rdx,rsp ; {rdx} will be length of number in bytes 45 | 46 | mov rsi,rsp ; address of top of stack 47 | 48 | call print_chars ; print out bytes 49 | 50 | mov rsp,rbp ; restore stack pointer 51 | 52 | pop rdx 53 | pop rsi 54 | pop rbp 55 | pop rax 56 | 57 | ret ; return 58 | 59 | %endif 60 | -------------------------------------------------------------------------------- /lib/math/parametric/linear_space.asm: -------------------------------------------------------------------------------- 1 | %ifndef LINEAR_SPACE 2 | %define LINEAR_SPACE 3 | 4 | linear_space: 5 | ; bool {rax} linear_space(double* {rdi}, long {rsi}, ulong {rdx} 6 | ; double {xmm0}, double {xmm1}); 7 | ; Writes a linear-spaced array of float values to a memory desination. 8 | ; {rdi} points to first address of destination array 9 | ; {rsi} contains extra stride between elements 10 | ; {rdx} contains number of elements 11 | ; {xmm0} contains first value (low 8-byte double) 12 | ; {xmm1} contains last value (low 8-byte double) 13 | ; Returns {rax}=1 on error, 0 otherwise. 14 | 15 | ; check for positive {rdx} 16 | test rdx,rdx 17 | jz .error 18 | 19 | push rcx 20 | push rdx 21 | sub rsp,48 22 | movdqu [rsp+0],xmm0 23 | movdqu [rsp+16],xmm1 24 | movdqu [rsp+32],xmm2 25 | 26 | ; compute increment between values 27 | mov rcx,rdx 28 | dec rcx 29 | cvtsi2sd xmm2,rcx 30 | subsd xmm1,xmm0 31 | divsd xmm1,xmm2 ; increment in {xmm1} 32 | 33 | ; populate memory with values 34 | .loop: 35 | movq [rdi],xmm0 36 | add rdi,rsi 37 | add rdi,8 38 | addsd xmm0,xmm1 39 | dec rdx 40 | jnz .loop ; fall out when done 41 | 42 | movdqu xmm2,[rsp+32] 43 | movdqu xmm1,[rsp+16] 44 | movdqu xmm0,[rsp+0] 45 | add rsp,48 46 | pop rdx 47 | pop rcx 48 | 49 | ; set {rax}=0 and return 50 | xor rax,rax 51 | ret 52 | 53 | .error: 54 | ; set {rax}=1 and return 55 | mov rax,1 56 | ret 57 | 58 | %endif 59 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_populate.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_POPULATE 2 | %define MATRIX_POPULATE 3 | 4 | matrix_populate: 5 | ; void matrix_populate(double* {rdi}, double* {rsi}, uint {rdx}, uint {rcx}, 6 | ; uint {r8}, uint {r9}); 7 | ; Populates a {rdx}x{rcx} double-precision floating point matrix 8 | ; beginning at address {rdi} with data beginning at address {rsi}, 9 | ; with {r8} bytes between rows of elements and {r9} bytes between 10 | ; columns of elements. 11 | 12 | ; NOTE: this function would work on matrices of any 8-byte datatype. 13 | 14 | push rax 15 | push rdi 16 | push rsi 17 | push rdx 18 | push rcx 19 | 20 | shl rcx,3 ; convert columns to bytewidth of matrix rows 21 | 22 | .loop_rows: 23 | ; {rsi} points to the current row of the source matrix 24 | xor r10,r10 ; {r10} contains offset to column in source matrix 25 | 26 | .loop_cols: ; one element at a time 27 | mov rax,[rsi+r10] ; grab element from source matrix 28 | mov [rdi],rax ; drop element in destination matrix 29 | 30 | add rdi,8 ; move to next element of the destination matrix 31 | add r10,r9 ; increment offset by column "width" 32 | 33 | cmp r10,rcx ; loop until out of columns 34 | jb .loop_cols 35 | 36 | add rsi,r8 ; move to next row of source matrix 37 | dec rdx ; loop until out of rows 38 | jnz .loop_rows 39 | 40 | pop rcx 41 | pop rdx 42 | pop rsi 43 | pop rdi 44 | pop rax 45 | 46 | ret ; return 47 | 48 | %endif 49 | -------------------------------------------------------------------------------- /lib/io/print_delimited_floats.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_DELIMITED_FLOATS 2 | %define PRINT_DELIMITED_FLOATS 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_float.asm" 7 | %include "lib/io/print_float_scientific.asm" 8 | 9 | print_delimited_floats: 10 | ; void print_delimited_floats(uint {rdi}, double* {rsi}, uint {rdx}, uint {rcx}, 11 | ; char {r8b}, void* {r9}); 12 | ; Prints {rdx} elements of double-precision floating-point array starting 13 | ; at address {rsi} to file descriptor {rdi} with {rcx} significant digits 14 | ; in scientific notation with a delimiter byte in {r8b}. 15 | 16 | push rsi 17 | push rdx 18 | push r10 19 | push r11 20 | sub rsp,16 21 | movdqu [rsp],xmm0 22 | 23 | ; drop delimiter into temporary buffer 24 | mov byte [.buffer],r8b 25 | 26 | ; track address of current element in {r10} 27 | mov r10,rsi 28 | 29 | ; track number of elements remaining in {r11} 30 | mov r11,rdx 31 | 32 | jmp .delimiter_printed 33 | 34 | .loop: 35 | 36 | ; print delimiter 37 | mov rsi,.buffer 38 | mov rdx,1 39 | call print_chars 40 | 41 | .delimiter_printed: 42 | 43 | ; print value 44 | movsd xmm0,[r10] 45 | mov rsi,rcx 46 | call r9 47 | 48 | ; go onto next element 49 | add r10,8 50 | dec r11 51 | jnz .loop 52 | 53 | 54 | movdqu xmm0,[rsp] 55 | add rsp,16 56 | pop r11 57 | pop r10 58 | pop rdx 59 | pop rsi 60 | 61 | ret 62 | 63 | .buffer: 64 | db 0 65 | 66 | %endif 67 | -------------------------------------------------------------------------------- /lib/io/print_int_h.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_INT_H 2 | %define PRINT_INT_H 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_int_h: 8 | ; void print_int_h(int {rdi}, int {rsi}); 9 | ; Prints hexadecimal value in {rsi} to file descriptor {rdi}. 10 | 11 | push rax 12 | push rbp 13 | push rsi 14 | push rdx 15 | 16 | mov rbp,rsp ; save base stack pointer 17 | 18 | ; value is kept in {rsi} and low bits are shifted off, four by four 19 | 20 | ; do all arithmetic in {rax} 21 | 22 | .loop: 23 | 24 | mov al,sil 25 | and al,15 ; {al} contains low nibble of {rsi} 26 | add al,48 ; {al} now correctly contains ascii "0"-"9" 27 | 28 | cmp al,57 29 | jle .insert_byte 30 | add al,39 ; adjust {al} for ascii "a"-"f" 31 | .insert_byte: 32 | dec rsp 33 | mov [rsp],al ; move this ascii value into next slot on stack 34 | 35 | shr rsi,4 ; go on to next lowest bit 36 | 37 | test rsi,rsi ; loop until nothing nonzero left 38 | jnz .loop 39 | 40 | ; move leading '0x' onto stack 41 | 42 | dec rsp 43 | mov [rsp],byte 120 44 | 45 | dec rsp 46 | mov [rsp],byte 48 47 | 48 | ; get ready to print 49 | 50 | mov rdx,rbp 51 | sub rdx,rsp ; {rdx} will be length of number in bytes 52 | 53 | mov rsi,rsp ; address of top of stack 54 | 55 | call print_chars ; print out bytes 56 | 57 | mov rsp,rbp ; restore stack pointer 58 | 59 | pop rdx 60 | pop rsi 61 | pop rbp 62 | pop rax 63 | 64 | ret ; return 65 | 66 | %endif 67 | -------------------------------------------------------------------------------- /lib/math/expressions/parse/shunting_yard.asm: -------------------------------------------------------------------------------- 1 | %ifndef SHUNTING_YARD 2 | %define SHUNTING_YARD 3 | 4 | %include "lib/io/parse_float.asm" 5 | ; need function to return numeric / aphabetic tokens; maybe embed that here? 6 | 7 | shunting_yard: 8 | ; void* {rax} shunting_yard(char* {rdi}); 9 | ; Parses the mathematic expression in infix notation starting at {rdi} 10 | ; into postfix notation, returned as as a linked-list structure in {rax}. 11 | ; Returns NULL {rax} on parse error. 12 | 13 | %if 0 14 | .integer: 15 | db 0b00000001 ; type 1 ; TODO, maybe remove integers completely? 16 | dq 0 ; next 17 | dq 0 ; value 18 | .float: 19 | db 0b00000010 ; type 2 20 | dq 0 ; next 21 | dq 0.0 ; value 22 | .power: 23 | dq 0b00000011 ; type 3 24 | dq 0 ; next 25 | db 94 ; ASCII value 26 | db 4 ; precedence 27 | db 1 ; right associativity 28 | .multiplication: 29 | dq 0b00000100 ; type 4 30 | dq 0 ; next 31 | db 42 ; ASCII value 32 | db 3 ; precedence 33 | db 0 ; right associativity 34 | .division: 35 | dq 0b00000101 ; type 5 36 | dq 0 ; next 37 | db 47 ; ASCII value 38 | db 3 ; precedence 39 | db 0 ; right associativity 40 | .addition: 41 | dq 0b00000110 ; type 6 42 | dq 0 ; next 43 | db 43 ; ASCII value 44 | db 2 ; precedence 45 | db 0 ; right associativity 46 | .subtraction: 47 | dq 0b00000111 ; type 7 48 | dq 0 ; next 49 | db 45 ; ASCII value 50 | db 2 ; precedence 51 | db 0 ; right associativity 52 | 53 | %endif 54 | 55 | %endif 56 | -------------------------------------------------------------------------------- /lib/math/vector/max_abs_float.asm: -------------------------------------------------------------------------------- 1 | %ifndef MAX_ABS_FLOAT 2 | %define MAX_ABS_FLOAT 3 | 4 | max_abs_float: 5 | ; double {xmm0} long {rax} max_abs_float(double* {rdi}, long {rsi}, long {rdx}); 6 | ; Returns in {xmm0} the maximum (by absolute value) 8-byte double from the set 7 | ; starting at address {rdi} with extra stride {rsi} and {rdx} elements. 8 | ; Returns ID of first maxima in {rax}, -1 on failure. 9 | 10 | push rdi 11 | push rdx 12 | push rcx 13 | sub rsp,16 14 | movdqu [rsp+0],xmm1 15 | 16 | ; check if at least 1 element 17 | cmp rdx,1 18 | jl .fail 19 | 20 | ; initialize counter 21 | xor rcx,rcx 22 | 23 | ; set abs max to the zeroth element 24 | xor rax,rax 25 | movsd xmm0, qword [rdi] 26 | 27 | pslld xmm0,1 28 | psrld xmm0,1 29 | 30 | ; check if we had only 1 element 31 | cmp rdx,1 32 | je .ret 33 | 34 | dec rdx ; we skip the first one in our loop 35 | 36 | .loop: 37 | inc rcx 38 | add rdi,8 ; go to next element 39 | add rdi,rsi 40 | movsd xmm1, qword [rdi] ; absolute value 41 | pslld xmm1,1 42 | psrld xmm1,1 43 | comisd xmm0,xmm1 ; compare element with max 44 | jae .not_max 45 | movsd xmm0,xmm1 ; new max value 46 | mov rax,rcx ; new max ID 47 | .not_max: 48 | dec rdx 49 | jnz .loop ; continue until done 50 | .ret: 51 | 52 | movdqu xmm1,[rsp+0] 53 | add rsp,16 54 | pop rcx 55 | pop rdx 56 | pop rdx 57 | 58 | ret 59 | 60 | .fail: 61 | mov rax,-1 62 | pxor xmm0,xmm0 63 | jmp .ret 64 | 65 | %endif 66 | -------------------------------------------------------------------------------- /lib/io/print_fixed.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_FIXED 2 | %define PRINT_FIXED 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_int_d.asm" 7 | 8 | print_fixed: 9 | ; void print_fixed(int {rdi}, int {rsi}, int {rdx}); 10 | ; Prints fixed-point value in {rsi} to file descriptor {rdi} 11 | ; with the low {rdx} bits representing the fraction. 12 | 13 | push rsi 14 | push rdx 15 | push rcx 16 | 17 | test rsi,rsi 18 | jns .positive 19 | 20 | ; print "-(" 21 | mov rsi,.grammar+2 22 | mov rdx,2 23 | call print_chars 24 | 25 | mov rsi,[rsp+16] 26 | neg rsi 27 | 28 | .positive: 29 | ; print integer part 30 | mov rcx,[rsp+8] 31 | sar rsi,cl 32 | call print_int_d 33 | 34 | ; print "+" 35 | mov rsi,.grammar 36 | mov rdx,1 37 | call print_chars 38 | 39 | ; print numerator 40 | mov rsi,[rsp+16] 41 | 42 | test rsi,rsi 43 | jns .numerator_inverted 44 | 45 | neg rsi 46 | 47 | .numerator_inverted: 48 | mov rdx,-1 49 | shl rdx,cl 50 | not rdx ; {rdx} mask off integer part 51 | and rsi,rdx 52 | call print_int_d 53 | 54 | ; print "/" 55 | mov rsi,.grammar+1 56 | mov rdx,1 57 | call print_chars 58 | 59 | ; print denominator 60 | mov rsi,1 61 | mov rcx,[rsp+8] 62 | shl rsi,cl 63 | call print_int_d 64 | 65 | mov rsi,[rsp+16] 66 | test rsi,rsi 67 | jns .done 68 | 69 | ; print ")" 70 | mov rsi,.grammar+4 71 | mov rdx,1 72 | call print_chars 73 | 74 | .done: 75 | pop rcx 76 | pop rdx 77 | pop rsi 78 | 79 | ret 80 | 81 | .grammar: 82 | db `+/-()` 83 | 84 | %endif 85 | -------------------------------------------------------------------------------- /lib/math/lin_alg/copy_lower_triangle.asm: -------------------------------------------------------------------------------- 1 | %ifndef COPY_LOWER_TRIANGLE 2 | %define COPY_LOWER_TRIANGLE 3 | 4 | copy_lower_triangle: 5 | ; void copy_lower_triangle(double* {rdi}, double* {rsi}, uint {rdx}); 6 | ; Copies lower triangle of {rdx}x{rdx} matrix at address {rsi} to matrix 7 | ; at address {rdi}. Overwrites the diagonals of the destination matrix. 8 | 9 | push rdi 10 | push rsi 11 | push rax 12 | push rdx 13 | push rcx 14 | push r8 15 | push r9 16 | push r10 17 | push r11 18 | 19 | mov r8,8 ; {r8} tracks running column byte-offset (r8+=8 each iter) 20 | 21 | mov rcx,rdx 22 | shl rcx,3 ; {rcx} contains byte-width of matrix row 23 | 24 | ; {rsi} tracks current row start address in source matrix 25 | ; {rdi} tracks current row start address in destination matrix 26 | ; {r11} tracks running column byte offset in the column loop 27 | 28 | .loop_rows: 29 | mov r9,rsi 30 | mov r10,rdi 31 | xor r11,r11 32 | 33 | .loop_cols: 34 | mov rax, qword [r9] 35 | mov [r10],rax 36 | add r9,8 37 | add r10,8 38 | add r11,8 39 | 40 | cmp r11,r8 41 | jb .loop_cols ; continue to end of the row 42 | 43 | add rsi,rcx ; proceed to next row in source matrix 44 | add rdi,rcx ; proceed to next row in destination matrix 45 | add r8,8 ; shift 1 column to right in starting byte-offset 46 | 47 | cmp r8,rcx 48 | jbe .loop_rows ; continue to end of matrices 49 | 50 | pop r11 51 | pop r10 52 | pop r9 53 | pop r8 54 | pop rcx 55 | pop rdx 56 | pop rax 57 | pop rsi 58 | pop rdi 59 | 60 | ret 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_rect.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_RECT 2 | %define SET_RECT 3 | 4 | ; dependency 5 | %include "lib/io/bitmap/set_line.asm" 6 | %include "lib/io/bitmap/set_pixel.asm" 7 | 8 | set_rect: 9 | ; void set_rect(void* {rdi}, int {rsi}, int {edx}, int {ecx}, 10 | ; int {r8d}, int {r9d}, int {r10d}, int {r11d}); 11 | ; Draws rectangle from ({r8d},{r9d}) to ({r10d},{r11d}) (from (0,0) 12 | ; @ top-left) in ARGB data array starting at {rdi} for an 13 | ; {edx}x{ecx} (WxH) image with a border color in the low 32 bits of 14 | ; {rsi} 15 | ; REMOVED: "and a fill color in the high 32 bits of {rsi}." 16 | 17 | push r8 18 | push r9 19 | push r10 20 | push r11 21 | 22 | ; line from (x0,y0) to (x1,y0) 23 | mov r11,[rsp+16] 24 | call set_line 25 | 26 | ; line from (x1,y1) to (x1,y0) 27 | mov r8,[rsp+8] 28 | mov r9,[rsp] 29 | call set_line 30 | 31 | ; line from (x1,y1) to (x0,y1) 32 | mov r10,[rsp+24] 33 | mov r11,[rsp] 34 | call set_line 35 | 36 | ; line from (x0,y0) to (x0,y1) 37 | mov r8,[rsp+24] 38 | mov r9,[rsp+16] 39 | call set_line 40 | 41 | %if 0 ; REMOVED! 42 | mov r10,[rsp+8] 43 | dec r11 44 | 45 | push rsi 46 | shr rsi,33; skip the inversion bit on fill check 47 | test rsi,rsi 48 | jz .ret 49 | 50 | .loop_rows: 51 | inc r9 52 | mov r8,[rsp+32] 53 | inc r8 54 | .loop_cols: 55 | call set_pixel 56 | inc r8 57 | cmp r8,r10 58 | jl .loop_cols 59 | cmp r9,r11 60 | jl .loop_rows 61 | %endif 62 | 63 | .ret: 64 | ; push rsi 65 | pop r11 66 | pop r10 67 | pop r9 68 | pop r8 69 | ret 70 | 71 | %endif 72 | -------------------------------------------------------------------------------- /lib/math/vector/perpendicularize_3.asm: -------------------------------------------------------------------------------- 1 | %ifndef PERPENDICULARIZE_3 2 | %define PERPENDICULARIZE_3 3 | 4 | perpendicularize_3: 5 | ; void perpendicularize_3(double* {rdi}, double* {rsi}); 6 | ; Makes the 3x1 double vector starting at {rdi} perpendicular to 7 | ; the 3x1 double vector starting at {rsi} (in-place). 8 | 9 | sub rsp,64 10 | movdqu [rsp],xmm0 11 | movdqu [rsp+16],xmm1 12 | movdqu [rsp+32],xmm2 13 | movdqu [rsp+32],xmm2 14 | movdqu [rsp+48],xmm3 15 | 16 | movsd xmm0,[rsi+0] 17 | mulsd xmm0,[rdi+0] 18 | movsd xmm1,[rsi+8] 19 | mulsd xmm1,[rdi+8] 20 | movsd xmm2,[rsi+16] 21 | mulsd xmm2,[rdi+16] 22 | addsd xmm0,xmm1 23 | addsd xmm0,xmm2 24 | movsd xmm3,xmm0 ; {xmm3} = U dot V 25 | 26 | movsd xmm0,[rsi+0] 27 | mulsd xmm0,xmm0 28 | movsd xmm1,[rsi+8] 29 | mulsd xmm1,xmm1 30 | movsd xmm2,[rsi+16] 31 | mulsd xmm2,xmm2 32 | addsd xmm0,xmm1 33 | addsd xmm0,xmm2 ; {xmm0} = V dot V 34 | 35 | divsd xmm3,xmm0 ; {xmm3} = (U dot V) / (V dot V) 36 | 37 | ; U = U - [(U dot V) / (V dot V)] * V 38 | movsd xmm0,[rsi+0] 39 | movsd xmm1,[rsi+8] 40 | movsd xmm2,[rsi+16] 41 | mulsd xmm0,xmm3 42 | mulsd xmm1,xmm3 43 | mulsd xmm2,xmm3 44 | movsd xmm3,[rdi+0] 45 | subsd xmm3,xmm0 46 | movsd [rdi+0],xmm3 47 | movsd xmm3,[rdi+8] 48 | subsd xmm3,xmm1 49 | movsd [rdi+8],xmm3 50 | movsd xmm3,[rdi+16] 51 | subsd xmm3,xmm2 52 | movsd [rdi+16],xmm3 53 | 54 | movdqu xmm0,[rsp] 55 | movdqu xmm1,[rsp+16] 56 | movdqu xmm2,[rsp+32] 57 | movdqu xmm3,[rsp+48] 58 | add rsp,64 59 | 60 | ret ; return 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /lib/math/rand/rand_float_array.asm: -------------------------------------------------------------------------------- 1 | %ifndef RAND_FLOAT_ARRAY 2 | %define RAND_FLOAT_ARRAY 3 | 4 | rand_float_array: 5 | ; void rand_float_array(double {xmm0}, double {xmm1}, double* {rdi}, 6 | ; int {rsi}, int {rdx}); 7 | ; Populates a {rdx}-element array starting at {rdi} with an offset of (8+{rsi}) 8 | ; bytes between elements with double-precision floating point numbers 9 | ; such that {xmm0} <= values <= {xmm1}. 10 | 11 | push rax 12 | push rdi 13 | push rdx 14 | 15 | sub rsp,32 16 | movdqu [rsp+16],xmm2 17 | movdqu [rsp+0],xmm1 18 | 19 | subsd xmm1,xmm0 ; range in {xmm1} 20 | 21 | .loop: 22 | rdrand rax ; random 64-bit value in {rax} 23 | jnc .loop ; this doesn't seem to be necessary, but we will put it 24 | ; anyway. wait for the carry flag to be set, 25 | ; indicating we have a valid random number in {rax} 26 | 27 | shr rax,1 ; positives only 28 | cvtsi2sd xmm2,rax ; random 64-bit value in {xmm2} 29 | mulsd xmm2,[.tiny] ; convert our number with a very small increment 30 | 31 | mulsd xmm2,xmm1 ; extend the float over the entire range 32 | addsd xmm2,xmm0 ; offset the float by the minimum value 33 | 34 | movsd [rdi],xmm2; place this element in the array 35 | add rdi,8 ; move onto the next target address 36 | add rdi,rsi 37 | 38 | dec rdx 39 | jnz .loop 40 | 41 | movdqu xmm2,[rsp+16] 42 | movdqu xmm1,[rsp+0] 43 | add rsp,32 44 | 45 | pop rdx 46 | pop rdi 47 | pop rax 48 | 49 | ret ; return 50 | 51 | .tiny: 52 | dq 0x3c00000000000000 ; (1/2)^63 to convert our int to float 53 | 54 | %endif 55 | -------------------------------------------------------------------------------- /aarch64/lib/SYS/UNLINK.S: -------------------------------------------------------------------------------- 1 | .IFNDEF UNLINK 2 | .EQU UNLINK,1 3 | 4 | .INCLUDE "SYS/HELPER.S" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | .MACRO __UNLINK 10 | 11 | _PUSH_VOLATILES 12 | 13 | MOV X0,SYS_AT_FDCWD 14 | LDR X1,[SP,VOLATILE_LENGTH+0] 15 | 16 | BL UNLINK 17 | 18 | _POP_VOLATILES 19 | 20 | .ENDM 21 | 22 | .MACRO _UNLINK PATH 23 | 24 | SUB SP,SP,16 25 | MOV X20,\PATH 26 | STR X20,[SP,0] 27 | 28 | __UNLINK 29 | 30 | ADD SP,SP,16 31 | 32 | .ENDM 33 | 34 | .IFDEF VERBOSE_LOGS 35 | 36 | .INCLUDE "IO/LOG_TEXT.S" 37 | 38 | 1: .ASCII "ATTEMPTING TO UNLINK '" 39 | 2: .ASCII "'. " 40 | 3: .ASCII "FAIL. \n" 41 | 4: .ASCII "SUCCESS.\n" 42 | 43 | .ENDIF 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | /////////////////////////////////////////////////////////////////////////////// 47 | 48 | .ALIGN 2 49 | 50 | UNLINK: // UNLINK({W0}, {X1}); 51 | 52 | .IFDEF VERBOSE_LOGS 53 | 54 | SUB SP,SP,32 55 | STP X0,X1,[SP,0] 56 | STR LR,[SP,16] 57 | _LOG_TEXT 1b 22 58 | LDP X0,X1,[SP,0] 59 | _LOG_NULL_TERM_STRING X1 60 | _LOG_TEXT 2b,3 61 | LDP X0,X1,[SP,0] 62 | LDR LR,[SP,16] 63 | ADD SP,SP,32 64 | 65 | .ENDIF 66 | 67 | ADD X1,X1,LOAD_ADDRESS 68 | MOV W8, SYS_UNLINK 69 | SVC 0 70 | 71 | .IFDEF VERBOSE_LOGS 72 | 73 | ADD X0,X0,1 74 | MOV X1,9 75 | MUL X0,X0,X1 76 | ADD X0,X0,3b 77 | _LOG_TEXT X0,9 78 | 79 | .ENDIF 80 | 81 | RET 82 | 83 | .ENDIF 84 | -------------------------------------------------------------------------------- /lib/io/parse_int.asm: -------------------------------------------------------------------------------- 1 | %ifndef PARSE_INT 2 | %define PARSE_INT 3 | 4 | parse_int: 5 | ; int {rax} parse_int(char* {rdi}); 6 | ; Returns in {rax} the value of null-terminated char array starting at 7 | ; {rdi}. 8 | ; NOTE: Hex numbers must include the lower-case 9 | ; alphabetic characters (0xabcdef) 10 | ; Beware: garbage in, garbage out 11 | 12 | push rdi 13 | push r8 14 | push rcx 15 | push rbx 16 | 17 | ; get radix (base 16,10,8,2). 18 | movzx rbx, byte [rdi+1] 19 | xor rax,rax 20 | xor r8,r8 21 | 22 | cmp rbx,120 ; second digit = x 23 | je .hexadecimal 24 | cmp rbx,98 ; second digit = b 25 | je .binary 26 | cmp rbx,111 ; second digit = o 27 | je .octal 28 | mov rcx,10 ; decimal radix 29 | movzx rbx, byte [rdi] 30 | cmp rbx,45 31 | jne .loop 32 | inc rdi 33 | inc r8 ; flag to indicate negative 34 | jmp .loop 35 | .hexadecimal: 36 | mov rcx,16 ; hexadecimal radix 37 | add rdi,2 38 | jmp .loop 39 | .octal: 40 | mov rcx,8 ; octal radix 41 | add rdi,2 42 | jmp .loop 43 | .binary: 44 | mov rcx,2 ; binary radix 45 | add rdi,2 46 | .loop: 47 | movzx rbx, byte [rdi] ; grab current byte 48 | sub rbx,48 49 | cmp rbx,9 50 | jbe .not_hex 51 | sub rbx,39 52 | .not_hex: 53 | imul rcx 54 | add rax,rbx 55 | 56 | inc rdi 57 | cmp byte [rdi],0 ; check if the byte is null 58 | jne .loop ; if not, try the next one 59 | 60 | test r8,r8 ; handle negatives for base-10 61 | jz .done 62 | mov rcx,-1 63 | imul rcx 64 | 65 | .done: 66 | pop rbx 67 | pop rcx 68 | pop r8 69 | pop rdi 70 | 71 | ret 72 | 73 | %endif 74 | -------------------------------------------------------------------------------- /lib/math/matrix/matrix_transpose.asm: -------------------------------------------------------------------------------- 1 | %ifndef MATRIX_TRANSPOSE 2 | %define MATRIX_TRANSPOSE 3 | 4 | matrix_transpose: 5 | ; void matrix_transpose(double* {rdi}, double* {rsi}, uint {rdx}, uint {rcx}); 6 | ; Transposes {rdx}x{rcx} double-precision floating point matrix beginning 7 | ; at {rsi} into the {rcx}x{rdx} matrix starting at address {rdi}. 8 | 9 | ; NOTE: should work on matrices of any 8-byte datatype. 10 | 11 | push rdi 12 | push rsi 13 | push rax 14 | push rbx 15 | push rcx 16 | push r8 17 | push r9 18 | push r10 19 | 20 | mov r9,rcx 21 | imul r9,rdx 22 | shl r9,3 ; {r9} points past the last element of 23 | add r9,rsi ; the source matrix 24 | 25 | mov r8,rcx ; set row counter in {r8} 26 | mov r10,rdx 27 | shl r10,3 ; convert {r10} into byte-width 28 | mov rbx,rdi ; set {rbx} to start of destination matrix 29 | 30 | .loop: 31 | mov rax,[rsi] ; grab element from source matrix 32 | mov [rbx],rax ; drop element into destination matrix 33 | add rsi,8 ; increment element in source matrix 34 | add rbx,r10 ; move to next row in destination matrix 35 | 36 | dec r8 ; loop until out of rows 37 | jnz .loop 38 | 39 | cmp rsi,r9 ; quit when out of elements 40 | jge .done 41 | 42 | mov r8,rcx ; reset row counter 43 | add rdi,8 ; move to next column of destination matrix 44 | mov rbx,rdi ; set {rsi} to next column of destination matrix 45 | 46 | jmp .loop 47 | 48 | .done: 49 | pop r10 50 | pop r9 51 | pop r8 52 | pop rcx 53 | pop rbx 54 | pop rax 55 | pop rsi 56 | pop rdi 57 | 58 | ret ; return 59 | 60 | %endif 61 | -------------------------------------------------------------------------------- /lib/io/print_memory.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_MEMORY 2 | %define PRINT_MEMORY 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_int_h.asm" 7 | %include "lib/io/print_int_d.asm" 8 | %include "lib/io/print_int_o.asm" 9 | %include "lib/io/print_int_b.asm" 10 | 11 | print_memory: 12 | ; void print_memory(int {rdi}, byte* {rsi}, void* {rdx}, int {rcx}); 13 | ; Prints {rcx} bytes from memory starting at {rsi} to file descriptor {rdi}. 14 | ; {rdx} points to the function to print integers in the desired format. 15 | 16 | push rsi 17 | push rax 18 | push rbx 19 | push rcx 20 | push rdx 21 | push rbp 22 | push r8 23 | 24 | mov rbp,rsi ; save initial memory location in {rbp} 25 | mov rbx,rdx ; save function pointer in {rbx} 26 | 27 | .outer_loop: 28 | 29 | ; print memory location 30 | mov rsi,rbp 31 | call print_int_h 32 | 33 | ; print `:` 34 | mov rsi,.grammar 35 | mov rdx,1 36 | call print_chars 37 | 38 | mov r8,8 ; 8 bytes per line 39 | 40 | .inner_loop: 41 | 42 | ; print ` ` 43 | mov rsi,.grammar+1 44 | mov rdx,1 45 | call print_chars 46 | 47 | ; print byte 48 | movzx rsi,byte [rbp] 49 | call rbx 50 | 51 | ; go onto next byte 52 | inc rbp 53 | dec rcx 54 | dec r8 55 | jnz .inner_loop 56 | 57 | ; print newline 58 | mov rsi,.grammar+2 59 | mov rdx,1 60 | call print_chars 61 | 62 | cmp rcx,0 63 | jg .outer_loop 64 | 65 | pop r8 66 | pop rbp 67 | pop rdx 68 | pop rcx 69 | pop rbx 70 | pop rax 71 | pop rsi 72 | 73 | ret ; return 74 | 75 | .grammar: 76 | db `: \n` 77 | 78 | %endif 79 | -------------------------------------------------------------------------------- /lib/math/lin_alg/copy_upper_triangle.asm: -------------------------------------------------------------------------------- 1 | %ifndef COPY_UPPER_TRIANGLE 2 | %define COPY_UPPER_TRIANGLE 3 | 4 | copy_upper_triangle: 5 | ; void copy_upper_triangle(double* {rdi}, double* {rsi}, uint {rdx}); 6 | ; Copies upper triangle of {rdx}x{rdx} matrix at address {rsi} to matrix 7 | ; at address {rdi}. Overwrites the diagonals of the destination matrix. 8 | 9 | push rdi 10 | push rsi 11 | push rax 12 | push rdx 13 | push rcx 14 | push r8 15 | push r9 16 | push r10 17 | push r11 18 | 19 | xor r8,r8 ; {r8} tracks running column byte-offset (r8+=8 each iter) 20 | 21 | mov rcx,rdx 22 | shl rcx,3 ; {rcx} contains byte-width of matrix row 23 | 24 | ; {rsi} tracks current row start address in source matrix 25 | ; {rdi} tracks current row start address in destination matrix 26 | ; {r11} tracks running column byte offset in the column loop 27 | 28 | .loop_rows: 29 | mov r9,r8 30 | add r9,rsi 31 | mov r10,r8 32 | add r10,rdi 33 | mov r11,r8 34 | 35 | .loop_cols: 36 | mov rax, qword [r9] 37 | mov [r10],rax 38 | add r9,8 39 | add r10,8 40 | add r11,8 41 | 42 | cmp r11,rcx 43 | jb .loop_cols ; continue to end of the row 44 | 45 | add rsi,rcx ; proceed to next row in source matrix 46 | add rdi,rcx ; proceed to next row in destination matrix 47 | add r8,8 ; shift 1 column to right in starting byte-offset 48 | 49 | cmp r8,rcx 50 | jb .loop_rows ; continue to end of matrices 51 | 52 | pop r11 53 | pop r10 54 | pop r9 55 | pop r8 56 | pop rcx 57 | pop rdx 58 | pop rax 59 | pop rsi 60 | pop rdi 61 | 62 | ret 63 | 64 | %endif 65 | -------------------------------------------------------------------------------- /lib/io/print_int_d.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_INT_D 2 | %define PRINT_INT_D 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | print_int_d: 8 | ; void print_int_d(int {rdi}, int {rsi}); 9 | ; Prints decimal value in {rsi} to file descriptor {rdi}. 10 | 11 | push rax 12 | push rbp 13 | push rsi 14 | push rdx 15 | push r8 16 | 17 | mov r8,rsi ; save original value in {r8} 18 | mov rax,rsi 19 | test rax,rax 20 | jns .positive 21 | neg rax 22 | .positive: 23 | mov rsi,10 ; divisor for decimal system 24 | mov rbp,rsp ; save base stack pointer 25 | 26 | ; value is kept in {rax} and is divided by 10 successively 27 | 28 | .loop: 29 | xor rdx,rdx ; zero out {rdx} before division 30 | div rsi ; divides full value in {rax} by 10 31 | ; remainder in {rdx} ; dl = 0-9 32 | ; result in {rax} for next time 33 | 34 | add dl,48 ; {dl} now correctly contains ascii "0"-"9" 35 | 36 | dec rsp 37 | mov [rsp],dl ; move this ascii value into next slot on stack 38 | 39 | test rax,rax ; loop until nothing nonzero left 40 | jnz .loop 41 | 42 | test r8,r8 43 | jns .no_neg_sign 44 | dec rsp 45 | mov [rsp],byte 45 ; add leading negative sign if necessary 46 | 47 | .no_neg_sign: 48 | ; get ready to print 49 | 50 | mov rdx,rbp 51 | sub rdx,rsp ; {rdx} will be length of number in bytes 52 | 53 | mov rsi,rsp ; address of top of red zone 54 | 55 | call print_chars ; print out bytes 56 | 57 | mov rsp,rbp ; restore stack pointer 58 | 59 | pop r8 60 | pop rdx 61 | pop rsi 62 | pop rbp 63 | pop rax 64 | 65 | ret ; return 66 | 67 | %endif 68 | -------------------------------------------------------------------------------- /lib/math/integration/trapezoidal_method.asm: -------------------------------------------------------------------------------- 1 | %ifndef TRAPEZOIDAL_METHOD 2 | %define TRAPEZOIDAL_METHOD 3 | 4 | trapezoidal_method: 5 | ; double {xmm0} trapezoidal_method(void* {rdi}, ulong {rsi}, double {xmm0}, double {xmm1}); 6 | ; Estimates the definite integral of the function at address {rdi} between {xmm0}<=x<={xmm1} 7 | ; using a trapezoidal method with {rsi} steps. Area returned in {xmm0}. 8 | ; Dear user, please don't pass in bogus values for {rsi}, thanks. 9 | ; Function of interest should take independent variable and returns dependend variable in {xmm0}. 10 | 11 | push rsi 12 | sub rsp,64 13 | movdqu [rsp+0],xmm3 14 | movdqu [rsp+16],xmm4 15 | movdqu [rsp+32],xmm5 16 | movdqu [rsp+48],xmm6 17 | 18 | cvtsi2sd xmm3,rsi 19 | movsd xmm2,xmm1 20 | subsd xmm2,xmm0 21 | divsd xmm2,xmm3 22 | ; step size in {xmm2} 23 | 24 | movsd xmm3,xmm0 ; x val track 25 | pxor xmm4,xmm4 ; track sum 26 | 27 | call rdi 28 | movsd xmm5,xmm0 ; LHS in xmm5 29 | addsd xmm3,xmm2 30 | 31 | .loop: 32 | movsd xmm0,xmm3 33 | call rdi 34 | 35 | movsd xmm6,xmm0 ; RHS in xmm6 36 | addsd xmm0,xmm5 ; LHS+RHS 37 | mulsd xmm0,[.half] ; (LHS+RHS)/2 38 | mulsd xmm0,xmm2 ; (LHS+RHS)*step/2 39 | addsd xmm4,xmm0 ; add to running sum 40 | 41 | movsd xmm5,xmm6 ; LHS <- RHS 42 | addsd xmm3,xmm2 ; increment x val 43 | dec rsi 44 | jnz .loop 45 | 46 | .ret: 47 | movsd xmm0,xmm4 48 | movdqu xmm3,[rsp+0] 49 | movdqu xmm4,[rsp+16] 50 | movdqu xmm5,[rsp+32] 51 | movdqu xmm6,[rsp+48] 52 | add rsp,64 53 | pop rsi 54 | 55 | ret ; return 56 | 57 | .half: 58 | dq 0.50 59 | 60 | %endif 61 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_filled_polygon.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_FILLED_POLYGON 2 | %define SET_FILLED_POLYGOM 3 | 4 | ; dependency 5 | %include "lib/io/bitmap/set_pixel.asm" 6 | %include "lib/math/int/max_int.asm" 7 | %include "lib/math/int/min_int.asm" 8 | 9 | set_filled_polygon: 10 | ; void set_filled_polygon(void* {rdi}, int {rsi}, int {edx}, int {ecx}, 11 | ; long* {r8}, int {r9}); 12 | ; Draws filled polygon with {r9} vertices in 2*{r9} length long (8-byte) int array at {r8} 13 | ; to ARGB data array starting at {rdi} for an 14 | ; {edx}x{ecx} (WxH) image with a fill color in the low 32 bits of {rsi}. 15 | 16 | push r8 17 | push r9 18 | push r10 19 | push r11 20 | push r12 21 | push r13 22 | push rax 23 | 24 | ; find min and max y values 25 | 26 | push rdi 27 | push rsi 28 | push rdx 29 | 30 | mov rdi,r9 31 | mov rsi,r8 32 | add rsi,8 33 | mov rdx,8 34 | call min_int 35 | mov r10,rax ; min y in r10 36 | 37 | mov rdx,8 38 | call max_int 39 | mov r11,rax ; max y in r11 40 | 41 | pop rdx 42 | pop rsi 43 | pop rdi 44 | 45 | ; loop thru y rows low to high 46 | .loop: 47 | mov r12,r8 48 | add r12,8 ; {r12} to 0th y 49 | ; check if and where last edge instersects y 50 | mov rax,r9 51 | dec rax 52 | shl rax,4 53 | add rax,r12 ; {rax} to N-1th y 54 | 55 | 56 | .first_pt_ 57 | ; loop thru edges to see if and where they cross the current y value 58 | .edge_loop: 59 | 60 | 61 | add r12, 62 | 63 | inc r10 64 | cmp r10,r11 65 | jle .loop 66 | 67 | .ret: 68 | pop rax 69 | pop r13 70 | pop r12 71 | pop r11 72 | pop r10 73 | pop r9 74 | pop r8 75 | ret 76 | 77 | %endif 78 | -------------------------------------------------------------------------------- /lib/math/root_finding/newtons_method.asm: -------------------------------------------------------------------------------- 1 | %ifndef NEWTONS_METHOD 2 | %define NEWTONS_METHOD 3 | 4 | newtons_method: 5 | ; ulong {rax}, double {xmm0} newtons_method(void* {rdi}, void* {rsi}, 6 | ; double {xmm0}, double {xmm1}); 7 | ; Uses Newton's method to find a root for the single-variable 8 | ; function at address {rdi}, with slope function at address {rsi} 9 | ; with initial guess {xmm0} to within tolerance {xmm1}. 10 | ; On fail, {rax}=0. On success, the root is returned 11 | ; in {xmm0}, and {rax} contains the number of iterations. 12 | ; 13 | ; The functions of interest at {rdi} and {rsi} should be of the form: 14 | ; double {xmm0} func(double {xmm0}); 15 | ; and should not affect any registers besides {xmm0}. 16 | 17 | sub rsp,48 18 | movdqu [rsp+0],xmm2 19 | movdqu [rsp+16],xmm3 20 | movdqu [rsp+32],xmm4 21 | 22 | xor rax,rax ; count number of iterations in {rax} 23 | 24 | ; new x in {xmm3} 25 | ; old x in {xmm4} (used for tolerance) 26 | ; current f(x) in {xmm2} 27 | ; current f'(x) in {xmm0} 28 | 29 | movsd xmm3,xmm0 30 | jmp .start 31 | 32 | .loop: 33 | 34 | subsd xmm4,xmm3 35 | 36 | pslld xmm4,1 37 | psrld xmm4,1 38 | comisd xmm4,xmm1 39 | jbe .ret 40 | 41 | .start: 42 | 43 | movsd xmm0,xmm3 44 | call rdi 45 | movsd xmm2,xmm0 ; {xmm2} = f(x); 46 | 47 | movsd xmm0,xmm3 48 | call rsi 49 | 50 | divsd xmm2,xmm0 ; f(x)/f'(x) 51 | movsd xmm4,xmm3 ; old x 52 | subsd xmm3,xmm2 ; new x 53 | 54 | inc rax 55 | 56 | jmp .loop 57 | 58 | .ret: 59 | movsd xmm0,xmm3 60 | movdqu xmm2,[rsp+0] 61 | movdqu xmm3,[rsp+16] 62 | movdqu xmm4,[rsp+32] 63 | add rsp,48 64 | 65 | ret ; return 66 | 67 | %endif 68 | -------------------------------------------------------------------------------- /lib/io/print_stack.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_STACK 2 | %define PRINT_STACK 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | %include "lib/io/print_int_h.asm" 7 | %include "lib/io/print_int_d.asm" 8 | %include "lib/io/print_int_o.asm" 9 | %include "lib/io/print_int_b.asm" 10 | 11 | print_stack: 12 | ; void print_stack(int {rdi}, int {rsi}, void* {rdx}); 13 | ; Prints stack contents starting at {rsi} quadwords above the stack pointer to 14 | ; file descriptor {rdi}. {rdx} points to the function used to print 15 | ; integers in the desired format. 16 | 17 | push rsi 18 | push rax 19 | push rbx 20 | push rcx 21 | push rdx 22 | push rbp 23 | 24 | mov rbp,rsi ; {rbp} tracks the offset to the current value to print 25 | shl rbp,3 ; convert {rbp} to bytes 26 | mov rcx,rbp ; {rcx} contains the byte offset from the stack 27 | add rbp,rsp ; offset {rbp} by the stack pointer 28 | add rbp,48 ; offset by the callee-saved registers 29 | mov rbx,rdx ; {rbx} contains function pointer to call 30 | 31 | .loop: 32 | ; print `\n[rsp+` 33 | mov rsi,.grammar 34 | mov rdx,6 35 | call print_chars 36 | 37 | ; print number 38 | mov rsi,rcx 39 | call print_int_d 40 | 41 | ; print `]:\t` 42 | mov rsi,.grammar+6 43 | mov rdx,3 44 | call print_chars 45 | 46 | ; print value 47 | mov rsi,[rbp] 48 | call rbx 49 | 50 | ; loop until at the stack pointer 51 | sub rbp,8 52 | sub rcx,8 53 | jns .loop 54 | 55 | ; print last newline 56 | mov rsi,.grammar 57 | mov rdx,1 58 | call print_chars 59 | 60 | pop rbp 61 | pop rdx 62 | pop rcx 63 | pop rbx 64 | pop rax 65 | pop rsi 66 | 67 | ret ; return 68 | 69 | .grammar: 70 | db `\n[rsp+]:\t` 71 | 72 | %endif 73 | -------------------------------------------------------------------------------- /lib/debug/debug_master_start.asm: -------------------------------------------------------------------------------- 1 | %ifndef DEBUG_MASTER_START 2 | %define DEBUG_MASTER_START 3 | 4 | ; dependency 5 | %include "lib/io/print_chars.asm" 6 | 7 | debug_master_start: 8 | ; void debug_master_start(void); 9 | ; Begins tracking quantities for debugging purposes. 10 | ; Records GP (and stack pointer) and XMM register state & timestamp. 11 | 12 | ; save GP registers 13 | mov [.GP_regs+0],rax 14 | mov [.GP_regs+8],rbx 15 | mov [.GP_regs+16],rcx 16 | mov [.GP_regs+24],rdx 17 | mov [.GP_regs+32],rdi 18 | mov [.GP_regs+40],rsi 19 | mov [.GP_regs+48],rsp 20 | mov [.GP_regs+56],rbp 21 | mov [.GP_regs+64],r8 22 | mov [.GP_regs+72],r9 23 | mov [.GP_regs+80],r10 24 | mov [.GP_regs+88],r11 25 | mov [.GP_regs+96],r12 26 | mov [.GP_regs+104],r13 27 | mov [.GP_regs+112],r14 28 | mov [.GP_regs+120],r15 29 | 30 | ; save XMM registers 31 | movdqu [.XMM_regs+0],xmm0 32 | movdqu [.XMM_regs+16],xmm1 33 | movdqu [.XMM_regs+32],xmm2 34 | movdqu [.XMM_regs+48],xmm3 35 | movdqu [.XMM_regs+64],xmm4 36 | movdqu [.XMM_regs+80],xmm5 37 | movdqu [.XMM_regs+96],xmm6 38 | movdqu [.XMM_regs+112],xmm7 39 | movdqu [.XMM_regs+128],xmm8 40 | movdqu [.XMM_regs+144],xmm9 41 | movdqu [.XMM_regs+160],xmm10 42 | movdqu [.XMM_regs+176],xmm11 43 | movdqu [.XMM_regs+192],xmm12 44 | movdqu [.XMM_regs+208],xmm13 45 | movdqu [.XMM_regs+224],xmm14 46 | movdqu [.XMM_regs+240],xmm15 47 | 48 | 49 | 50 | 51 | 52 | ret ; return 53 | 54 | .GP_regs: 55 | times 16 dq 0 ; 16 quadwords for the normal registers 56 | 57 | .XMM_regs: 58 | times 32 dq 0 ; 32 quadwords for the XMM registers 59 | 60 | .timestamp: 61 | dq 0 ; seconds 62 | dq 0 ; microseconds 63 | %endif 64 | -------------------------------------------------------------------------------- /make_bins.sh: -------------------------------------------------------------------------------- 1 | # create bin directory if it doesn't exist 2 | mkdir -p bin 3 | 4 | echo "'make_executable abc' = 'chmod +x abc' 5 | 'spawn abc' = 'touch abc' 6 | 'recycle abc' = 'rm abc' 7 | 'nyancat abc' = 'cat abc' 8 | 'list' = 'ls' 9 | 'dump abc' = 'xxd abc' = 'hexdump -C abc' 10 | 'countdown 5' -> 5 sec countdown timer" > bin/bins.md 11 | 12 | # generate "make_executable" aka "chmod +x" 13 | nasm -f bin -I lib/sys/`uname` -o bin/make_executable ex/ex003_command_line_args_and_code_golf/ex003b_chmod_smaller/code.asm 14 | chmod +x bin/make_executable 15 | 16 | # generate "spawn" aka "touch" 17 | nasm -f bin -I lib/sys/`uname` -o bin/spawn ex/ex003_command_line_args_and_code_golf/ex003d_touch_smaller/code.asm 18 | chmod +x bin/spawn 19 | 20 | # generate "recycle" aka "rm" 21 | nasm -f bin -I lib/sys/`uname` -o bin/recycle ex/ex003_command_line_args_and_code_golf/ex003f_rm_smaller/code.asm 22 | chmod +x bin/recycle 23 | 24 | # generate "nyancat" aka "cat" 25 | nasm -f bin -I lib/sys/`uname` -o bin/nyancat ex/ex004_printing_strings/ex004d_nyancat/code.asm 26 | chmod +x bin/nyancat 27 | 28 | # generate "countdown" aka a countdown timer 29 | nasm -f bin -I lib/sys/`uname` -o bin/countdown lab/lab004_countdown_timer/code.asm 30 | chmod +x bin/countdown 31 | 32 | # generate "list" aka "ls" 33 | nasm -f bin -I lib/sys/`uname` -o bin/list lab/lab006_ls/code.asm 34 | chmod +x bin/list 35 | 36 | # generate "dump" aka "xxd" aka "hexdump" 37 | nasm -f bin -I lib/sys/`uname` -o bin/dump lab/lab005_hexdump/code.asm 38 | chmod +x bin/dump 39 | 40 | # generate "rpn" aka a calculator 41 | nasm -f bin -I lib/sys/`uname` -o bin/rpn ex/ex030_postfix_notation/ex30a_evaluate_postfix/code.asm 42 | chmod +x bin/rpn 43 | -------------------------------------------------------------------------------- /lib/math/lin_alg/is_diagonal.asm: -------------------------------------------------------------------------------- 1 | %ifndef IS_DIAGONAL 2 | %define IS_DIAGONAL 3 | 4 | is_diagonal: 5 | ; bool {rax} is_diagonal(double* {rdi}, uint {rsi}, double {xmm0}); 6 | ; Returns {rax}=1 if {rsi}x{rsi} matrix at address {rdi} is diagonal. 7 | ; Values within tolerance {xmm0} are considered zero. 8 | 9 | ; Algorithm: 10 | ; Iterate over all elements checking for zeros in non-diagonal spots. 11 | 12 | push rdi 13 | push rsi 14 | push rcx 15 | push rdx 16 | sub rsp,16 17 | movdqu [rsp+0],xmm1 18 | 19 | cmp rsi,1 20 | je .yes_diagonal 21 | 22 | ; convert rsi to indicate the byte-width between diagonal elements 23 | ; and rdx to indicate address beyond the matrix 24 | mov rdx,rsi 25 | shl rsi,3 26 | imul rdx,rsi 27 | add rdx,rdi 28 | add rsi,8 29 | sub rdx,8 30 | 31 | ; use rcx to track address of next diagonal element 32 | mov rcx,rdi 33 | add rcx,rsi 34 | 35 | ; use rdi to track current element, skipping first element 36 | add rdi,8 37 | 38 | ; implement algorithm described above 39 | .loop: 40 | ; check if current element is zero within tolerance xmm0 41 | movsd xmm1,[rdi] 42 | pslld xmm1,1 43 | psrld xmm1,1 44 | comisd xmm1,xmm0 45 | ja .not_diagonal 46 | 47 | ; move to next element, return when done 48 | add rdi,8 49 | cmp rdi,rdx 50 | jae .yes_diagonal 51 | 52 | ; if current element is diagonal, skip element and set next diagonal 53 | cmp rdi,rcx 54 | jne .loop 55 | add rdi,8 56 | add rcx,rsi 57 | jmp .loop 58 | 59 | .not_diagonal: 60 | xor rax,rax 61 | jmp .ret 62 | 63 | .yes_diagonal: 64 | mov rax,1 65 | 66 | .ret: 67 | movdqu xmm1,[rsp+0] 68 | add rsp,16 69 | pop rdx 70 | pop rcx 71 | pop rsi 72 | pop rdi 73 | 74 | ret 75 | 76 | %endif 77 | -------------------------------------------------------------------------------- /lib/io/print_chars.asm: -------------------------------------------------------------------------------- 1 | %ifndef PRINT_CHARS 2 | %define PRINT_CHARS 3 | 4 | ; dependency 5 | %include "lib/io/print_buffer_flush.asm" 6 | ; also requires PRINT_BUFFER and its PRINT_BUFFER_SIZE to be defined 7 | 8 | print_chars: 9 | ; void print_chars(int {rdi}, char* {rsi}, uint {rdx}); 10 | ; Writes {rdx} chars of char array starting at {rsi} to file 11 | ; descriptor {rdi}. 12 | 13 | push rsi ; save registers 14 | push rdx 15 | push rcx 16 | push rax 17 | push r8 18 | 19 | mov rax,PRINT_BUFFER 20 | add rax,[PRINT_BUFFER_LENGTH] ; {rax} points to the next free byte 21 | ; in buffer 22 | add rdx,rsi ; {rdx} points past the last address 23 | ; of string 24 | mov r8,PRINT_BUFFER 25 | add r8,PRINT_BUFFER_SIZE ; {r8} points past the last address 26 | ; of buffer 27 | .buffer_load_loop: 28 | mov byte cl,[rsi] ; *** can revise this to do more than 1 byte at a time 29 | mov byte [rax],cl ; move byte into next free buffer slot 30 | inc rsi ; move to next byte of string 31 | inc rax ; move to next byte of buffer 32 | cmp r8,rax ; unless we've filled the buffer 33 | ja .no_flush ; do the next character 34 | mov rcx,PRINT_BUFFER_SIZE; quickly set the buffer to "full" 35 | mov [PRINT_BUFFER_LENGTH],rcx 36 | call print_buffer_flush ; flush the buffer 37 | mov rax,PRINT_BUFFER ; reset {rax} to the start of the buffer 38 | .no_flush: 39 | cmp rsi,rdx ; continue until we hit the end of our string 40 | jb .buffer_load_loop 41 | sub rax,PRINT_BUFFER ; compute number of bytes in buffer 42 | mov [PRINT_BUFFER_LENGTH],rax ; save number of bytes in buffer 43 | 44 | pop r8 ; restore registers 45 | pop rax 46 | pop rcx 47 | pop rdx 48 | pop rsi 49 | 50 | ret ;return 51 | 52 | %endif 53 | -------------------------------------------------------------------------------- /lib/math/lin_alg/plu_solve.asm: -------------------------------------------------------------------------------- 1 | %ifndef PLU_SOLVE 2 | %define PLU_SOLVE 3 | 4 | ; dependencies 5 | %include "lib/math/lin_alg/plu_decomposition.asm" 6 | %include "lib/math/lin_alg/permute_matrix.asm" 7 | %include "lib/math/lin_alg/forward_substitution.asm" 8 | %include "lib/math/lin_alg/backward_substitution.asm" 9 | 10 | plu_solve: 11 | ; void plu_solve(double* {rdi}, double* {rsi}, double* {rdx}, uint {rcx}, 12 | ; uint* {r8}); 13 | ; Solves linear system for square {rcx}x{rcx} double-precision matrix A at {rsi} 14 | ; and {rcx}x1 right-hand-side vector b at {rdx} into resultant {rcx}x1 vector at 15 | ; {rdi}. Needs a {rcx}*8 byte array of memory allocated at {r8} to return the 16 | ; permutation matrix P. Row-pivoting Doolittle algorithm. 17 | 18 | push rdi ; [rsp+32] 19 | push rsi ; [rsp+24] 20 | push rdx ; [rsp+16] 21 | push rcx ; [rsp+8] 22 | push r8 ; [rsp+0] 23 | 24 | ; perform PLU_decomposition in-place 25 | ; so Ax=b=(PLU)x=Pb 26 | mov rdi,rsi ; address of A 27 | mov rsi,r8 ; address of P (unset) 28 | mov rdx,rcx ; size of A matrix (# rows) 29 | call plu_decomposition 30 | 31 | ; pivot RHS vector b 32 | mov rdi,[rsp+16] 33 | mov rsi,[rsp+0] 34 | mov rdx,[rsp+8] 35 | mov rcx,1 36 | call permute_matrix 37 | 38 | ; forward substitution to find (Ux) from L(Ux)=b 39 | mov rdi,[rsp+32] 40 | mov rsi,[rsp+24] 41 | mov rdx,[rsp+16] 42 | mov rcx,[rsp+8] 43 | mov r8,2 44 | call forward_substitution 45 | 46 | ; backward substitution to find x from Ux=(Ux) 47 | mov rdi,[rsp+32] 48 | mov rsi,[rsp+24] 49 | mov rdx,[rsp+16] 50 | mov rcx,[rsp+8] 51 | xor r8,r8 52 | call backward_substitution 53 | 54 | pop r8 55 | pop rcx 56 | pop rdx 57 | pop rsi 58 | pop rdi 59 | 60 | ret 61 | 62 | %endif 63 | -------------------------------------------------------------------------------- /aarch64/lib/IO/LOG_OCTAL.S: -------------------------------------------------------------------------------- 1 | .IFNDEF LOG_OCTAL 2 | .EQU LOG_OCTAL,1 3 | 4 | .INCLUDE "IO/LOG_TEXT.S" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | .MACRO _LOG_OCTAL NUMBER // CAN ALSO PUT REGISTER 10 | SUB SP,SP,80 11 | STP LR,X0,[SP,0] 12 | STP X1,X2,[SP,16] 13 | STP X3,X4,[SP,32] 14 | STP X5,X6,[SP,48] 15 | STP X7,X8,[SP,64] 16 | 17 | MOV X0,\NUMBER 18 | BL LOG_OCTAL 19 | 20 | LDP LR,X0,[SP,0] 21 | LDP X1,X2,[SP,16] 22 | LDP X3,X4,[SP,32] 23 | LDP X5,X6,[SP,48] 24 | LDP X7,X8,[SP,64] 25 | ADD SP,SP,80 26 | .ENDM 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | .ALIGN 2 32 | 33 | LOG_OCTAL:// {W0} LOG_OCTAL({X0}); 34 | // RETURNS NUMBER BYTES WRITTEN IN {W0} 35 | 36 | MOV W4,0 // DIGIT COUNTER 37 | MOV X6,(4f+32) // BUFFER END 38 | ADD X6,X6,LOAD_ADDRESS 39 | 40 | CMP X0,0 41 | B.EQ 3f 42 | 43 | 1: 44 | 45 | CMP X0,0 // CHECK IF DONE 46 | B.EQ 2f 47 | 48 | AND X2,X0,0X7 49 | ADD X2,X2,48 50 | 51 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 52 | STRB W2,[X6,0] // PUSH BYTE TO BUFFER 53 | ADD W4,W4,1 // INCREMENT DIGIT COUNTER 54 | 55 | LSR X0,X0,3 56 | 57 | B 1b // GO AGAIN 58 | 59 | 2: // LOOP BREAKOUT 60 | 61 | SUB X6,X6,LOAD_ADDRESS 62 | _LOG_TEXT X6 W4 63 | 64 | RET 65 | 66 | 3: // HANDLE ZERO 67 | 68 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 69 | MOV W3,48 // ASCII ZERO 70 | STRB W3,[X6,0] // PUSH BYTE TO BUFFER 71 | MOV W4,1 72 | B 2b 73 | 74 | 4: // BUFFER 75 | 76 | .SPACE 32 77 | 78 | .ENDIF 79 | -------------------------------------------------------------------------------- /aarch64/lib/IO/LOG_BINARY.S: -------------------------------------------------------------------------------- 1 | .IFNDEF LOG_BINARY 2 | .EQU LOG_BINARY,1 3 | 4 | .INCLUDE "IO/LOG_TEXT.S" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | .MACRO _LOG_BINARY NUMBER // CAN ALSO PUT REGISTER 10 | SUB SP,SP,80 11 | STP LR,X0,[SP,0] 12 | STP X1,X2,[SP,16] 13 | STP X3,X4,[SP,32] 14 | STP X5,X6,[SP,48] 15 | STP X7,X8,[SP,64] 16 | 17 | MOV X0,\NUMBER 18 | BL LOG_BINARY 19 | 20 | LDP LR,X0,[SP,0] 21 | LDP X1,X2,[SP,16] 22 | LDP X3,X4,[SP,32] 23 | LDP X5,X6,[SP,48] 24 | LDP X7,X8,[SP,64] 25 | ADD SP,SP,80 26 | .ENDM 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | .ALIGN 2 32 | 33 | LOG_BINARY:// {W0} LOG_BINARY({X0}); 34 | // RETURNS NUMBER BYTES WRITTEN IN {W0} 35 | 36 | MOV W4,0 // DIGIT COUNTER 37 | MOV X6,(4f+32) // BUFFER END 38 | ADD X6,X6,LOAD_ADDRESS 39 | 40 | CMP X0,0 41 | B.EQ 3f 42 | 43 | 1: 44 | 45 | CMP X0,0 // CHECK IF DONE 46 | B.EQ 2f 47 | 48 | AND X2,X0,0X1 49 | ADD X2,X2,48 50 | 51 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 52 | STRB W2,[X6,0] // PUSH BYTE TO BUFFER 53 | ADD W4,W4,1 // INCREMENT DIGIT COUNTER 54 | 55 | LSR X0,X0,1 56 | 57 | B 1b // GO AGAIN 58 | 59 | 2: // LOOP BREAKOUT 60 | 61 | SUB X6,X6,LOAD_ADDRESS 62 | _LOG_TEXT X6 W4 63 | 64 | RET 65 | 66 | 3: // HANDLE ZERO 67 | 68 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 69 | MOV W3,48 // ASCII ZERO 70 | STRB W3,[X6,0] // PUSH BYTE TO BUFFER 71 | MOV W4,1 72 | B 2b 73 | 74 | 4: // BUFFER 75 | 76 | .SPACE 32 77 | 78 | .ENDIF 79 | -------------------------------------------------------------------------------- /lib/math/root_finding/secant_method.asm: -------------------------------------------------------------------------------- 1 | %ifndef SECANT_METHOD 2 | %define SECANT_METHOD 3 | 4 | secant_method: 5 | ; ulong {rax}, double {xmm0} secant_method(void* {rdi}, double {xmm0}, 6 | ; double {xmm1}, double {xmm2}); 7 | ; Uses the secant method to find a root for the single-variable 8 | ; function at address {rdi} with initial guesses {xmm0} and {xmm1} 9 | ; to within tolerance {xmm2}. On fail, {rax}=0. On success, the 10 | ; root is returned in {xmm0}, and {rax} contains the number of 11 | ; iterations. 12 | ; 13 | ; The function of interest at address {rdi} should be of the form: 14 | ; double {xmm0} func(double {xmm0}); 15 | ; and should not affect any registers besides {xmm0}. 16 | 17 | sub rsp,80 18 | movdqu [rsp+0],xmm1 19 | movdqu [rsp+16],xmm3 20 | movdqu [rsp+32],xmm4 21 | movdqu [rsp+48],xmm5 22 | movdqu [rsp+64],xmm6 23 | 24 | xor rax,rax ; count number of iterations in {rax} 25 | 26 | .loop: 27 | movsd xmm3,xmm1 ; (x2-x1) in {xmm3} 28 | subsd xmm3,xmm0 29 | 30 | movsd xmm6,xmm3 31 | pslld xmm6,1 32 | psrld xmm6,1 33 | comisd xmm6,xmm2 34 | jbe .ret 35 | 36 | call rdi 37 | movsd xmm4,xmm0 ; {xmm4} = f(x1); 38 | 39 | movsd xmm0,xmm1 40 | call rdi 41 | 42 | movsd xmm5,xmm0 ; {xmm5} = f(x2); 43 | 44 | mulsd xmm3,xmm5 ; f(x2)*(x2-x1) 45 | subsd xmm5,xmm4 ; f(x2)-f(x1) 46 | divsd xmm3,xmm5 ; f(x2)*(x2-x1)*(f(x2)-f(x1)) 47 | 48 | movsd xmm0,xmm1 ; new x1 49 | subsd xmm1,xmm3 ; new x2 50 | 51 | inc rax 52 | 53 | jmp .loop 54 | 55 | .ret: 56 | movdqu xmm1,[rsp+0] 57 | movdqu xmm3,[rsp+16] 58 | movdqu xmm4,[rsp+32] 59 | movdqu xmm5,[rsp+48] 60 | movdqu xmm6,[rsp+64] 61 | add rsp,80 62 | 63 | ret ; return 64 | 65 | .zero: 66 | dq 0.0 67 | .half: 68 | dq 0.5 69 | 70 | %endif 71 | -------------------------------------------------------------------------------- /aarch64/lib/SYS/CHMOD.S: -------------------------------------------------------------------------------- 1 | .IFNDEF CHMOD 2 | .EQU CHMOD,1 3 | 4 | // TODO: TEST, i don't think this is set up correctly. i think i just copied and pasted unlink. 5 | // needs to be tested 6 | 7 | .INCLUDE "SYS/HELPER.S" 8 | 9 | /////////////////////////////////////////////////////////////////////////////// 10 | /////////////////////////////////////////////////////////////////////////////// 11 | 12 | .MACRO __CHMOD 13 | 14 | _PUSH_VOLATILES 15 | 16 | LDP X0,X1,[SP,VOLATILE_LENGTH+0] 17 | 18 | BL CHMOD 19 | 20 | _POP_VOLATILES 21 | 22 | .ENDM 23 | 24 | .MACRO _CHMOD PATH PERMISSIONS 25 | 26 | SUB SP,SP,16 27 | MOV X20,\PATH 28 | STR X20,[SP,0] 29 | MOV X20,\PERMISSIONS 30 | STR X20,[SP,8] 31 | 32 | __CHMOD 33 | 34 | ADD SP,SP,16 35 | 36 | .ENDM 37 | 38 | .MACRO _MAKE_EXECUTABLE PATH 39 | 40 | _CHMOD \PATH SYS_EXECUTE_PERMISSIONS 41 | 42 | .END 43 | 44 | .IFDEF VERBOSE_LOGS 45 | 46 | .INCLUDE "IO/LOG_TEXT.S" 47 | .INCLUDE "SYS/EXIT.S" 48 | 49 | 1: .ASCII "ATTEMPTING TO SET '" 50 | 2: .ASCII "'. " 51 | 3: .ASCII "FAIL. \n" 52 | 4: .ASCII "SUCCESS.\n" 53 | 54 | .ENDIF 55 | 56 | /////////////////////////////////////////////////////////////////////////////// 57 | /////////////////////////////////////////////////////////////////////////////// 58 | 59 | .ALIGN 2 60 | 61 | CHMOD: // CHMOD({W0}, {X1}); 62 | 63 | .IFDEF VERBOSE_LOGS 64 | 65 | SUB SP,SP,32 66 | STP X0,X1,[SP,0] 67 | STR LR,[SP,16] 68 | _LOG_TEXT 1b 22 69 | LDP X0,X1,[SP,0] 70 | _LOG_NULL_TERM_STRING X1 71 | _LOG_TEXT 2b,3 72 | LDP X0,X1,[SP,0] 73 | LDR LR,[SP,16] 74 | ADD SP,SP,32 75 | 76 | .ENDIF 77 | 78 | ADD X1,X1,LOAD_ADDRESS 79 | MOV W8, SYS_CHMOD 80 | SVC 0 81 | 82 | .IFDEF VERBOSE_LOGS 83 | 84 | ADD X0,X0,1 85 | MOV X1,9 86 | MUL X0,X0,X1 87 | ADD X0,X0,3b 88 | _LOG_TEXT X0,9 89 | 90 | .ENDIF 91 | 92 | RET 93 | 94 | .ENDIF 95 | -------------------------------------------------------------------------------- /lib/math/lin_alg/is_upper_triangular.asm: -------------------------------------------------------------------------------- 1 | %ifndef IS_UPPER_TRIANGULAR 2 | %define IS_UPPER_TRIANGULAR 3 | 4 | is_upper_triangular: 5 | ; bool {rax} is_upper_triangular(double* {rdi}, uint {rsi}, double {xmm0}); 6 | ; Returns {rax}=1 if {rsi}x{rsi} matrix at address {rdi} is upper-triangular. 7 | ; Values within tolerance {xmm0} are considered zero. 8 | 9 | ; Algorithm: 10 | ; Start at [1,0] element and go across horizontally up until diagonal, 11 | ; checking for zeros. Move down one row at a time repeating above until 12 | ; we exceed the memory of the matrix. 13 | 14 | push rdi 15 | push rsi 16 | push rcx 17 | push rdx 18 | sub rsp,16 19 | movdqu [rsp+0],xmm1 20 | 21 | cmp rsi,1 22 | je .yes_upper_triangular 23 | 24 | ; convert rsi to track the byte-width of matrix row 25 | shl rsi,3 26 | 27 | ; use rcx to track byte offset for current column 28 | xor rcx,rcx 29 | 30 | ; use rdx to track current byte offset to current diagonal element 31 | mov rdx,8 32 | 33 | ; use rdi to track address of [i,0] element, starting at i=1 34 | add rdi,rsi 35 | 36 | ; implement algorithm described above 37 | .loop: 38 | ; check if current element is zero within tolerance xmm0 39 | 40 | movsd xmm1,[rdi+rcx] 41 | pslld xmm1,1 42 | psrld xmm1,1 43 | comisd xmm1,xmm0 44 | ja .not_upper_triangular 45 | 46 | ; move to next column, up until (not including) diagonal 47 | add rcx,8 48 | cmp rcx,rdx 49 | jb .loop 50 | 51 | ; check if we are at the last row 52 | add rdx,8 53 | test rdx,rsi 54 | jge .yes_upper_triangular 55 | 56 | ; move to next row 57 | xor rcx,rcx 58 | add rdi,rsi 59 | jmp .loop 60 | 61 | .not_upper_triangular: 62 | xor rax,rax 63 | jmp .ret 64 | 65 | .yes_upper_triangular: 66 | mov rax,1 67 | 68 | .ret: 69 | movdqu xmm1,[rsp+0] 70 | add rsp,16 71 | pop rdx 72 | pop rcx 73 | pop rsi 74 | pop rdi 75 | 76 | ret 77 | 78 | %endif 79 | -------------------------------------------------------------------------------- /lib/math/lin_alg/is_lower_triangular.asm: -------------------------------------------------------------------------------- 1 | %ifndef IS_LOWER_TRIANGULAR 2 | %define IS_LOWER_TRIANGULAR 3 | 4 | is_lower_triangular: 5 | ; bool {rax} is_lower_triangular(double* {rdi}, uint {rsi}, double {xmm0}); 6 | ; Returns {rax}=1 if {rsi}x{rsi} matrix at address {rdi} is lower-triangular. 7 | ; Values within tolerance {xmm0} are considered zero. 8 | 9 | ; Algorithm: 10 | ; Start at [0,N-1] element and go back horizontally up until diagonal, 11 | ; checking for zeros. Move down one row at a time repeating above until 12 | ; we exceed the memory of the matrix. 13 | 14 | push rdi 15 | push rsi 16 | push rcx 17 | push rdx 18 | sub rsp,16 19 | movdqu [rsp+0],xmm1 20 | 21 | cmp rsi,1 22 | je .yes_lower_triangular 23 | 24 | ; convert rsi to track the byte-width of matrix row 25 | shl rsi,3 26 | 27 | ; use rcx to track byte offset for current column 28 | mov rcx,rsi 29 | sub rcx,8 30 | 31 | ; use rdx to track current byte offset to current diagonal element 32 | xor rdx,rdx 33 | 34 | ; use rdi to track address of [i,0] element, starting at i=0 35 | 36 | ; implement algorithm described above 37 | .loop: 38 | ; check if current element is zero within tolerance xmm0 39 | movsd xmm1,[rdi+rcx] 40 | pslld xmm1,1 41 | psrld xmm1,1 42 | comisd xmm1,xmm0 43 | ja .not_lower_triangular 44 | 45 | ; move to next column, up until (not including) diagonal 46 | sub rcx,8 47 | cmp rcx,rdx 48 | ja .loop 49 | 50 | ; check if we are at the last row 51 | add rdx,8 52 | test rdx,rsi 53 | jge .yes_lower_triangular 54 | 55 | ; move to next row 56 | mov rcx,rsi 57 | sub rcx,8 58 | add rdi,rsi 59 | jmp .loop 60 | 61 | .not_lower_triangular: 62 | xor rax,rax 63 | jmp .ret 64 | 65 | .yes_lower_triangular: 66 | mov rax,1 67 | 68 | .ret: 69 | movdqu xmm1,[rsp+0] 70 | add rsp,16 71 | pop rdx 72 | pop rcx 73 | pop rsi 74 | pop rdi 75 | 76 | ret 77 | 78 | %endif 79 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_fill.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_FILL 2 | %define SET_FILL 3 | 4 | ; dependency 5 | %include "lib/io/bitmap/set_pixel.asm" 6 | 7 | set_fill: 8 | ; void set_fill(void* {rdi}, int {esi}, int {edx}, int {ecx}, 9 | ; int {r8d}, int {r9d}); 10 | ; Fills the region at ({r8d},{r9d}) (from (0,0) @ top-left) 11 | ; in ARGB data array starting at {rdi} for an image of dimension 12 | ; ({edx},{ecx}) (WxH) to the color value in {esi}. All adjacent 13 | ; pixels of the same original color will be filled. 14 | 15 | push rax 16 | push rbx 17 | 18 | mov rax,rcx 19 | sub rax,r9 20 | dec rax 21 | imul rax,rdx 22 | add rax,r8 23 | shl rax,2 ; offset to pixel address 24 | mov eax,dword [rdi+rax] ; target pixel color in rax 25 | 26 | call .loop 27 | jmp .ret 28 | .loop: 29 | ; if we are beyond the boundaries, return 30 | test r8,r8 31 | js .outside_image_boundaries 32 | test r9,r9 33 | js .outside_image_boundaries 34 | cmp r8,rdx 35 | jge .outside_image_boundaries 36 | cmp r9,rcx 37 | jge .outside_image_boundaries 38 | 39 | ; check pixel color of target 40 | mov rbx,rcx 41 | sub rbx,r9 42 | dec rbx 43 | imul rbx,rdx 44 | add rbx,r8 45 | shl rbx,2 ; offset to pixel address 46 | mov ebx,dword [rdi+rbx] ; current pixel color in rbx 47 | 48 | cmp eax,ebx ; if we are the same color as the original 49 | je .set_this_one ; set this pixel 50 | ret 51 | 52 | .set_this_one: 53 | call set_pixel ; set this pixel 54 | 55 | ; recursive flood above 56 | push r9 57 | dec r9 58 | call .loop 59 | pop r9 60 | ; recursive flood below 61 | push r9 62 | inc r9 63 | call .loop 64 | pop r9 65 | ; recursive flood to left 66 | push r8 67 | dec r8 68 | call .loop 69 | pop r8 70 | ; recursive flood to right 71 | push r8 72 | inc r8 73 | call .loop 74 | pop r8 75 | ret 76 | 77 | .ret: 78 | pop rbx 79 | pop rax 80 | .outside_image_boundaries: 81 | ret 82 | 83 | %endif 84 | -------------------------------------------------------------------------------- /aarch64/lib/IO/LOG_HEXADECIMAL.S: -------------------------------------------------------------------------------- 1 | .IFNDEF LOG_HEXADECIMAL 2 | .EQU LOG_HEXADECIMAL,1 3 | 4 | .INCLUDE "IO/LOG_TEXT.S" 5 | 6 | /////////////////////////////////////////////////////////////////////////////// 7 | /////////////////////////////////////////////////////////////////////////////// 8 | 9 | .MACRO _LOG_HEXADECIMAL NUMBER // CAN ALSO PUT REGISTER 10 | SUB SP,SP,80 11 | STP LR,X0,[SP,0] 12 | STP X1,X2,[SP,16] 13 | STP X3,X4,[SP,32] 14 | STP X5,X6,[SP,48] 15 | STP X7,X8,[SP,64] 16 | 17 | MOV X0,\NUMBER 18 | BL LOG_HEXADECIMAL 19 | 20 | LDP LR,X0,[SP,0] 21 | LDP X1,X2,[SP,16] 22 | LDP X3,X4,[SP,32] 23 | LDP X5,X6,[SP,48] 24 | LDP X7,X8,[SP,64] 25 | ADD SP,SP,80 26 | .ENDM 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | .ALIGN 2 32 | 33 | LOG_HEXADECIMAL:// {W0} LOG_HEXADECIMAL({X0}); 34 | // RETURNS NUMBER BYTES WRITTEN IN {W0} 35 | 36 | MOV W1,48 37 | MOV W7,55 // ADDENDS FOR CONDITIONAL HEX CONVERSION 38 | 39 | MOV W4,0 // DIGIT COUNTER 40 | MOV X6,(4f+32) // BUFFER END 41 | ADD X6,X6,LOAD_ADDRESS 42 | 43 | CMP X0,0 44 | B.EQ 3f 45 | 46 | 1: 47 | 48 | CMP X0,0 // CHECK IF DONE 49 | B.EQ 2f 50 | 51 | AND X2,X0,0XF 52 | CMP X2,0X9 53 | CSEL W8,W7,W1,GT 54 | ADD W2,W2,W8 55 | 56 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 57 | STRB W2,[X6,0] // PUSH BYTE TO BUFFER 58 | ADD W4,W4,1 // INCREMENT DIGIT COUNTER 59 | 60 | LSR X0,X0,4 61 | 62 | B 1b // GO AGAIN 63 | 64 | 2: // LOOP BREAKOUT 65 | 66 | SUB X6,X6,LOAD_ADDRESS 67 | _LOG_TEXT X6 W4 68 | 69 | RET 70 | 71 | 3: // HANDLE ZERO 72 | 73 | SUB X6,X6,1 // MOVE POINTER TO PRECEDING BYTE 74 | MOV W3,48 // ASCII ZERO 75 | STRB W3,[X6,0] // PUSH BYTE TO BUFFER 76 | MOV W4,1 77 | B 2b 78 | 79 | 4: // BUFFER 80 | 81 | .SPACE 32 82 | 83 | .ENDIF 84 | -------------------------------------------------------------------------------- /lib/math/lin_alg/least_squares_regression.asm: -------------------------------------------------------------------------------- 1 | %ifndef LEAST_SQUARES_REGRESSION 2 | %define LEAST_SQUARES_REGRESSION 3 | 4 | %include "lib/mem/heap_free.asm" 5 | %include "lib/mem/heap_alloc.asm" 6 | %include "lib/math/lin_alg/lu_solve.asm" 7 | 8 | least_squares_regression: 9 | ; double* {rax} least_squares_regression (double* {rdi}, uint {rsi}, double {xmm0}); 10 | ; Returns {rax}=1 if {rsi}x{rsi} matrix at address {rdi} is diagonal. 11 | ; Values within tolerance {xmm0} are considered zero. 12 | 13 | ; Algorithm: 14 | ; Iterate over all elements checking for zeros in non-diagonal spots. 15 | 16 | push rdi 17 | push rsi 18 | push rcx 19 | push rdx 20 | sub rsp,16 21 | movdqu [rsp+0],xmm1 22 | 23 | cmp rsi,1 24 | je .yes_diagonal 25 | 26 | ; convert rsi to indicate the byte-width between diagonal elements 27 | ; and rdx to indicate address beyond the matrix 28 | mov rdx,rsi 29 | shl rsi,3 30 | imul rdx,rsi 31 | add rdx,rdi 32 | add rsi,8 33 | sub rdx,8 34 | 35 | ; use rcx to track address of next diagonal element 36 | mov rcx,rdi 37 | add rcx,rsi 38 | 39 | ; use rdi to track current element, skipping first element 40 | add rdi,8 41 | 42 | ; implement algorithm described above 43 | .loop: 44 | ; check if current element is zero within tolerance xmm0 45 | movsd xmm1,[rdi] 46 | pslld xmm1,1 47 | psrld xmm1,1 48 | comisd xmm1,xmm0 49 | ja .not_diagonal 50 | 51 | ; move to next element, return when done 52 | add rdi,8 53 | cmp rdi,rdx 54 | jae .yes_diagonal 55 | 56 | ; if current element is diagonal, skip element and set next diagonal 57 | cmp rdi,rcx 58 | jne .loop 59 | add rdi,8 60 | add rcx,rsi 61 | jmp .loop 62 | 63 | .not_diagonal: 64 | xor rax,rax 65 | jmp .ret 66 | 67 | .yes_diagonal: 68 | mov rax,1 69 | 70 | .ret: 71 | movdqu xmm1,[rsp+0] 72 | add rsp,16 73 | pop rdx 74 | pop rcx 75 | pop rsi 76 | pop rdi 77 | 78 | ret 79 | 80 | %endif 81 | -------------------------------------------------------------------------------- /lib/io/bitmap/set_foreground.asm: -------------------------------------------------------------------------------- 1 | %ifndef SET_FOREGROUND 2 | %define SET_FOREGROUND 3 | 4 | set_foreground: 5 | ; void set_foreground(void* {rdi}, void* {rsi}, int {edx}, int {ecx}, 6 | ; int {r8d}, int {r9d}, int {r10d}, int {r11d}); 7 | ; Copies pixels from the {r8d}x{r9d} bitmap at {rsi} to 8 | ; the {edx}x{ecx} bitmap at {rdi} starting at the pixel 9 | ; at corner ({r10d},{r11d}). Only copies pixels with nonzero 10 | ; transparency byte. 11 | 12 | push rsi 13 | push rax 14 | push rbx 15 | push r9 16 | push r12 17 | push r13 18 | push r15 19 | 20 | ; adjust number of rows down if we slide off the bottom 21 | mov eax,r11d 22 | add eax,r9d 23 | cmp eax,ecx 24 | jle .good_y 25 | sub eax,ecx 26 | sub r9d,eax 27 | .good_y: 28 | ; compute valid number of columns (we won't plot beyond this) 29 | mov eax,r10d 30 | add eax,r8d 31 | cmp eax,edx 32 | jle .good_x 33 | sub eax,edx 34 | mov r15d,r8d 35 | sub r15d,eax 36 | .good_x: 37 | 38 | shl edx,2 ; {edx} contains byte width of background bitmap 39 | mov eax,edx 40 | imul eax,r11d 41 | shl r10d,2 42 | add eax,r10d 43 | add rax,rdi ; {rax} points to starting corner of bg bmp 44 | shr r10d,2 45 | 46 | ; skip if we have zero rows left 47 | test r9d,r9d 48 | jz .ret 49 | 50 | ; loop thru rows of foreground bitmap 51 | .row_loop: 52 | mov rbx,rax ; {rbx} will track the target pixel in the loops 53 | xor r12d,r12d ; track col pixel count in {r12} 54 | 55 | ; loop thru cols of foreground bitmap 56 | .col_loop: 57 | cmp r12d,r15d 58 | jg .skip 59 | mov r13d,[rsi] 60 | test r13d,0xFF000000 61 | jz .skip 62 | mov [rbx],r13d 63 | .skip: 64 | add rsi,4 65 | add rbx,4 66 | inc r12d 67 | cmp r12d,r8d 68 | jl .col_loop 69 | 70 | add rax,rdx 71 | dec r9d 72 | jnz .row_loop 73 | 74 | .ret: 75 | shr edx,2 76 | pop r15 77 | pop r13 78 | pop r12 79 | pop r9 80 | pop rbx 81 | pop rax 82 | pop rsi 83 | ret 84 | 85 | %endif 86 | -------------------------------------------------------------------------------- /lib/math/expressions/trig/sine_bhaskara.asm: -------------------------------------------------------------------------------- 1 | %ifndef SINE_BHASKARA 2 | %define SINE_BHASKARA 3 | 4 | ; double {xmm0} sine_bhaskara(double {xmm0}); 5 | ; Returns approximation of sine({xmm0}) in {xmm0} using approximation 6 | ; below: 7 | ; sine(x)~=(16x*(pi-x))/(5pi^2-4x*(pi-x)) 8 | 9 | align 64 10 | sine_bhaskara: 11 | 12 | push rax 13 | push rbx 14 | sub rsp,16 15 | movdqu [rsp+0],xmm1 16 | 17 | xor rax,rax 18 | xor rbx,rbx ; negate flag 19 | 20 | pxor xmm1,xmm1 21 | comisd xmm0,xmm1 22 | jae .no_negate 23 | pslld xmm0,1 24 | psrld xmm0,1 25 | mov rbx,1 26 | 27 | .no_negate: 28 | 29 | movsd xmm1,xmm0 30 | mulsd xmm1,[.recip_two_pi] 31 | roundsd xmm1,xmm1,0b11 ; truncate xmm8 to integer 32 | mulsd xmm1,[.two_pi] ; xmm8 is the closest multiple of 2pi 33 | ; of lower absolute value 34 | subsd xmm0,xmm1 ; xmm0 is now within [0,2pi] 35 | 36 | movsd xmm1,[.pi] 37 | comisd xmm0,xmm1 38 | jbe .reduced 39 | subsd xmm0,xmm1 40 | xor rbx,1 41 | .reduced: ; xmm0 is now within [0,pi] 42 | 43 | 44 | ; sine(x)~=(16x*(pi-x))/(5pi^2-4x*(pi-x)) 45 | 46 | movsd xmm1,[.pi] 47 | subsd xmm1,xmm0 48 | movsd xmm2,xmm0 49 | mulsd xmm0,[.sixteen] 50 | mulsd xmm0,xmm1 51 | 52 | mulsd xmm2,[.four] 53 | mulsd xmm2,xmm1 54 | movsd xmm1,[.five_pi_squared] 55 | subsd xmm1,xmm2 56 | 57 | divsd xmm0,xmm1 58 | 59 | test rbx,rbx 60 | jz .no_neg 61 | mulsd xmm0,[.neg] 62 | 63 | .no_neg: 64 | 65 | movdqu xmm1,[rsp+0] 66 | add rsp,16 67 | 68 | pop rbx 69 | pop rax 70 | 71 | ret 72 | 73 | align 8 74 | 75 | .neg: ; -1 76 | dq 0xBFF0000000000000 77 | 78 | .pi: ; ~3.1 79 | dq 0x400921FB54442D18 80 | 81 | .four: 82 | dq 0x4010000000000000 83 | 84 | .sixteen: 85 | dq 0x4030000000000000 86 | 87 | .five_pi_squared: 88 | dq 0x4048AC8BFC2DD756 89 | 90 | .two_pi: ; ~6.3 91 | dq 0x401921FB54442D18 92 | 93 | .recip_two_pi: ; 1/6.3 94 | dq 0x3FC45F306DC9C883 95 | 96 | %endif 97 | 98 | --------------------------------------------------------------------------------