diff --git a/worksheet_1/makefile b/worksheet_1/makefile index 1a1f4314fa526e9ac38d8a00200c3208263cff68..f36e333afa189629f9dae0972a790e8375a9395b 100644 --- a/worksheet_1/makefile +++ b/worksheet_1/makefile @@ -1,28 +1,27 @@ +NASM = nasm -f macho64 +GCC = gcc -arch x86_64 +SRC_DIR = src +OBJ_DIR = src + all: task1 task2 task3 task4 -task1: src/task1.asm src/asm_io.asm src/driver.c - nasm -f elf src/task1.asm -o src/task1.o - nasm -f elf src/asm_io.asm -o src/asm_io.o - gcc -m32 -c src/driver.c -o src/driver.o - gcc -m32 src/task1.o src/asm_io.o src/driver.o -o task1 - -task2: src/task2.asm src/asm_io.asm src/driver.c - nasm -f elf src/task2.asm -o src/task2.o - nasm -f elf src/asm_io.asm -o src/asm_io.o - gcc -m32 -c src/driver.c -o src/driver.o - gcc -m32 src/task2.o src/asm_io.o src/driver.o -o task2 - -task3: src/task3.asm src/asm_io.asm src/driver.c - nasm -f elf src/task3.asm -o src/task3.o - nasm -f elf src/asm_io.asm -o src/asm_io.o - gcc -m32 -c src/driver.c -o src/driver.o - gcc -m32 src/task3.o src/asm_io.o src/driver.o -o task3 - -task4: src/task4.asm src/asm_io.asm src/driver.c - nasm -f elf src/task4.asm -o src/task4.o - nasm -f elf src/asm_io.asm -o src/asm_io.o - gcc -m32 -c src/driver.c -o src/driver.o - gcc -m32 src/task4.o src/asm_io.o src/driver.o -o 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 src/*.o + rm -f task1 task2 task3 task4 $(OBJ_DIR)/*.o diff --git a/worksheet_1/src/driver.o b/worksheet_1/src/driver.o index 964d1066906062baddae6f1a5a2c83c8b9222b7e..6c725f2e37968a41072c6e57680baf5d9f6f68d9 100644 Binary files a/worksheet_1/src/driver.o and b/worksheet_1/src/driver.o differ diff --git a/worksheet_1/src/task1.asm b/worksheet_1/src/task1.asm index 0442b2c42e236974799f1b00f33c02689b4661c2..34d554ac08fb1c938678b6040d5ce2416a0278a7 100644 --- a/worksheet_1/src/task1.asm +++ b/worksheet_1/src/task1.asm @@ -13,5 +13,5 @@ asm_main: mov [result], eax push eax call print_int - add esp, 4 + add rsp, 8 ret diff --git a/worksheet_1/src/task2.asm b/worksheet_1/src/task2.asm index a2eea578d6c38191c15084f8ce77a88e18a69149..9a783d9bdfac2640d9c880b79944d8226bcfba83 100644 --- a/worksheet_1/src/task2.asm +++ b/worksheet_1/src/task2.asm @@ -10,20 +10,20 @@ asm_main: ; Prompt for name push message_name call print_string - add esp, 4 + add rsp, 8 push name call read_string - add esp, 4 + add rsp, 8 ; Prompt for count push message_count call print_string - add esp, 4 + add rsp, 8 push count call read_int - add esp, 4 + add rsp, 8 ; Validate count mov eax, [count] @@ -36,7 +36,7 @@ asm_main: print_loop: push name call print_string - add esp, 4 + add rsp, 8 dec eax jnz print_loop ret @@ -44,7 +44,7 @@ print_loop: invalid: push error_message call print_string - add esp, 4 + add rsp, 8 ret section .data diff --git a/worksheet_1/src/task3.asm b/worksheet_1/src/task3.asm index 91d006b0b3a1d4b586882b852ba57a58c3494d0c..d26a59fc309413bdd35871f547f58e35a97853bb 100644 --- a/worksheet_1/src/task3.asm +++ b/worksheet_1/src/task3.asm @@ -19,5 +19,17 @@ sum_loop: mov [sum], eax push eax call print_int - add esp, 4 + 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 index a7facb283eedf7d9993cb6a0a64fa13434be53bf..64bd5fa28e6ed252ce6b4d1bd09238691d0a5e1c 100644 --- a/worksheet_1/src/task4.asm +++ b/worksheet_1/src/task4.asm @@ -14,17 +14,17 @@ asm_main: ; Prompt for range push message_start call print_string - add esp, 4 + add rsp, 8 push start call read_int - add esp, 4 + add rsp, 8 push message_end call print_string - add esp, 4 + add rsp, 8 push end call read_int - add esp, 4 + add rsp, 8 ; Validate range mov eax, [start] @@ -40,7 +40,8 @@ asm_main: xor ecx, ecx mov esi, array sub eax, 1 - add esi, eax * 4 ; Adjust start index + imul eax, eax, 4 + add esi, eax mov ecx, ebx sub ecx, eax ; Range length @@ -51,16 +52,27 @@ sum_range: push eax call print_int - add esp, 4 + add rsp, 8 ret invalid: push error_message call print_string - add esp, 4 + 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