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 all: task1 task2 task3 task4
task1: src/task1.asm src/asm_io.asm src/driver.c task1: $(OBJ_DIR)/task1.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o
nasm -f elf src/task1.asm -o src/task1.o $(GCC) $^ -o task1
nasm -f elf src/asm_io.asm -o src/asm_io.o
gcc -m32 -c src/driver.c -o src/driver.o task2: $(OBJ_DIR)/task2.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o
gcc -m32 src/task1.o src/asm_io.o src/driver.o -o task1 $(GCC) $^ -o task2
task2: src/task2.asm src/asm_io.asm src/driver.c task3: $(OBJ_DIR)/task3.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o
nasm -f elf src/task2.asm -o src/task2.o $(GCC) $^ -o task3
nasm -f elf src/asm_io.asm -o src/asm_io.o
gcc -m32 -c src/driver.c -o src/driver.o task4: $(OBJ_DIR)/task4.o $(OBJ_DIR)/asm_io.o $(OBJ_DIR)/driver.o
gcc -m32 src/task2.o src/asm_io.o src/driver.o -o task2 $(GCC) $^ -o task4
task3: src/task3.asm src/asm_io.asm src/driver.c $(OBJ_DIR)/%.o: $(SRC_DIR)/%.asm
nasm -f elf src/task3.asm -o src/task3.o $(NASM) $< -o $@
nasm -f elf src/asm_io.asm -o src/asm_io.o
gcc -m32 -c src/driver.c -o src/driver.o $(OBJ_DIR)/driver.o: $(SRC_DIR)/driver.c
gcc -m32 src/task3.o src/asm_io.o src/driver.o -o task3 $(GCC) -c $< -o $@
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
clean: 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: ...@@ -13,5 +13,5 @@ asm_main:
mov [result], eax mov [result], eax
push eax push eax
call print_int call print_int
add esp, 4 add rsp, 8
ret ret
...@@ -10,20 +10,20 @@ asm_main: ...@@ -10,20 +10,20 @@ asm_main:
; Prompt for name ; Prompt for name
push message_name push message_name
call print_string call print_string
add esp, 4 add rsp, 8
push name push name
call read_string call read_string
add esp, 4 add rsp, 8
; Prompt for count ; Prompt for count
push message_count push message_count
call print_string call print_string
add esp, 4 add rsp, 8
push count push count
call read_int call read_int
add esp, 4 add rsp, 8
; Validate count ; Validate count
mov eax, [count] mov eax, [count]
...@@ -36,7 +36,7 @@ asm_main: ...@@ -36,7 +36,7 @@ asm_main:
print_loop: print_loop:
push name push name
call print_string call print_string
add esp, 4 add rsp, 8
dec eax dec eax
jnz print_loop jnz print_loop
ret ret
...@@ -44,7 +44,7 @@ print_loop: ...@@ -44,7 +44,7 @@ print_loop:
invalid: invalid:
push error_message push error_message
call print_string call print_string
add esp, 4 add rsp, 8
ret ret
section .data section .data
......
...@@ -19,5 +19,17 @@ sum_loop: ...@@ -19,5 +19,17 @@ sum_loop:
mov [sum], eax mov [sum], eax
push eax push eax
call print_int call print_int
add esp, 4 add rsp, 8
ret 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: ...@@ -14,17 +14,17 @@ asm_main:
; Prompt for range ; Prompt for range
push message_start push message_start
call print_string call print_string
add esp, 4 add rsp, 8
push start push start
call read_int call read_int
add esp, 4 add rsp, 8
push message_end push message_end
call print_string call print_string
add esp, 4 add rsp, 8
push end push end
call read_int call read_int
add esp, 4 add rsp, 8
; Validate range ; Validate range
mov eax, [start] mov eax, [start]
...@@ -40,7 +40,8 @@ asm_main: ...@@ -40,7 +40,8 @@ asm_main:
xor ecx, ecx xor ecx, ecx
mov esi, array mov esi, array
sub eax, 1 sub eax, 1
add esi, eax * 4 ; Adjust start index imul eax, eax, 4
add esi, eax
mov ecx, ebx mov ecx, ebx
sub ecx, eax ; Range length sub ecx, eax ; Range length
...@@ -51,16 +52,27 @@ sum_range: ...@@ -51,16 +52,27 @@ sum_range:
push eax push eax
call print_int call print_int
add esp, 4 add rsp, 8
ret ret
invalid: invalid:
push error_message push error_message
call print_string call print_string
add esp, 4 add rsp, 8
ret ret
section .data section .data
message_start db "Enter start of range (1-100): ", 0 message_start db "Enter start of range (1-100): ", 0
message_end db "Enter end of range (1-100): ", 0 message_end db "Enter end of range (1-100): ", 0
error_message db "Invalid range!", 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