diff --git a/curs/chap-05-ihs/00-intro/Makefile b/curs/chap-05-ihs/00-intro/Makefile new file mode 100644 index 00000000..7deeb706 --- /dev/null +++ b/curs/chap-05-ihs/00-intro/Makefile @@ -0,0 +1,46 @@ +CC = gcc +CFLAGS = -O2 -m32 -g -fno-PIC +NASM = nasm +ASM_FLAGS = -f elf32 -g -F dwarf +LD = ld -melf_i386 -no-pie + +all : hello + +sum_array: sum_array.o + $(CC) -m32 -no-pie -o sum_array sum_array.o + + +mul: mul.o + $(CC) -m32 -no-pie -o mul mul.o + +subreg: subreg.o + $(CC) -m32 -no-pie -o subreg subreg.o + +declarations: declarations.o + $(CC) -m32 -no-pie -o declarations declarations.o + +decl: decl.o + $(CC) -m32 -no-pie -o decl decl.o + +%.o : %.c + $(warning CC=$(CC) FLAGS=$(CFLAGS)) + $(CC) -c $(CFLAGS) -o $@ $< + +sum_array.o : sum_array.asm + $(warning NASM=$(NASM) FLAGS=$(ASM_FLAGS)) + $(NASM) $(ASM_FLAGS) -o $@ $< + + +declarations.o : declarations.asm + $(warning NASM=$(NASM) FLAGS=$(ASM_FLAGS)) + $(NASM) $(ASM_FLAGS) -o $@ $< + +mul.o : mul.asm + $(warning NASM=$(NASM) FLAGS=$(ASM_FLAGS)) + $(NASM) $(ASM_FLAGS) -o $@ $< + +subreg.o : subreg.asm + $(warning NASM=$(NASM) FLAGS=$(ASM_FLAGS)) + $(NASM) $(ASM_FLAGS) -o $@ $< +clean: + rm -f *.o subreg declarations decl mul sum_array diff --git a/curs/chap-05-ihs/00-intro/decl.c b/curs/chap-05-ihs/00-intro/decl.c new file mode 100644 index 00000000..13acbaf3 --- /dev/null +++ b/curs/chap-05-ihs/00-intro/decl.c @@ -0,0 +1,11 @@ +int a = 9; +int b; + +char t = 1; + +void main() +{ + int a, b; + a = 0; + b = 7; +} diff --git a/curs/chap-05-ihs/00-intro/declarations.asm b/curs/chap-05-ihs/00-intro/declarations.asm new file mode 100644 index 00000000..e5f1b141 --- /dev/null +++ b/curs/chap-05-ihs/00-intro/declarations.asm @@ -0,0 +1,52 @@ +section .data + var1: db 9 + var2: dw 10 + var3: dd 11 + arr1: db 8, 9, 10 + arr2: dw 8, 9, 10 + arr3: dd 0xAABBCCDD, 0x11223344, 0x55667788 + str: db "Hello World",0 + +section .bss + a: resb 4 + +section .rodata + b: dd 9 + +section .text + global main + +main: + xor eax, eax + mov al, [var1] + mov ah, [var1] + mov ax, [var2] + mov eax, [var3] + + xor ebx, ebx + mov bl, [arr1] + mov bh, [arr1 + 1] + mov bl, [arr1 + 2] + + mov bx, [arr2] + mov bx, [arr2 + 2] + mov bx, [arr2 + 3] + + mov ebx, [arr3 + 4] + + mov cl, [str] + mov ecx, [str] + + mov eax, [a] + mov ebx, [b] + + mov ax, [var1] + mov ax, [var1 + 1] + mov eax, [var1] + mov eax, [arr3 + 2] + + mov dword[a], 0xaabbccdd + ;mov [b], ebx + mov dword[a], 20 + + ret diff --git a/curs/chap-05-ihs/00-intro/mul.asm b/curs/chap-05-ihs/00-intro/mul.asm new file mode 100644 index 00000000..4ace2e47 --- /dev/null +++ b/curs/chap-05-ihs/00-intro/mul.asm @@ -0,0 +1,36 @@ +section .data + num1: dd 10 + num2: dd 40 + + num3: dw 500 + num4: dw 3 + + num5: dw 1 + +section .bss + a: resb 4 + +section .text + global main + +main: + + mov al, [num1] + mov bl, [num2] + + mul bl + + mov ax, [num3] + xor dx, dx + mov cx, [num5] + div cx + + mov ax, [num3] + mov cl, [num4] + div cl + + ;mov ax, [num3] + ;mov cl, [num5] + ;div cl + + ret diff --git a/curs/chap-05-ihs/00-intro/subreg.asm b/curs/chap-05-ihs/00-intro/subreg.asm new file mode 100644 index 00000000..c5c5fe5c --- /dev/null +++ b/curs/chap-05-ihs/00-intro/subreg.asm @@ -0,0 +1,11 @@ +section .text + global main + +main: + mov eax, 1 + shl eax, 28 + mov al, 10 + mov ah, 10 + mov eax, 11 + ret +