From 927ceb94e220d286ef811af9b37489271013ca26 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:26:31 +0200 Subject: [PATCH] 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