From fe21fb97acaa55e67dfcabf08c9f33ec3866636d Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:10:46 +0200 Subject: [PATCH 1/7] chap-05: Add demo showing variable use This is a C demo that should be compiled and linked and then disassembled. Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/01-disass/.gitignore | 2 ++ curs/chap-05-ihs/01-disass/Makefile | 19 ++++++++++++ curs/chap-05-ihs/01-disass/many_vars.c | 41 ++++++++++++++++++++++++++ curs/chap-05-ihs/01-disass/one_var.c | 13 ++++++++ 4 files changed, 75 insertions(+) create mode 100644 curs/chap-05-ihs/01-disass/.gitignore create mode 100644 curs/chap-05-ihs/01-disass/Makefile create mode 100644 curs/chap-05-ihs/01-disass/many_vars.c create mode 100644 curs/chap-05-ihs/01-disass/one_var.c diff --git a/curs/chap-05-ihs/01-disass/.gitignore b/curs/chap-05-ihs/01-disass/.gitignore new file mode 100644 index 00000000..ba00f350 --- /dev/null +++ b/curs/chap-05-ihs/01-disass/.gitignore @@ -0,0 +1,2 @@ +/one_var +/many_vars diff --git a/curs/chap-05-ihs/01-disass/Makefile b/curs/chap-05-ihs/01-disass/Makefile new file mode 100644 index 00000000..e9b000be --- /dev/null +++ b/curs/chap-05-ihs/01-disass/Makefile @@ -0,0 +1,19 @@ +CFLAGS = -m32 -fno-PIC -Wall +LDFLAGS = -m32 -no-pie + +.PHONY: all clean + +all: one_var many_vars + +one_var: one_var.o + +one_var.o: one_var.c + +many_vars: many_vars.o + +many_vars.o: many_vars.c + +clean: + -rm -f *~ + -rm -f one_var.o one_var + -rm -f many_vars.o many_vars diff --git a/curs/chap-05-ihs/01-disass/many_vars.c b/curs/chap-05-ihs/01-disass/many_vars.c new file mode 100644 index 00000000..22bae9af --- /dev/null +++ b/curs/chap-05-ihs/01-disass/many_vars.c @@ -0,0 +1,41 @@ +#include +#include + +unsigned int age = 10; +unsigned short new_age; + +struct { + unsigned int age; + unsigned short occupation; + unsigned int new_age; + unsigned char location; +} s; + +unsigned int v[4] = {10, 20, 30, 40}; +unsigned int *p; + +void g(void) +{ + s.age = 10; + s.occupation = 20; + s.new_age = 30; + s.location = 40; + + v[2] = 1000; + p = &v[2]; +} + +void f(void) +{ + new_age = age + 4; +} + +unsigned long long alfa(void) +{ + return 119328984948393; +} + +int main(void) +{ + return 0; +} diff --git a/curs/chap-05-ihs/01-disass/one_var.c b/curs/chap-05-ihs/01-disass/one_var.c new file mode 100644 index 00000000..7d8d0c3e --- /dev/null +++ b/curs/chap-05-ihs/01-disass/one_var.c @@ -0,0 +1,13 @@ +#include + +unsigned int age = 32; + +void f(void) +{ + age = 64; +} + +int main(void) +{ + return 0; +} From cc99118784aa5560a7beb47de451f607b01431f2 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:13:11 +0200 Subject: [PATCH 2/7] chap-05: Add demo showing jmp and je use cases This is a C demo that should be compiled and linked and then disassembled. Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/02-jmp/.gitignore | 2 ++ curs/chap-05-ihs/02-jmp/Makefile | 19 +++++++++++++++++++ curs/chap-05-ihs/02-jmp/je.c | 12 ++++++++++++ curs/chap-05-ihs/02-jmp/jmp.c | 10 ++++++++++ 4 files changed, 43 insertions(+) create mode 100644 curs/chap-05-ihs/02-jmp/.gitignore create mode 100644 curs/chap-05-ihs/02-jmp/Makefile create mode 100644 curs/chap-05-ihs/02-jmp/je.c create mode 100644 curs/chap-05-ihs/02-jmp/jmp.c diff --git a/curs/chap-05-ihs/02-jmp/.gitignore b/curs/chap-05-ihs/02-jmp/.gitignore new file mode 100644 index 00000000..f884f990 --- /dev/null +++ b/curs/chap-05-ihs/02-jmp/.gitignore @@ -0,0 +1,2 @@ +/je +/jmp diff --git a/curs/chap-05-ihs/02-jmp/Makefile b/curs/chap-05-ihs/02-jmp/Makefile new file mode 100644 index 00000000..d2f8aed7 --- /dev/null +++ b/curs/chap-05-ihs/02-jmp/Makefile @@ -0,0 +1,19 @@ +CFLAGS = -m32 -fno-PIC -Wall +LDFLAGS = -m32 -no-pie + +.PHONY: all clean + +all: jmp je + +jmp: jmp.o + +jmp.o: jmp.c + +je: je.o + +je.o: je.c + +clean: + -rm -f *~ + -rm -f jmp.o jmp + -rm -f je.o je diff --git a/curs/chap-05-ihs/02-jmp/je.c b/curs/chap-05-ihs/02-jmp/je.c new file mode 100644 index 00000000..20fcc0ec --- /dev/null +++ b/curs/chap-05-ihs/02-jmp/je.c @@ -0,0 +1,12 @@ +unsigned int i; + +int main(void) +{ + i = 0; + + if (i > 0) + i += 1; + i += 2; + + return 0; +} diff --git a/curs/chap-05-ihs/02-jmp/jmp.c b/curs/chap-05-ihs/02-jmp/jmp.c new file mode 100644 index 00000000..66beff02 --- /dev/null +++ b/curs/chap-05-ihs/02-jmp/jmp.c @@ -0,0 +1,10 @@ +unsigned int i; + +int main(void) +{ + i = 0; +start: + i += 2; + goto start; + i += 6; +} From 1127febf6e30a8695827187ed17b9bf82a642375 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:14:58 +0200 Subject: [PATCH 3/7] chap-05: Add demo showing flag activation for assembly instructions Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/03-flags/.gitignore | 1 + curs/chap-05-ihs/03-flags/Makefile | 21 ++++++++ curs/chap-05-ihs/03-flags/flags.asm | 78 ++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 curs/chap-05-ihs/03-flags/.gitignore create mode 100644 curs/chap-05-ihs/03-flags/Makefile create mode 100644 curs/chap-05-ihs/03-flags/flags.asm diff --git a/curs/chap-05-ihs/03-flags/.gitignore b/curs/chap-05-ihs/03-flags/.gitignore new file mode 100644 index 00000000..30386b37 --- /dev/null +++ b/curs/chap-05-ihs/03-flags/.gitignore @@ -0,0 +1 @@ +/flags diff --git a/curs/chap-05-ihs/03-flags/Makefile b/curs/chap-05-ihs/03-flags/Makefile new file mode 100644 index 00000000..974a9286 --- /dev/null +++ b/curs/chap-05-ihs/03-flags/Makefile @@ -0,0 +1,21 @@ +NASM = nasm +AFILES = flags.asm +OBJS = $(AFILES:.asm=.o) +ASM_FLAGS = -f elf32 -g -F dwarf +LD = gcc +LDFLAGS = -m32 -g -fno-PIC -no-pie +BINARIES = flags + +.PHONY: all clean + +all : $(BINARIES) + +%.o : %.asm + $(NASM) $(ASM_FLAGS) -o $@ $< + +%: %.o + $(LD) $(LDFLAGS) -o $@ $^ + +clean: + -rm -f *.o $(BINARIES) *.s + -rm -f *~ diff --git a/curs/chap-05-ihs/03-flags/flags.asm b/curs/chap-05-ihs/03-flags/flags.asm new file mode 100644 index 00000000..d1ad32e9 --- /dev/null +++ b/curs/chap-05-ihs/03-flags/flags.asm @@ -0,0 +1,78 @@ +section .text + global main + +main: + push ebp + mov ebp, esp + + ; ZF = 1 + ; cmp eax, eax + ; xor eax, eax + sub eax, eax + + ; ZF = 0 + inc eax + + ; CF = 1 + shr eax, 1 + + ; CF = 0 + shr eax, 1 + + ; SF = 1 + dec eax ; eax <- 0xffffffff + + ; SF = 0 + inc eax + + ; OF = 1 + + ; OF = 0 + + ; ZF = 1, CF = 1 + + ; ZF = 0, CF = 0 + + ; ZF = 0, CF = 1 + + ; ZF = 1, CF = 0 + + ; SF = 1, OF = 1 + + ; SF = 0, OF = 0 + + ; SF = 0, OF = 1 + mov eax, 0x80000000 ; signed int = -2 ^ 31 + sub eax, 1 + + ; SF = 1, OF = 0 + + ; SF = 1, ZF = 1 + ; N/A + + ; SF = 0, ZF = 0 + + mov eax, 1 + ; SF = 0, ZF = 1 + xor eax, eax + ;shr eax, N + ;dec eax + ;sub eax, 1 + + ; SF = 1, ZF = 0 + + ; SF = 1, CF = 1 + + mov eax, 1 + ; SF = 0, CF = 0 + shl eax, 1 + add eax, 1 + sub eax, 1 + xor eax, eax + + ; SF = 0, CF = 1 + + ; SF = 1, CF = 0 + + pop ebp + ret From d0bff4ee4ca0f656c99d80365ee13794fc9a6a53 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:15:56 +0200 Subject: [PATCH 4/7] chap-05: Add simple demo of computing sum(N) in assembly Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/04-sum/.gitignore | 1 + curs/chap-05-ihs/04-sum/Makefile | 21 +++++++++++++++++++++ curs/chap-05-ihs/04-sum/sum.asm | 27 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 curs/chap-05-ihs/04-sum/.gitignore create mode 100644 curs/chap-05-ihs/04-sum/Makefile create mode 100644 curs/chap-05-ihs/04-sum/sum.asm diff --git a/curs/chap-05-ihs/04-sum/.gitignore b/curs/chap-05-ihs/04-sum/.gitignore new file mode 100644 index 00000000..c5caada7 --- /dev/null +++ b/curs/chap-05-ihs/04-sum/.gitignore @@ -0,0 +1 @@ +/sum diff --git a/curs/chap-05-ihs/04-sum/Makefile b/curs/chap-05-ihs/04-sum/Makefile new file mode 100644 index 00000000..61664fad --- /dev/null +++ b/curs/chap-05-ihs/04-sum/Makefile @@ -0,0 +1,21 @@ +NASM = nasm +AFILES = hello_world.asm +OBJS = $(AFILES:.asm=.o) +ASM_FLAGS = -f elf32 -g -F dwarf +LD = gcc +LDFLAGS = -m32 -g -fno-PIC -no-pie +BINARIES = sum + +.PHONY: all clean + +all : $(BINARIES) + +%.o : %.asm + $(NASM) $(ASM_FLAGS) -o $@ $< + +%: %.o + $(LD) $(LDFLAGS) -o $@ $^ + +clean: + -rm -f *.o $(BINARIES) *.s + -rm -f *~ diff --git a/curs/chap-05-ihs/04-sum/sum.asm b/curs/chap-05-ihs/04-sum/sum.asm new file mode 100644 index 00000000..4d3a9f53 --- /dev/null +++ b/curs/chap-05-ihs/04-sum/sum.asm @@ -0,0 +1,27 @@ +%include "../io.mac" + +section .bss + sum: resd 1 + +section .text + global main + extern printf + +main: + push ebp + mov ebp, esp + mov eax, 0 ; eax is the loop counter + mov edx, 0 ; edx is sum +begin: + cmp eax, 100 + ja out + add edx, eax + add eax, 1 + jmp begin +out: + mov [sum], edx + + PRINTF32 `%d\n\x0`, [sum] + nop + pop ebp + ret From 537ff1b3a926ede84ef7acbdd6ba5c061d907e75 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:24:08 +0200 Subject: [PATCH 5/7] chap-05: Add demo showing data sections Source code files are both in C and in assembly. Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/08-data/.gitignore | 3 +++ curs/chap-05-ihs/08-data/Makefile | 25 +++++++++++++++++++++++++ curs/chap-05-ihs/08-data/data_asm.asm | 25 +++++++++++++++++++++++++ curs/chap-05-ihs/08-data/data_c.c | 8 ++++++++ 4 files changed, 61 insertions(+) create mode 100644 curs/chap-05-ihs/08-data/.gitignore create mode 100644 curs/chap-05-ihs/08-data/Makefile create mode 100644 curs/chap-05-ihs/08-data/data_asm.asm create mode 100644 curs/chap-05-ihs/08-data/data_c.c diff --git a/curs/chap-05-ihs/08-data/.gitignore b/curs/chap-05-ihs/08-data/.gitignore new file mode 100644 index 00000000..6f71ad17 --- /dev/null +++ b/curs/chap-05-ihs/08-data/.gitignore @@ -0,0 +1,3 @@ +/data_c +/data_asm +/data_c.s diff --git a/curs/chap-05-ihs/08-data/Makefile b/curs/chap-05-ihs/08-data/Makefile new file mode 100644 index 00000000..f9b608bf --- /dev/null +++ b/curs/chap-05-ihs/08-data/Makefile @@ -0,0 +1,25 @@ +CFLAGS = -m32 -fno-PIC -Wall +LDFLAGS = -m32 -no-pie +ASFLAGS = -f elf32 +AS = nasm + +.PHONY: all clean + +all: data_c data_asm data_c.s + +data_c: data_c.o + +data_c.o: data_c.c + +data_c.s: data_c.c + $(CC) -S -o $@ $< + +data_asm: data_asm.o + +data_asm.o: data_asm.asm + $(AS) $(ASFLAGS) -o $@ $< + +clean: + -rm -f *~ + -rm -f data_c.o data_c + -rm -f data_asm.o data_asm diff --git a/curs/chap-05-ihs/08-data/data_asm.asm b/curs/chap-05-ihs/08-data/data_asm.asm new file mode 100644 index 00000000..c08feeae --- /dev/null +++ b/curs/chap-05-ihs/08-data/data_asm.asm @@ -0,0 +1,25 @@ +section .data +global init + +init: dd 3 + +section .bss +global non_init + +non_init: resd 1 + +section .rodata +global ro + +ro: dd 10 + +section .text + +global main + +main: + push ebp + mov ebp, esp + + leave + ret diff --git a/curs/chap-05-ihs/08-data/data_c.c b/curs/chap-05-ihs/08-data/data_c.c new file mode 100644 index 00000000..0201b7eb --- /dev/null +++ b/curs/chap-05-ihs/08-data/data_c.c @@ -0,0 +1,8 @@ +int non_init; +int init = 3; +const int ro = 10; + +int main(void) +{ + return 0; +} From 9e1e777a5a1f823115e15f97d91ee78eb31a8186 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:24:54 +0200 Subject: [PATCH 6/7] chap-05: Add io.mac dependency file for assembly source code Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/io.mac | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 curs/chap-05-ihs/io.mac diff --git a/curs/chap-05-ihs/io.mac b/curs/chap-05-ihs/io.mac new file mode 100644 index 00000000..61a930ed --- /dev/null +++ b/curs/chap-05-ihs/io.mac @@ -0,0 +1,22 @@ +;;; macro to use printf with 32bit parameters: +;;; - 1st parameter MUST be an immediate in backquotes `EAX=%d ECX=%x \n\x0` +;;; escape \n and \x0 only work with backquotes +;;; - rest of parameters MUST be 32bit +;;; - gen purpose and flags are preserved +;;; - stack is cleaned +%macro PRINTF32 1-* + pushf + pushad + jmp %%endstr +%%str: db %1 +%%endstr: +%rep %0 - 1 +%rotate -1 + push dword %1 +%endrep + push %%str + call printf + add esp, 4*%0 + popad + popf +%endmacro From 297b2bf2c28aae5b13d0d73d01c816484c1193af Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:26:31 +0200 Subject: [PATCH 7/7] chap-05: Reindex older demos Signed-off-by: Razvan Deaconescu --- .../Makefile | 0 .../README.md => 05-hello-world/README} | 0 curs/chap-05-ihs/05-hello-world/README.md | 25 ++++++ .../hello.asm | 0 .../{02-dandamudi => 06-dandamudi}/.gitignore | 0 .../{02-dandamudi => 06-dandamudi}/Makefile | 0 .../{02-dandamudi => 06-dandamudi}/README.md | 0 .../{02-dandamudi => 06-dandamudi}/getput.asm | 0 .../{02-dandamudi => 06-dandamudi}/ijump.asm | 0 curs/chap-05-ihs/06-dandamudi/ijump.sasm.asm | 78 +++++++++++++++++++ .../shift_types.asm | 0 .../{02-dandamudi => 06-dandamudi}/size.asm | 0 .../str_test.asm | 0 .../{02-dandamudi => 06-dandamudi}/string.asm | 0 .../tst_gtpt.asm | 0 .../chap-05-ihs/{03-cmov => 07-cmov}/Makefile | 0 .../{03-cmov => 07-cmov}/test_update_max.c | 0 .../{03-cmov => 07-cmov}/update_max.asm | 0 18 files changed, 103 insertions(+) rename curs/chap-05-ihs/{01-hello-world => 05-hello-world}/Makefile (100%) rename curs/chap-05-ihs/{01-hello-world/README.md => 05-hello-world/README} (100%) create mode 100644 curs/chap-05-ihs/05-hello-world/README.md rename curs/chap-05-ihs/{01-hello-world => 05-hello-world}/hello.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/.gitignore (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/Makefile (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/README.md (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/getput.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/ijump.asm (100%) create mode 100644 curs/chap-05-ihs/06-dandamudi/ijump.sasm.asm rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/shift_types.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/size.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/str_test.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/string.asm (100%) rename curs/chap-05-ihs/{02-dandamudi => 06-dandamudi}/tst_gtpt.asm (100%) rename curs/chap-05-ihs/{03-cmov => 07-cmov}/Makefile (100%) rename curs/chap-05-ihs/{03-cmov => 07-cmov}/test_update_max.c (100%) rename curs/chap-05-ihs/{03-cmov => 07-cmov}/update_max.asm (100%) diff --git a/curs/chap-05-ihs/01-hello-world/Makefile b/curs/chap-05-ihs/05-hello-world/Makefile similarity index 100% rename from curs/chap-05-ihs/01-hello-world/Makefile rename to curs/chap-05-ihs/05-hello-world/Makefile diff --git a/curs/chap-05-ihs/01-hello-world/README.md b/curs/chap-05-ihs/05-hello-world/README similarity index 100% rename from curs/chap-05-ihs/01-hello-world/README.md rename to curs/chap-05-ihs/05-hello-world/README diff --git a/curs/chap-05-ihs/05-hello-world/README.md b/curs/chap-05-ihs/05-hello-world/README.md new file mode 100644 index 00000000..61388679 --- /dev/null +++ b/curs/chap-05-ihs/05-hello-world/README.md @@ -0,0 +1,25 @@ +# chap-03-demo + +1. Demo gdb +- make +- gdb hello +- Comands: b main, r, n +- set $eax = 0xffffffff +- set $eip = main + +2. Demo gdb + step through hello.asm to inspect the changes to the following registers: + * EAX, AX, AH, AL + * EFLAGS + * EIP +Note: Instructions to whatch are: MOV, ADD, JMP + +3. Demo Inspect ~/.gdbinit +- less ~/.gdbinit + +cleanup: +set disassembly-flavor intel +set history save on + + + diff --git a/curs/chap-05-ihs/01-hello-world/hello.asm b/curs/chap-05-ihs/05-hello-world/hello.asm similarity index 100% rename from curs/chap-05-ihs/01-hello-world/hello.asm rename to curs/chap-05-ihs/05-hello-world/hello.asm diff --git a/curs/chap-05-ihs/02-dandamudi/.gitignore b/curs/chap-05-ihs/06-dandamudi/.gitignore similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/.gitignore rename to curs/chap-05-ihs/06-dandamudi/.gitignore diff --git a/curs/chap-05-ihs/02-dandamudi/Makefile b/curs/chap-05-ihs/06-dandamudi/Makefile similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/Makefile rename to curs/chap-05-ihs/06-dandamudi/Makefile diff --git a/curs/chap-05-ihs/02-dandamudi/README.md b/curs/chap-05-ihs/06-dandamudi/README.md similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/README.md rename to curs/chap-05-ihs/06-dandamudi/README.md diff --git a/curs/chap-05-ihs/02-dandamudi/getput.asm b/curs/chap-05-ihs/06-dandamudi/getput.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/getput.asm rename to curs/chap-05-ihs/06-dandamudi/getput.asm diff --git a/curs/chap-05-ihs/02-dandamudi/ijump.asm b/curs/chap-05-ihs/06-dandamudi/ijump.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/ijump.asm rename to curs/chap-05-ihs/06-dandamudi/ijump.asm diff --git a/curs/chap-05-ihs/06-dandamudi/ijump.sasm.asm b/curs/chap-05-ihs/06-dandamudi/ijump.sasm.asm new file mode 100644 index 00000000..1a816be3 --- /dev/null +++ b/curs/chap-05-ihs/06-dandamudi/ijump.sasm.asm @@ -0,0 +1,78 @@ + ;; adaptat cu macrourile SASM - ușor diferite ! + +;Sample indirect jump example IJUMP.ASM +; +; Objective: To demonstrate the use of indirect jump. +; Input: Requests a digit character from the user. +; Output: Appropriate class selection message. +%include "io.inc" + +section .data +jump_table dd code_for_0 ; indirect jump pointer table + dd code_for_1 + dd code_for_2 + dd default_code ; default code for digits 3-9 + dd default_code + dd default_code + dd default_code + dd default_code + dd default_code + dd default_code + +prompt_msg db "Type a digit: ",0 +msg_0 db "Economy class selected.",0 +msg_1 db "Business class selected.",0 +msg_2 db "First class selected.",0 +msg_default db "Not a valid code!",0 +msg_nodigit db "Not a digit! Try again.",0 +key db 0 + +section .text +global main +main: + mov ebp, esp; for correct debugging +read_again: + PRINT_STRING prompt_msg ; request a digit + sub EAX,EAX ; EAX = 0 + GET_CHAR key + mov AL, [key] ; read input digit and + cmp AL,'0' ; check to see if it is a digit + jb not_digit + cmp AL,'9' + ja not_digit + ; if digit, proceed + sub AL,'0' ; convert to numeric equivalent + mov ESI,EAX ; ESI is index into jump table + add ESI,ESI ; ESI = ESI * 4 + add ESI,ESI + jmp [jump_table+ESI] ; indirect jump based on ESI +test_termination: + cmp AL,2 + ja done + jmp read_again +code_for_0: + PRINT_STRING msg_0 + NEWLINE + jmp test_termination +code_for_1: + PRINT_STRING msg_1 + NEWLINE + jmp test_termination +code_for_2: + PRINT_STRING msg_2 + NEWLINE + jmp test_termination +default_code: + PRINT_STRING msg_default + NEWLINE + jmp test_termination + +not_digit: + PRINT_STRING msg_nodigit + NEWLINE + jmp read_again +done: + mov eax, 1 + mov ebx, 0 + int 0x80 ; exit(0) + diff --git a/curs/chap-05-ihs/02-dandamudi/shift_types.asm b/curs/chap-05-ihs/06-dandamudi/shift_types.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/shift_types.asm rename to curs/chap-05-ihs/06-dandamudi/shift_types.asm diff --git a/curs/chap-05-ihs/02-dandamudi/size.asm b/curs/chap-05-ihs/06-dandamudi/size.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/size.asm rename to curs/chap-05-ihs/06-dandamudi/size.asm diff --git a/curs/chap-05-ihs/02-dandamudi/str_test.asm b/curs/chap-05-ihs/06-dandamudi/str_test.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/str_test.asm rename to curs/chap-05-ihs/06-dandamudi/str_test.asm diff --git a/curs/chap-05-ihs/02-dandamudi/string.asm b/curs/chap-05-ihs/06-dandamudi/string.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/string.asm rename to curs/chap-05-ihs/06-dandamudi/string.asm diff --git a/curs/chap-05-ihs/02-dandamudi/tst_gtpt.asm b/curs/chap-05-ihs/06-dandamudi/tst_gtpt.asm similarity index 100% rename from curs/chap-05-ihs/02-dandamudi/tst_gtpt.asm rename to curs/chap-05-ihs/06-dandamudi/tst_gtpt.asm diff --git a/curs/chap-05-ihs/03-cmov/Makefile b/curs/chap-05-ihs/07-cmov/Makefile similarity index 100% rename from curs/chap-05-ihs/03-cmov/Makefile rename to curs/chap-05-ihs/07-cmov/Makefile diff --git a/curs/chap-05-ihs/03-cmov/test_update_max.c b/curs/chap-05-ihs/07-cmov/test_update_max.c similarity index 100% rename from curs/chap-05-ihs/03-cmov/test_update_max.c rename to curs/chap-05-ihs/07-cmov/test_update_max.c diff --git a/curs/chap-05-ihs/03-cmov/update_max.asm b/curs/chap-05-ihs/07-cmov/update_max.asm similarity index 100% rename from curs/chap-05-ihs/03-cmov/update_max.asm rename to curs/chap-05-ihs/07-cmov/update_max.asm