From 660a055729d56fdad17d4518dbcb9f16636a57f3 Mon Sep 17 00:00:00 2001
From: "Hazal2.Veziroglu@live.uwe.ac.uk" <hazal2.veziroglu@live.uwe.ac.uk>
Date: Thu, 28 Nov 2024 22:15:14 +0000
Subject: [PATCH] Update 6 files

- /worksheet_1/makefile
- /worksheet_1/src/task2.asm
- /worksheet_1/src/task3.asm
- /worksheet_1/src/task1.asm
- /worksheet_1/src/task4.asm
- /worksheet_1/src/driver.o
---
 worksheet_1/makefile      |  47 +++++++++++++++++++-------------------
 worksheet_1/src/driver.o  | Bin 572 -> 664 bytes
 worksheet_1/src/task1.asm |   2 +-
 worksheet_1/src/task2.asm |  12 +++++-----
 worksheet_1/src/task3.asm |  14 +++++++++++-
 worksheet_1/src/task4.asm |  26 +++++++++++++++------
 6 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/worksheet_1/makefile b/worksheet_1/makefile
index 1a1f431..f36e333 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
GIT binary patch
literal 664
zcmX^A>+L^w1_nlE1_lO31_lNe1_p*5Acg`17)UZOFj#>2U>+vX02R6cRRiO*GcYiK
zFvwhxlKA+N)QS=i3xeb0LtG<5AZ%n3YAplEJdj%=m>}+AU}1n64OSi>pPZjtkeFN&
zUz%5*nU@kD@8bfNfD$lsVDt}01_qE@5@6;rFfc)tf~olU)QtGFqQu-(FqZ+{eGU*|
z1{f{D1ThaP%)rgSkO5<ZXd?y&1_@}GGBEHnFfj6igu#}A#50&64(MQFU=Uzn0O@B4
z0INU{pdf`|geY;WP>;^19?fqAj=TN=X?Ou5I$eKsyZ-QKJ|Yl%7{mu*X!wAv0de72
z1j=Hp3SwZa5MUJGVdt2@$iSe&z`!8Gz`(HJKLkMaGcY*v3A8ae^Rhwpf&9eCz@Q7_
iGBPl*u`)0)@FUp*VuCP89*pA?i*w_16EpL`JO%&&N<2XT

delta 280
zcmbQix`##S+^@I)*cliYm>C!t7#SECSQr=>T0jg1D4%iiMn*Bt3<d^<1&j;~852Xz
zd1av-kXnw33xy}{P~jC}U|=}F$iTqFz`!6d@uTo$4n_rD69xtb5WWJEm~6`^J~@Js
zPo9r~fdPaeiX|8r7$le=Yy&0+2A;{Sj3L^cPn+Lx9C!W0z`(%p;@$uM|2tiObi4j&
zKEe@u7$nBPzyNXu$kCGpm_$8lI2Z+ZSXnw485lqY$}li6toi@{KUj?;A4dz56EDcM
gAZr;J7<fTOFfuT(ure?(@Pm8{G6;kxH!=wW03^jOy#N3J

diff --git a/worksheet_1/src/task1.asm b/worksheet_1/src/task1.asm
index 0442b2c..34d554a 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 a2eea57..9a783d9 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 91d006b..d26a59f 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 a7facb2..64bd5fa 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
-- 
GitLab