Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions curs/chap-05-ihs/00-intro/Makefile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions curs/chap-05-ihs/00-intro/decl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int a = 9;
int b;

char t = 1;

void main()
{
int a, b;
a = 0;
b = 7;
}
52 changes: 52 additions & 0 deletions curs/chap-05-ihs/00-intro/declarations.asm
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions curs/chap-05-ihs/00-intro/mul.asm
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions curs/chap-05-ihs/00-intro/subreg.asm
Original file line number Diff line number Diff line change
@@ -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