Skip to content
Snippets Groups Projects
Commit 660a0557 authored by Hazal2.Veziroglu@live.uwe.ac.uk's avatar Hazal2.Veziroglu@live.uwe.ac.uk
Browse files

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
parent a7e5a6d4
No related branches found
No related tags found
No related merge requests found
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
No preview for this file type
......@@ -13,5 +13,5 @@ asm_main:
mov [result], eax
push eax
call print_int
add esp, 4
add rsp, 8
ret
......@@ -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
......
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment