diff --git a/worksheet2_1/Makefile b/Worksheet2_1/Makefile similarity index 100% rename from worksheet2_1/Makefile rename to Worksheet2_1/Makefile diff --git a/worksheet2_1/README.md b/Worksheet2_1/README.md similarity index 100% rename from worksheet2_1/README.md rename to Worksheet2_1/README.md diff --git a/worksheet2_1/iso/boot/grub/menu.lst b/Worksheet2_1/iso/boot/grub/menu.lst similarity index 100% rename from worksheet2_1/iso/boot/grub/menu.lst rename to Worksheet2_1/iso/boot/grub/menu.lst diff --git a/worksheet2_1/iso/boot/grub/stage2_eltorito b/Worksheet2_1/iso/boot/grub/stage2_eltorito similarity index 100% rename from worksheet2_1/iso/boot/grub/stage2_eltorito rename to Worksheet2_1/iso/boot/grub/stage2_eltorito diff --git a/worksheet2_1/loader.asm b/Worksheet2_1/loader.asm similarity index 100% rename from worksheet2_1/loader.asm rename to Worksheet2_1/loader.asm diff --git a/worksheet2_1/loader.o b/Worksheet2_1/loader.o similarity index 100% rename from worksheet2_1/loader.o rename to Worksheet2_1/loader.o diff --git a/worksheet2_1/source/link.ld b/Worksheet2_1/source/link.ld similarity index 100% rename from worksheet2_1/source/link.ld rename to Worksheet2_1/source/link.ld diff --git a/worksheet2_2/Makefile b/Worksheet2_2/Makefile similarity index 100% rename from worksheet2_2/Makefile rename to Worksheet2_2/Makefile diff --git a/worksheet2_2/frame_buffer.c b/Worksheet2_2/frame_buffer.c similarity index 100% rename from worksheet2_2/frame_buffer.c rename to Worksheet2_2/frame_buffer.c diff --git a/worksheet2_2/frame_buffer.h b/Worksheet2_2/frame_buffer.h similarity index 100% rename from worksheet2_2/frame_buffer.h rename to Worksheet2_2/frame_buffer.h diff --git a/worksheet2_2/hardware_interrupt_enabler.s b/Worksheet2_2/hardware_interrupt_enabler.s similarity index 100% rename from worksheet2_2/hardware_interrupt_enabler.s rename to Worksheet2_2/hardware_interrupt_enabler.s diff --git a/worksheet2_2/interrupt_asm.o b/Worksheet2_2/interrupt_asm.o similarity index 100% rename from worksheet2_2/interrupt_asm.o rename to Worksheet2_2/interrupt_asm.o diff --git a/worksheet2_2/interrupt_asm.s b/Worksheet2_2/interrupt_asm.s similarity index 100% rename from worksheet2_2/interrupt_asm.s rename to Worksheet2_2/interrupt_asm.s diff --git a/worksheet2_2/interrupt_handlers.o b/Worksheet2_2/interrupt_handlers.o similarity index 100% rename from worksheet2_2/interrupt_handlers.o rename to Worksheet2_2/interrupt_handlers.o diff --git a/worksheet2_2/interrupt_handlers.s b/Worksheet2_2/interrupt_handlers.s similarity index 100% rename from worksheet2_2/interrupt_handlers.s rename to Worksheet2_2/interrupt_handlers.s diff --git a/worksheet2_2/interrupts.c b/Worksheet2_2/interrupts.c similarity index 100% rename from worksheet2_2/interrupts.c rename to Worksheet2_2/interrupts.c diff --git a/worksheet2_2/interrupts.h b/Worksheet2_2/interrupts.h similarity index 100% rename from worksheet2_2/interrupts.h rename to Worksheet2_2/interrupts.h diff --git a/worksheet2_2/interrupts.o b/Worksheet2_2/interrupts.o similarity index 100% rename from worksheet2_2/interrupts.o rename to Worksheet2_2/interrupts.o diff --git a/worksheet2_2/io.h b/Worksheet2_2/io.h similarity index 100% rename from worksheet2_2/io.h rename to Worksheet2_2/io.h diff --git a/worksheet2_2/io.o b/Worksheet2_2/io.o similarity index 100% rename from worksheet2_2/io.o rename to Worksheet2_2/io.o diff --git a/worksheet2_2/io.s b/Worksheet2_2/io.s similarity index 100% rename from worksheet2_2/io.s rename to Worksheet2_2/io.s diff --git a/worksheet2_2/keyboard.c b/Worksheet2_2/keyboard.c similarity index 100% rename from worksheet2_2/keyboard.c rename to Worksheet2_2/keyboard.c diff --git a/worksheet2_2/keyboard.h b/Worksheet2_2/keyboard.h similarity index 100% rename from worksheet2_2/keyboard.h rename to Worksheet2_2/keyboard.h diff --git a/worksheet2_2/keyboard.o b/Worksheet2_2/keyboard.o similarity index 100% rename from worksheet2_2/keyboard.o rename to Worksheet2_2/keyboard.o diff --git a/worksheet2_2/kmain.c b/Worksheet2_2/kmain.c similarity index 100% rename from worksheet2_2/kmain.c rename to Worksheet2_2/kmain.c diff --git a/worksheet2_2/kmain.o b/Worksheet2_2/kmain.o similarity index 100% rename from worksheet2_2/kmain.o rename to Worksheet2_2/kmain.o diff --git a/worksheet2_2/loader.s b/Worksheet2_2/loader.s similarity index 100% rename from worksheet2_2/loader.s rename to Worksheet2_2/loader.s diff --git a/worksheet2_2/pic.c b/Worksheet2_2/pic.c similarity index 100% rename from worksheet2_2/pic.c rename to Worksheet2_2/pic.c diff --git a/worksheet2_2/pic.h b/Worksheet2_2/pic.h similarity index 100% rename from worksheet2_2/pic.h rename to Worksheet2_2/pic.h diff --git a/worksheet2_2/pic.o b/Worksheet2_2/pic.o similarity index 100% rename from worksheet2_2/pic.o rename to Worksheet2_2/pic.o diff --git a/worksheet2_2/types.h b/Worksheet2_2/types.h similarity index 100% rename from worksheet2_2/types.h rename to Worksheet2_2/types.h diff --git a/worksheet_0/foo.txt b/Worksheet_0/foo.txt similarity index 100% rename from worksheet_0/foo.txt rename to Worksheet_0/foo.txt diff --git a/worksheet_0/task1_pointer b/Worksheet_0/task1_pointer similarity index 100% rename from worksheet_0/task1_pointer rename to Worksheet_0/task1_pointer diff --git a/worksheet_0/task1_pointer.c b/Worksheet_0/task1_pointer.c similarity index 100% rename from worksheet_0/task1_pointer.c rename to Worksheet_0/task1_pointer.c diff --git a/worksheet_0/task1_pointer.dSYM/Contents/Info.plist b/Worksheet_0/task1_pointer.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task1_pointer.dSYM/Contents/Info.plist rename to Worksheet_0/task1_pointer.dSYM/Contents/Info.plist diff --git a/worksheet_0/task1_pointer.dSYM/Contents/Resources/DWARF/task1_pointer b/Worksheet_0/task1_pointer.dSYM/Contents/Resources/DWARF/task1_pointer similarity index 100% rename from worksheet_0/task1_pointer.dSYM/Contents/Resources/DWARF/task1_pointer rename to Worksheet_0/task1_pointer.dSYM/Contents/Resources/DWARF/task1_pointer diff --git a/worksheet_0/task1_pointer.dSYM/Contents/Resources/Relocations/x86_64/task1_pointer.yml b/Worksheet_0/task1_pointer.dSYM/Contents/Resources/Relocations/x86_64/task1_pointer.yml similarity index 100% rename from worksheet_0/task1_pointer.dSYM/Contents/Resources/Relocations/x86_64/task1_pointer.yml rename to Worksheet_0/task1_pointer.dSYM/Contents/Resources/Relocations/x86_64/task1_pointer.yml diff --git a/worksheet_0/task2_array_pointer b/Worksheet_0/task2_array_pointer similarity index 100% rename from worksheet_0/task2_array_pointer rename to Worksheet_0/task2_array_pointer diff --git a/worksheet_0/task2_array_pointer.c b/Worksheet_0/task2_array_pointer.c similarity index 100% rename from worksheet_0/task2_array_pointer.c rename to Worksheet_0/task2_array_pointer.c diff --git a/worksheet_0/task2_array_pointer.dSYM/Contents/Info.plist b/Worksheet_0/task2_array_pointer.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task2_array_pointer.dSYM/Contents/Info.plist rename to Worksheet_0/task2_array_pointer.dSYM/Contents/Info.plist diff --git a/worksheet_0/task2_array_pointer.dSYM/Contents/Resources/DWARF/task2_array_pointer b/Worksheet_0/task2_array_pointer.dSYM/Contents/Resources/DWARF/task2_array_pointer similarity index 100% rename from worksheet_0/task2_array_pointer.dSYM/Contents/Resources/DWARF/task2_array_pointer rename to Worksheet_0/task2_array_pointer.dSYM/Contents/Resources/DWARF/task2_array_pointer diff --git a/worksheet_0/task2_array_pointer.dSYM/Contents/Resources/Relocations/x86_64/task2_array_pointer.yml b/Worksheet_0/task2_array_pointer.dSYM/Contents/Resources/Relocations/x86_64/task2_array_pointer.yml similarity index 100% rename from worksheet_0/task2_array_pointer.dSYM/Contents/Resources/Relocations/x86_64/task2_array_pointer.yml rename to Worksheet_0/task2_array_pointer.dSYM/Contents/Resources/Relocations/x86_64/task2_array_pointer.yml diff --git a/worksheet_0/task3_array_compare b/Worksheet_0/task3_array_compare similarity index 100% rename from worksheet_0/task3_array_compare rename to Worksheet_0/task3_array_compare diff --git a/worksheet_0/task3_array_compare.c b/Worksheet_0/task3_array_compare.c similarity index 100% rename from worksheet_0/task3_array_compare.c rename to Worksheet_0/task3_array_compare.c diff --git a/worksheet_0/task3_array_compare.dSYM/Contents/Info.plist b/Worksheet_0/task3_array_compare.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task3_array_compare.dSYM/Contents/Info.plist rename to Worksheet_0/task3_array_compare.dSYM/Contents/Info.plist diff --git a/worksheet_0/task3_array_compare.dSYM/Contents/Resources/DWARF/task3_array_compare b/Worksheet_0/task3_array_compare.dSYM/Contents/Resources/DWARF/task3_array_compare similarity index 100% rename from worksheet_0/task3_array_compare.dSYM/Contents/Resources/DWARF/task3_array_compare rename to Worksheet_0/task3_array_compare.dSYM/Contents/Resources/DWARF/task3_array_compare diff --git a/worksheet_0/task3_array_compare.dSYM/Contents/Resources/Relocations/x86_64/task3_array_compare.yml b/Worksheet_0/task3_array_compare.dSYM/Contents/Resources/Relocations/x86_64/task3_array_compare.yml similarity index 100% rename from worksheet_0/task3_array_compare.dSYM/Contents/Resources/Relocations/x86_64/task3_array_compare.yml rename to Worksheet_0/task3_array_compare.dSYM/Contents/Resources/Relocations/x86_64/task3_array_compare.yml diff --git a/worksheet_0/task4_file_sum b/Worksheet_0/task4_file_sum similarity index 100% rename from worksheet_0/task4_file_sum rename to Worksheet_0/task4_file_sum diff --git a/worksheet_0/task4_file_sum.c b/Worksheet_0/task4_file_sum.c similarity index 100% rename from worksheet_0/task4_file_sum.c rename to Worksheet_0/task4_file_sum.c diff --git a/worksheet_0/task4_file_sum.dSYM/Contents/Info.plist b/Worksheet_0/task4_file_sum.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task4_file_sum.dSYM/Contents/Info.plist rename to Worksheet_0/task4_file_sum.dSYM/Contents/Info.plist diff --git a/worksheet_0/task4_file_sum.dSYM/Contents/Resources/DWARF/task4_file_sum b/Worksheet_0/task4_file_sum.dSYM/Contents/Resources/DWARF/task4_file_sum similarity index 100% rename from worksheet_0/task4_file_sum.dSYM/Contents/Resources/DWARF/task4_file_sum rename to Worksheet_0/task4_file_sum.dSYM/Contents/Resources/DWARF/task4_file_sum diff --git a/worksheet_0/task4_file_sum.dSYM/Contents/Resources/Relocations/x86_64/task4_file_sum.yml b/Worksheet_0/task4_file_sum.dSYM/Contents/Resources/Relocations/x86_64/task4_file_sum.yml similarity index 100% rename from worksheet_0/task4_file_sum.dSYM/Contents/Resources/Relocations/x86_64/task4_file_sum.yml rename to Worksheet_0/task4_file_sum.dSYM/Contents/Resources/Relocations/x86_64/task4_file_sum.yml diff --git a/worksheet_0/task5_swap_function b/Worksheet_0/task5_swap_function similarity index 100% rename from worksheet_0/task5_swap_function rename to Worksheet_0/task5_swap_function diff --git a/worksheet_0/task5_swap_function.c b/Worksheet_0/task5_swap_function.c similarity index 100% rename from worksheet_0/task5_swap_function.c rename to Worksheet_0/task5_swap_function.c diff --git a/worksheet_0/task5_swap_function.dSYM/Contents/Info.plist b/Worksheet_0/task5_swap_function.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task5_swap_function.dSYM/Contents/Info.plist rename to Worksheet_0/task5_swap_function.dSYM/Contents/Info.plist diff --git a/worksheet_0/task5_swap_function.dSYM/Contents/Resources/DWARF/task5_swap_function b/Worksheet_0/task5_swap_function.dSYM/Contents/Resources/DWARF/task5_swap_function similarity index 100% rename from worksheet_0/task5_swap_function.dSYM/Contents/Resources/DWARF/task5_swap_function rename to Worksheet_0/task5_swap_function.dSYM/Contents/Resources/DWARF/task5_swap_function diff --git a/worksheet_0/task5_swap_function.dSYM/Contents/Resources/Relocations/x86_64/task5_swap_function.yml b/Worksheet_0/task5_swap_function.dSYM/Contents/Resources/Relocations/x86_64/task5_swap_function.yml similarity index 100% rename from worksheet_0/task5_swap_function.dSYM/Contents/Resources/Relocations/x86_64/task5_swap_function.yml rename to Worksheet_0/task5_swap_function.dSYM/Contents/Resources/Relocations/x86_64/task5_swap_function.yml diff --git a/worksheet_0/task6_print_2d_array b/Worksheet_0/task6_print_2d_array similarity index 100% rename from worksheet_0/task6_print_2d_array rename to Worksheet_0/task6_print_2d_array diff --git a/worksheet_0/task6_print_2d_array.c b/Worksheet_0/task6_print_2d_array.c similarity index 100% rename from worksheet_0/task6_print_2d_array.c rename to Worksheet_0/task6_print_2d_array.c diff --git a/worksheet_0/task6_print_2d_array.dSYM/Contents/Info.plist b/Worksheet_0/task6_print_2d_array.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task6_print_2d_array.dSYM/Contents/Info.plist rename to Worksheet_0/task6_print_2d_array.dSYM/Contents/Info.plist diff --git a/worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/DWARF/task6_print_2d_array b/Worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/DWARF/task6_print_2d_array similarity index 100% rename from worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/DWARF/task6_print_2d_array rename to Worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/DWARF/task6_print_2d_array diff --git a/worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/Relocations/x86_64/task6_print_2d_array.yml b/Worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/Relocations/x86_64/task6_print_2d_array.yml similarity index 100% rename from worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/Relocations/x86_64/task6_print_2d_array.yml rename to Worksheet_0/task6_print_2d_array.dSYM/Contents/Resources/Relocations/x86_64/task6_print_2d_array.yml diff --git a/worksheet_0/task7_tic_tac_toe b/Worksheet_0/task7_tic_tac_toe similarity index 100% rename from worksheet_0/task7_tic_tac_toe rename to Worksheet_0/task7_tic_tac_toe diff --git a/worksheet_0/task7_tic_tac_toe.c b/Worksheet_0/task7_tic_tac_toe.c similarity index 100% rename from worksheet_0/task7_tic_tac_toe.c rename to Worksheet_0/task7_tic_tac_toe.c diff --git a/worksheet_0/task7_tic_tac_toe.dSYM/Contents/Info.plist b/Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Info.plist similarity index 100% rename from worksheet_0/task7_tic_tac_toe.dSYM/Contents/Info.plist rename to Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Info.plist diff --git a/worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/DWARF/task7_tic_tac_toe b/Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/DWARF/task7_tic_tac_toe similarity index 100% rename from worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/DWARF/task7_tic_tac_toe rename to Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/DWARF/task7_tic_tac_toe diff --git a/worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/Relocations/x86_64/task7_tic_tac_toe.yml b/Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/Relocations/x86_64/task7_tic_tac_toe.yml similarity index 100% rename from worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/Relocations/x86_64/task7_tic_tac_toe.yml rename to Worksheet_0/task7_tic_tac_toe.dSYM/Contents/Resources/Relocations/x86_64/task7_tic_tac_toe.yml diff --git a/Worksheet_1/Dockerfile b/Worksheet_1/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..85516ee65b1e69dee682518af6512f756f0345bb --- /dev/null +++ b/Worksheet_1/Dockerfile @@ -0,0 +1,17 @@ +# Use an official lightweight Linux image +FROM debian:latest + +# Install NASM and GCC for assembly and linking +RUN apt-get update && apt-get install -y \ + nasm \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /app + +# Copy the current directory contents into the container +COPY . /app + +# Set default command to bash +CMD ["/bin/bash"] diff --git a/Worksheet_1/Makefile b/Worksheet_1/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..aaec790657ade094ac4c4b416eab9d42485e2506 --- /dev/null +++ b/Worksheet_1/Makefile @@ -0,0 +1,31 @@ +all: task1 task2 task3 + +task1: src/task1.o src/driver.o src/asm_io.o + gcc -m32 -o src/task1 src/task1.o src/driver.o src/asm_io.o + +task2: src/task2.o src/driver.o src/asm_io.o src/print_int.o + gcc -m32 -o src/task2 src/task2.o src/driver.o src/asm_io.o src/print_int.o + +task3: src/task3.o src/driver.o src/asm_io.o src/print_int.o + gcc -m32 -o src/task3 src/task3.o src/driver.o src/asm_io.o src/print_int.o + +src/task1.o: src/task1.asm + nasm -f elf src/task1.asm -o src/task1.o + +src/task2.o: src/task2.asm + nasm -f elf src/task2.asm -o src/task2.o + +src/task3.o: src/task3.asm + nasm -f elf src/task3.asm -o src/task3.o + +src/driver.o: src/driver.c + gcc -m32 -c src/driver.c -o src/driver.o + +src/asm_io.o: src/asm_io.asm + nasm -f elf src/asm_io.asm -o src/asm_io.o + +src/print_int.o: src/print_int.c + gcc -m32 -c src/print_int.c -o src/print_int.o + +clean: + rm -f src/*.o src/task1 src/task2 src/task3 diff --git a/Worksheet_1/README.md b/Worksheet_1/README.md new file mode 100644 index 0000000000000000000000000000000000000000..dc4aefd59d53a61c0fc659bc74c500e3ae3dc543 --- /dev/null +++ b/Worksheet_1/README.md @@ -0,0 +1,84 @@ +# Worksheet 1: Assembly Programming with Docker Integration + +This project is part of the **Worksheet 1** task, focusing on assembly programming and integration with Docker for build and run processes. + +## Project Overview + +This repository contains assembly language programs and supporting files to demonstrate basic programming concepts in assembly language. The workflow involves writing assembly code, integrating it with C for execution, and containerizing the build process using Docker. + +### Files in the Repository + +- **Assembly Files** + - `task1.asm`: First task in assembly programming. + - `task2.asm`: Second task in assembly programming. + - `task3.asm`: Third task in assembly programming. + +- **C Files** + - `driver.c`: Main driver file that calls the assembly program. + - `print_int.c`: Helper function to print integers. + +- **Include Files** + - `asm_io.asm` and `asm_io.inc`: Assembly IO routines. + +- **Build Files** + - `Makefile`: Automates the build process. + - `Dockerfile`: Containerizes the build and execution process. + +## Getting Started + +### Prerequisites + +- **Docker**: Ensure Docker is installed on your machine. +- **NASM**: An assembler for x86 assembly. +- **GCC**: A C compiler to link the assembly and C code. + +### Building and Running + +1. **Using Docker**: + - Build the Docker container: + ```bash + docker build -t asm_project . + ``` + - Run the container: + ```bash + docker run --rm asm_project + ``` + +2. **Locally**: + - Compile using `make`: + ```bash + make + ``` + - Run the program: + ```bash + ./program + ``` + +## Project Structure + +worksheet_1/ +├── README.md # Project documentation (to be created or updated by you) +├── Makefile # Build file for automating compilation +├── Dockerfile # Docker configuration for containerized builds +├── src/ # Directory containing all source files +│ ├── asm_io.asm # Provided Assembly IO code +│ ├── asm_io.inc # Provided IO include file +│ ├── driver.c # Main C program calling assembly functions +│ ├── print_int.c # Helper C program for printing integers +│ ├── task1.asm # Assembly code for Task 1 +│ ├── task2.asm # Assembly code for Task 2 +│ ├── task3.asm # Assembly code for Task 3 + + +## Authors + +- Hazal Veziroglu + +## License + +This project is licensed under the MIT License. See the `LICENSE` file for details. + +## Acknowledgments + +- UWE Course Material on Assembly Programming +- Online assembly programming resources and communities. diff --git a/Worksheet_1/src/asm_io.asm b/Worksheet_1/src/asm_io.asm new file mode 100644 index 0000000000000000000000000000000000000000..96c5e4993668355f44c85af5999d640a41c0ec84 --- /dev/null +++ b/Worksheet_1/src/asm_io.asm @@ -0,0 +1,502 @@ +; +; file: asm_io.asm +; Assembly I/O routines +; To assemble for DJGPP +; nasm -f coff -d COFF_TYPE asm_io.asm +; To assemble for Borland C++ 5.x +; nasm -f obj -d OBJ_TYPE asm_io.asm +; To assemble for Microsoft Visual Studio +; nasm -f win32 -d COFF_TYPE asm_io.asm +; To assemble for Linux +; nasm -f elf -d ELF_TYPE asm_io.asm +; To assemble for Watcom +; nasm -f obj -d OBJ_TYPE -d WATCOM asm_io.asm +; IMPORTANT NOTES FOR WATCOM +; The Watcom compiler's C library does not use the +; standard C calling convention. For example, the +; putchar() function gets its argument from the +; the value of EAX, not the stack. + + +%define NL 10 +%define CF_MASK 00000001h +%define PF_MASK 00000004h +%define AF_MASK 00000010h +%define ZF_MASK 00000040h +%define SF_MASK 00000080h +%define DF_MASK 00000400h +%define OF_MASK 00000800h + + +; +; Linux C doesn't put underscores on labels +; +; %ifdef ELF_TYPE +%define _scanf scanf +%define _printf printf +%define _getchar getchar +%define _putchar putchar +; %endif + +; ; +; ; Watcom puts underscores at end of label +; ; +; %ifdef WATCOM +; %define _scanf scanf_ +; %define _printf printf +; %define _getchar getchar_ +; %define _putchar putchar_ +; %endif + +%ifdef OBJ_TYPE +segment .data public align=4 class=data use32 +%else +segment .data +%endif + +int_format db "%i", 0 +string_format db "%s", 0 +reg_format db "Register Dump # %d", NL + db "EAX = %.8X EBX = %.8X ECX = %.8X EDX = %.8X", NL + db "ESI = %.8X EDI = %.8X EBP = %.8X ESP = %.8X", NL + db "EIP = %.8X FLAGS = %.4X %s %s %s %s %s %s %s", NL + db 0 +carry_flag db "CF", 0 +zero_flag db "ZF", 0 +sign_flag db "SF", 0 +parity_flag db "PF", 0 +overflow_flag db "OF", 0 +dir_flag db "DF", 0 +aux_carry_flag db "AF", 0 +unset_flag db " ", 0 +mem_format1 db "Memory Dump # %d Address = %.8X", NL, 0 +mem_format2 db "%.8X ", 0 +mem_format3 db "%.2X ", 0 +stack_format db "Stack Dump # %d", NL + db "EBP = %.8X ESP = %.8X", NL, 0 +stack_line_format db "%+4d %.8X %.8X", NL, 0 +math_format1 db "Math Coprocessor Dump # %d Control Word = %.4X" + db " Status Word = %.4X", NL, 0 +valid_st_format db "ST%d: %.10g", NL, 0 +invalid_st_format db "ST%d: Invalid ST", NL, 0 +empty_st_format db "ST%d: Empty", NL, 0 + +; +; code is put in the _TEXT segment +; +%ifdef OBJ_TYPE +segment text public align=1 class=code use32 +%else +segment .text +%endif + global read_int, print_int, print_string, read_char + global print_char, print_nl, sub_dump_regs, sub_dump_mem + global sub_dump_math, sub_dump_stack + extern _scanf, _printf, _getchar, _putchar + +read_int: + enter 4,0 + pusha + pushf + + lea eax, [ebp-4] + push eax + push dword int_format + call _scanf + pop ecx + pop ecx + + popf + popa + mov eax, [ebp-4] + leave + ret + +print_int: + enter 0,0 + pusha + pushf + + push eax + push dword int_format + call _printf + pop ecx + pop ecx + + popf + popa + leave + ret + +print_string: + enter 0,0 + pusha + pushf + + push eax + push dword string_format + call _printf + pop ecx + pop ecx + + popf + popa + leave + ret + +read_char: + enter 4,0 + pusha + pushf + + call _getchar + mov [ebp-4], eax + + popf + popa + mov eax, [ebp-4] + leave + ret + +print_char: + enter 0,0 + pusha + pushf + +%ifndef WATCOM + push eax +%endif + call _putchar +%ifndef WATCOM + pop ecx +%endif + + popf + popa + leave + ret + + +print_nl: + enter 0,0 + pusha + pushf + +%ifdef WATCOM + mov eax, 10 ; WATCOM doesn't use the stack here +%else + push dword 10 ; 10 == ASCII code for \n +%endif + call _putchar +%ifndef WATCOM + pop ecx +%endif + popf + popa + leave + ret + + +sub_dump_regs: + enter 4,0 + pusha + pushf + mov eax, [esp] ; read FLAGS back off stack + mov [ebp-4], eax ; save flags + +; +; show which FLAGS are set +; + test eax, CF_MASK + jz cf_off + mov eax, carry_flag + jmp short push_cf +cf_off: + mov eax, unset_flag +push_cf: + push eax + + test dword [ebp-4], PF_MASK + jz pf_off + mov eax, parity_flag + jmp short push_pf +pf_off: + mov eax, unset_flag +push_pf: + push eax + + test dword [ebp-4], AF_MASK + jz af_off + mov eax, aux_carry_flag + jmp short push_af +af_off: + mov eax, unset_flag +push_af: + push eax + + test dword [ebp-4], ZF_MASK + jz zf_off + mov eax, zero_flag + jmp short push_zf +zf_off: + mov eax, unset_flag +push_zf: + push eax + + test dword [ebp-4], SF_MASK + jz sf_off + mov eax, sign_flag + jmp short push_sf +sf_off: + mov eax, unset_flag +push_sf: + push eax + + test dword [ebp-4], DF_MASK + jz df_off + mov eax, dir_flag + jmp short push_df +df_off: + mov eax, unset_flag +push_df: + push eax + + test dword [ebp-4], OF_MASK + jz of_off + mov eax, overflow_flag + jmp short push_of +of_off: + mov eax, unset_flag +push_of: + push eax + + push dword [ebp-4] ; FLAGS + mov eax, [ebp+4] + sub eax, 10 ; EIP on stack is 10 bytes ahead of orig + push eax ; EIP + lea eax, [ebp+12] + push eax ; original ESP + push dword [ebp] ; original EBP + push edi + push esi + push edx + push ecx + push ebx + push dword [ebp-8] ; original EAX + push dword [ebp+8] ; # of dump + push dword reg_format + call _printf + add esp, 76 + popf + popa + leave + ret 4 + +sub_dump_stack: + enter 0,0 + pusha + pushf + + lea eax, [ebp+20] + push eax ; original ESP + push dword [ebp] ; original EBP + push dword [ebp+8] ; # of dump + push dword stack_format + call _printf + add esp, 16 + + mov ebx, [ebp] ; ebx = original ebp + mov eax, [ebp+16] ; eax = # dwords above ebp + shl eax, 2 ; eax *= 4 + add ebx, eax ; ebx = & highest dword in stack to display + mov edx, [ebp+16] + mov ecx, edx + add ecx, [ebp+12] + inc ecx ; ecx = # of dwords to display + +stack_line_loop: + push edx + push ecx ; save ecx & edx + + push dword [ebx] ; value on stack + push ebx ; address of value on stack + mov eax, edx + sal eax, 2 ; eax = 4*edx + push eax ; offset from ebp + push dword stack_line_format + call _printf + add esp, 16 + + pop ecx + pop edx + + sub ebx, 4 + dec edx + loop stack_line_loop + + popf + popa + leave + ret 12 + + +sub_dump_mem: + enter 0,0 + pusha + pushf + + push dword [ebp+12] + push dword [ebp+16] + push dword mem_format1 + call _printf + add esp, 12 + mov esi, [ebp+12] ; address + and esi, 0FFFFFFF0h ; move to start of paragraph + mov ecx, [ebp+8] + inc ecx +mem_outer_loop: + push ecx + push esi + push dword mem_format2 + call _printf + add esp, 8 + + xor ebx, ebx +mem_hex_loop: + xor eax, eax + mov al, [esi + ebx] + push eax + push dword mem_format3 + call _printf + add esp, 8 + inc ebx + cmp ebx, 16 + jl mem_hex_loop + + mov eax, '"' + call print_char + xor ebx, ebx +mem_char_loop: + xor eax, eax + mov al, [esi+ebx] + cmp al, 32 + jl non_printable + cmp al, 126 + jg non_printable + jmp short mem_char_loop_continue +non_printable: + mov eax, '?' +mem_char_loop_continue: + call print_char + + inc ebx + cmp ebx, 16 + jl mem_char_loop + + mov eax, '"' + call print_char + call print_nl + + add esi, 16 + pop ecx + loop mem_outer_loop + + popf + popa + leave + ret 12 + +; function sub_dump_math +; prints out state of math coprocessor without modifying the coprocessor +; or regular processor state +; Parameters: +; dump number - dword at [ebp+8] +; Local variables: +; ebp-108 start of fsave buffer +; ebp-116 temp double +; Notes: This procedure uses the Pascal convention. +; fsave buffer structure: +; ebp-108 control word +; ebp-104 status word +; ebp-100 tag word +; ebp-80 ST0 +; ebp-70 ST1 +; ebp-60 ST2 ... +; ebp-10 ST7 +; +sub_dump_math: + enter 116,0 + pusha + pushf + + fsave [ebp-108] ; save coprocessor state to memory + mov eax, [ebp-104] ; status word + and eax, 0FFFFh + push eax + mov eax, [ebp-108] ; control word + and eax, 0FFFFh + push eax + push dword [ebp+8] + push dword math_format1 + call _printf + add esp, 16 +; +; rotate tag word so that tags in same order as numbers are +; in the stack +; + mov cx, [ebp-104] ; ax = status word + shr cx, 11 + and cx, 7 ; cl = physical state of number on stack top + mov bx, [ebp-100] ; bx = tag word + shl cl,1 ; cl *= 2 + ror bx, cl ; move top of stack tag to lowest bits + + mov edi, 0 ; edi = stack number of number + lea esi, [ebp-80] ; esi = address of ST0 + mov ecx, 8 ; ecx = loop counter +tag_loop: + push ecx + mov ax, 3 + and ax, bx ; ax = current tag + or ax, ax ; 00 -> valid number + je valid_st + cmp ax, 1 ; 01 -> zero + je zero_st + cmp ax, 2 ; 10 -> invalid number + je invalid_st + push edi ; 11 -> empty + push dword empty_st_format + call _printf + add esp, 8 + jmp short cont_tag_loop +zero_st: + fldz + jmp short print_real +valid_st: + fld tword [esi] +print_real: + fstp qword [ebp-116] + push dword [ebp-112] + push dword [ebp-116] + push edi + push dword valid_st_format + call _printf + add esp, 16 + jmp short cont_tag_loop +invalid_st: + push edi + push dword invalid_st_format + call _printf + add esp, 8 +cont_tag_loop: + ror bx, 2 ; mov next tag into lowest bits + inc edi + add esi, 10 ; mov to next number on stack + pop ecx + loop tag_loop + + frstor [ebp-108] ; restore coprocessor state + popf + popa + leave + ret 4 \ No newline at end of file diff --git a/worksheet_1/src/asm_io.inc b/Worksheet_1/src/asm_io.inc similarity index 100% rename from worksheet_1/src/asm_io.inc rename to Worksheet_1/src/asm_io.inc diff --git a/Worksheet_1/src/asm_io.o b/Worksheet_1/src/asm_io.o new file mode 100644 index 0000000000000000000000000000000000000000..d2921f0c774600089db73d581638199c58d10228 Binary files /dev/null and b/Worksheet_1/src/asm_io.o differ diff --git a/Worksheet_1/src/driver.c b/Worksheet_1/src/driver.c new file mode 100644 index 0000000000000000000000000000000000000000..64ba9001c4eed4765d503fec31e54eb9d4d46415 --- /dev/null +++ b/Worksheet_1/src/driver.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +// Declare the external assembly function +int _asm_main(void); + +int main() { + return _asm_main(); +} diff --git a/Worksheet_1/src/driver.o b/Worksheet_1/src/driver.o new file mode 100644 index 0000000000000000000000000000000000000000..8090fe23abb575b716b15004787dfe40aa48f0be Binary files /dev/null and b/Worksheet_1/src/driver.o differ diff --git a/Worksheet_1/src/print_int.c b/Worksheet_1/src/print_int.c new file mode 100644 index 0000000000000000000000000000000000000000..82049641dc463053cd63fd84dd0cfe65f3d00fdc --- /dev/null +++ b/Worksheet_1/src/print_int.c @@ -0,0 +1,5 @@ +#include <stdio.h> + +void _print_int(int num) { + printf("%d\n", num); +} diff --git a/Worksheet_1/src/print_int.o b/Worksheet_1/src/print_int.o new file mode 100644 index 0000000000000000000000000000000000000000..e5ddce09277b33588795be751817c50edd637d83 Binary files /dev/null and b/Worksheet_1/src/print_int.o differ diff --git a/Worksheet_1/src/task1 b/Worksheet_1/src/task1 new file mode 100644 index 0000000000000000000000000000000000000000..88a523743d9b9167a35ac9ede884eca3220a38f2 Binary files /dev/null and b/Worksheet_1/src/task1 differ diff --git a/Worksheet_1/src/task1.asm b/Worksheet_1/src/task1.asm new file mode 100644 index 0000000000000000000000000000000000000000..28e27ceb4d9919c2ae6c4c409b761e91e4d42362 --- /dev/null +++ b/Worksheet_1/src/task1.asm @@ -0,0 +1,23 @@ +%include "src/asm_io.inc" + +section .data + num1 dd 10 + num2 dd 20 + result dd 0 + +section .text + global _asm_main + extern _print_int + +_asm_main: + mov eax, [num1] + add eax, [num2] + mov [result], eax + + push eax + call _print_int + + add esp, 4 + ret + +section .note.GNU-stack noalloc noexec nowrite progbits diff --git a/Worksheet_1/src/task1.o b/Worksheet_1/src/task1.o new file mode 100644 index 0000000000000000000000000000000000000000..0fdf34bad3608b40d06e60add49bf528077429b4 Binary files /dev/null and b/Worksheet_1/src/task1.o differ diff --git a/Worksheet_1/src/task2 b/Worksheet_1/src/task2 new file mode 100644 index 0000000000000000000000000000000000000000..46d2d578c808f6fe51cb84355814143a0094b4c5 Binary files /dev/null and b/Worksheet_1/src/task2 differ diff --git a/Worksheet_1/src/task2.asm b/Worksheet_1/src/task2.asm new file mode 100644 index 0000000000000000000000000000000000000000..841981a96bb0c7c95cc8adde58d1876bc91a42d5 --- /dev/null +++ b/Worksheet_1/src/task2.asm @@ -0,0 +1,132 @@ +%include "src/asm_io.inc" + +section .data + prompt_name db "Enter your name: ", 0 + prompt_num db "Enter a number (50-100): ", 0 + error_msg db "Error: Number must be 50-100.", 10, 0 + welcome_msg db "Welcome, ", 0 + newline db 10, 0 + prompt_start db "Enter start index (1-100): ", 0 + prompt_end db "Enter end index (1-100): ", 0 + range_error db "Invalid range.", 10, 0 + sum_msg db "Sum of range: ", 0 + +section .bss + user_name resb 50 ; Buffer for user name + user_num resd 1 + array resd 100 + start_index resd 1 + end_index resd 1 + range_sum resd 1 + +section .text + global main + +main: + ; Prompt for and read user name + mov eax, prompt_name + call print_string + call read_name + + ; Get user number + mov eax, prompt_num + call print_string + call read_int + mov [user_num], eax + cmp eax, 50 + jl show_error + cmp eax, 100 + jg show_error + + ; Print welcome message + mov ecx, eax +welcome_loop: + mov eax, welcome_msg + call print_string + mov eax, user_name + call print_string + call print_nl + loop welcome_loop + jmp fill_array + +show_error: + mov eax, error_msg + call print_string + call print_nl + ret + +fill_array: + mov ecx, 100 + xor edi, edi +fill_loop: + mov eax, edi + inc eax + mov [array + edi * 4], eax + inc edi + loop fill_loop + call sum_range + +sum_range: + mov eax, prompt_start + call print_string + call read_int + mov [start_index], eax + mov eax, prompt_end + call print_string + call read_int + mov [end_index], eax + + ; Validate range + mov eax, [start_index] + cmp eax, 1 + jl invalid_range + cmp eax, 100 + jg invalid_range + mov ebx, [end_index] + cmp ebx, 1 + jl invalid_range + cmp ebx, 100 + jg invalid_range + cmp eax, ebx + jg invalid_range + + ; Sum range + xor ecx, ecx + mov edi, eax +sum_loop: + add ecx, [array + (edi - 1) * 4] + inc edi + cmp edi, ebx + jg display_sum + jmp sum_loop + +display_sum: + mov [range_sum], ecx + mov eax, sum_msg + call print_string + mov eax, [range_sum] + call print_int + call print_nl + ret + +invalid_range: + mov eax, range_error + call print_string + call print_nl + ret + +; Reads a name character-by-character and stores it in user_name +read_name: + mov edi, user_name ; Point to user_name buffer +read_char_loop: + call read_char ; Read one character + cmp al, 10 ; Check for Enter key (newline) + je end_read_name ; If Enter, finish + mov [edi], al ; Store the character in the buffer + inc edi ; Move to the next position + cmp edi, user_name + 50 ; Ensure we don't exceed the buffer + jne read_char_loop ; Repeat until buffer is full or Enter is pressed + +end_read_name: + mov byte [edi], 0 ; Null-terminate the string + ret diff --git a/Worksheet_1/src/task2.o b/Worksheet_1/src/task2.o new file mode 100644 index 0000000000000000000000000000000000000000..1350a839d50964848196e916937d40860000b6cb Binary files /dev/null and b/Worksheet_1/src/task2.o differ diff --git a/Worksheet_1/src/task3 b/Worksheet_1/src/task3 new file mode 100644 index 0000000000000000000000000000000000000000..875aa5b4cd87366df0cf448446624b48bddae443 Binary files /dev/null and b/Worksheet_1/src/task3 differ diff --git a/Worksheet_1/src/task3.asm b/Worksheet_1/src/task3.asm new file mode 100644 index 0000000000000000000000000000000000000000..8846cb9ba96f08433b607216b99d61c4d662cec7 --- /dev/null +++ b/Worksheet_1/src/task3.asm @@ -0,0 +1,98 @@ +%include "src/asm_io.inc" + +section .data + prompt_array db "Enter numbers (one by one): ", 0 + prompt_size db "Enter size of the array: ", 0 + max_msg db "Maximum value is: ", 0 + min_msg db "Minimum value is: ", 0 + sum_msg db "Sum of all values is: ", 0 + newline db 10, 0 + +section .bss + array resd 100 ; Reserve space for an array of 100 integers + size resd 1 ; Store the size of the array + max_val resd 1 ; Store the maximum value + min_val resd 1 ; Store the minimum value + total resd 1 ; Store the sum of the array elements + +section .text + global main + +main: + ; Prompt user for array size + mov eax, prompt_size + call print_string + call read_int + mov [size], eax + + ; Fill the array + mov ecx, [size] + xor edi, edi ; Index for the array +fill_array: + mov eax, prompt_array + call print_string + call read_int ; Read one integer + mov [array + edi * 4], eax + inc edi + loop fill_array + + ; Find maximum and minimum values + call find_max_min + + ; Calculate the sum of the array + call calculate_sum + + ; Print results + mov eax, max_msg + call print_string + mov eax, [max_val] + call print_int + call print_nl + + mov eax, min_msg + call print_string + mov eax, [min_val] + call print_int + call print_nl + + mov eax, sum_msg + call print_string + mov eax, [total] + call print_int + call print_nl + ret + +find_max_min: + mov ecx, [size] + mov edi, 0 + mov eax, [array] ; Load the first element + mov ebx, eax ; Assume it is the maximum + mov edx, eax ; Assume it is the minimum +find_loop: + mov eax, [array + edi * 4] + cmp eax, ebx + jle check_min + mov ebx, eax ; Update maximum +check_min: + cmp eax, edx + jge next + mov edx, eax ; Update minimum +next: + inc edi + loop find_loop + mov [max_val], ebx + mov [min_val], edx + ret + +calculate_sum: + mov ecx, [size] + mov edi, 0 + xor eax, eax ; Initialize sum to 0 +sum_loop: + add eax, [array + edi * 4] + inc edi + loop sum_loop + mov [total], eax + ret + + diff --git a/Worksheet_1/src/task3.o b/Worksheet_1/src/task3.o new file mode 100644 index 0000000000000000000000000000000000000000..82d98d4c2bf567bc1b89f1f5b354fa9ad290bb0d Binary files /dev/null and b/Worksheet_1/src/task3.o differ diff --git a/worksheet_1/README.md b/worksheet_1/README.md deleted file mode 100644 index c4ab675cf56a056268710e3a0fba1728ee1ff1eb..0000000000000000000000000000000000000000 --- a/worksheet_1/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Operating Systems Worksheet 1 - -## Overview -This repository contains my solutions for Worksheet 1 of the Operating Systems module. The tasks include: -- Basic assembler programming. -- Translating C loops into assembler. -- Using Makefiles to automate builds. - -## Repository Structure diff --git a/worksheet_1/makefile b/worksheet_1/makefile deleted file mode 100644 index f36e333afa189629f9dae0972a790e8375a9395b..0000000000000000000000000000000000000000 --- a/worksheet_1/makefile +++ /dev/null @@ -1,27 +0,0 @@ -NASM = nasm -f macho64 -GCC = gcc -arch x86_64 -SRC_DIR = src -OBJ_DIR = src - -all: task1 task2 task3 task4 - -task1: $(OBJ_DIR)/task1.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o - $(GCC) $^ -o task1 - -task2: $(OBJ_DIR)/task2.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o - $(GCC) $^ -o task2 - -task3: $(OBJ_DIR)/task3.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o - $(GCC) $^ -o task3 - -task4: $(OBJ_DIR)/task4.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o - $(GCC) $^ -o task4 - -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.asm - $(NASM) $< -o $@ - -$(OBJ_DIR)/driver.o: $(SRC_DIR)/driver.c - $(GCC) -c $< -o $@ - -clean: - rm -f task1 task2 task3 task4 $(OBJ_DIR)/*.o diff --git a/worksheet_1/src/asm_io.asm b/worksheet_1/src/asm_io.asm deleted file mode 100644 index 2e6e666792b5fb894ac64e0c3128bb930694d77d..0000000000000000000000000000000000000000 --- a/worksheet_1/src/asm_io.asm +++ /dev/null @@ -1,26 +0,0 @@ -; -; file: asm_io.asm -; Assembly I/O routines -; To assemble for DJGPP -; nasm -f coff -d COFF_TYPE asm_io.asm -; To assemble for Borland C++ 5.x -; nasm -f obj -d OBJ_TYPE asm_io.asm -; To assemble for Microsoft Visual Studio -; nasm -f win32 -d COFF_TYPE asm_io.asm -; To assemble for Linux -; nasm -f elf -d ELF_TYPE asm_io.asm -; To assemble for Watcom -; nasm -f obj -d OBJ_TYPE -d WATCOM asm_io.asm -; IMPORTANT NOTES FOR WATCOM -; The Watcom compiler's C library does not use the -; standard C calling convention. For example, the -; putchar() function gets its argument from the -; the value of EAX, not the stack. - - -%define NL 10 -%define CF_MASK 00000001h -%define PF_MASK 00000004h -%define AF_MASK 00000010h -%define ZF_MASK 00000040h -%define SF_MASK 00000080h \ No newline at end of file diff --git a/worksheet_1/src/asm_io.o b/worksheet_1/src/asm_io.o deleted file mode 100644 index d75ea1f27158915097669a9fe1672cfa3c2e56e7..0000000000000000000000000000000000000000 Binary files a/worksheet_1/src/asm_io.o and /dev/null differ diff --git a/worksheet_1/src/driver.c b/worksheet_1/src/driver.c deleted file mode 100644 index d386c74936eba2544246ad72a6344e7d61d3e60b..0000000000000000000000000000000000000000 --- a/worksheet_1/src/driver.c +++ /dev/null @@ -1,7 +0,0 @@ -int __attribute__((cdecl)) asm_main(void); - -int main() { - int ret_status; - ret_status = asm_main(); - return ret_status; -} diff --git a/worksheet_1/src/driver.o b/worksheet_1/src/driver.o deleted file mode 100644 index 6c725f2e37968a41072c6e57680baf5d9f6f68d9..0000000000000000000000000000000000000000 Binary files a/worksheet_1/src/driver.o and /dev/null differ diff --git a/worksheet_1/src/task1.asm b/worksheet_1/src/task1.asm deleted file mode 100644 index 34d554ac08fb1c938678b6040d5ce2416a0278a7..0000000000000000000000000000000000000000 --- a/worksheet_1/src/task1.asm +++ /dev/null @@ -1,17 +0,0 @@ -section .data - num1 dd 10 - num2 dd 20 - result dd 0 - -section .text - global asm_main - extern print_int - -asm_main: - mov eax, [num1] - add eax, [num2] - mov [result], eax - push eax - call print_int - add rsp, 8 - ret diff --git a/worksheet_1/src/task1.o b/worksheet_1/src/task1.o deleted file mode 100644 index 16322411018601cd7b758cef60386d91406c0583..0000000000000000000000000000000000000000 Binary files a/worksheet_1/src/task1.o and /dev/null differ diff --git a/worksheet_1/src/task2.asm b/worksheet_1/src/task2.asm deleted file mode 100644 index 9a783d9bdfac2640d9c880b79944d8226bcfba83..0000000000000000000000000000000000000000 --- a/worksheet_1/src/task2.asm +++ /dev/null @@ -1,53 +0,0 @@ -section .bss - name resb 32 - count resd 1 - -section .text - global asm_main - extern print_string, print_int, read_int, read_string - -asm_main: - ; Prompt for name - push message_name - call print_string - add rsp, 8 - - push name - call read_string - add rsp, 8 - - ; Prompt for count - push message_count - call print_string - add rsp, 8 - - push count - call read_int - add rsp, 8 - - ; Validate count - mov eax, [count] - cmp eax, 50 - jl invalid - cmp eax, 100 - jg invalid - - ; Print welcome message -print_loop: - push name - call print_string - add rsp, 8 - dec eax - jnz print_loop - ret - -invalid: - push error_message - call print_string - add rsp, 8 - ret - -section .data - message_name db "Enter your name: ", 0 - message_count db "Enter a number (50-100): ", 0 - error_message db "Invalid input!", 0 diff --git a/worksheet_1/src/task3.asm b/worksheet_1/src/task3.asm deleted file mode 100644 index d26a59fc309413bdd35871f547f58e35a97853bb..0000000000000000000000000000000000000000 --- a/worksheet_1/src/task3.asm +++ /dev/null @@ -1,35 +0,0 @@ -section .data - array dd 1, 2, 3, ..., 100 ; Replace ... with remaining numbers - sum dd 0 - -section .text - global asm_main - extern print_int - -asm_main: - mov ecx, 100 ; Counter for 100 elements - mov esi, array ; Start of the array - xor eax, eax ; Accumulator - -sum_loop: - add eax, [esi] - add esi, 4 ; Move to the next integer - loop sum_loop - - mov [sum], eax - push eax - call print_int - add rsp, 8 - ret - -array dd 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 - diff --git a/worksheet_1/src/task4.asm b/worksheet_1/src/task4.asm deleted file mode 100644 index 64bd5fa28e6ed252ce6b4d1bd09238691d0a5e1c..0000000000000000000000000000000000000000 --- a/worksheet_1/src/task4.asm +++ /dev/null @@ -1,78 +0,0 @@ -section .bss - start resd 1 - end resd 1 - -section .data - array dd 1, 2, 3, ..., 100 ; Replace ... with remaining numbers - sum dd 0 - -section .text - global asm_main - extern print_int, read_int, print_string - -asm_main: - ; Prompt for range - push message_start - call print_string - add rsp, 8 - push start - call read_int - add rsp, 8 - - push message_end - call print_string - add rsp, 8 - push end - call read_int - add rsp, 8 - - ; Validate range - mov eax, [start] - cmp eax, 1 - jl invalid - mov ebx, [end] - cmp ebx, 100 - jg invalid - cmp eax, ebx - jg invalid - - ; Calculate sum - xor ecx, ecx - mov esi, array - sub eax, 1 - imul eax, eax, 4 - add esi, eax - mov ecx, ebx - sub ecx, eax ; Range length - -sum_range: - add eax, [esi] - add esi, 4 - loop sum_range - - push eax - call print_int - add rsp, 8 - ret - -invalid: - push error_message - call print_string - add rsp, 8 - ret - -section .data - message_start db "Enter start of range (1-100): ", 0 - message_end db "Enter end of range (1-100): ", 0 - error_message db "Invalid range!", 0 - -array dd 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, 93, 94, 95, 96, 97, 98, 99, 100