From 737708d2a5e6ec61079236484c0a4c8234206ea8 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Sat, 19 Jun 2021 22:39:02 -0400 Subject: [PATCH] edge cases and more commands --- README.md | 12 ++++++++---- repl.asm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2436d48..7f87c88 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,6 @@ **sped** is a line editor written in x86 assembly. Back in the day, before visual editors, line editors like **ed** were used. This is my own stupid and pointless attempt at writing such line editor. -### FEATURES/NON-FEATURES - - - ### INSTALLATION #### Build from source @@ -29,12 +25,20 @@ to build the project **c** - change the contents of the current line +**o/O** - insert line after/before current line + +**d** - delete current line + **w** - saves file **q** - exists the program ### FAQ +**what is the point of this** + +obviously, we live in a day and age where we have the comfort of visual editors, so line editors like these have become obsolete. i simply wanted to work on a relatively easy to implement project so i can learn some assembly. + **are you insane** yes diff --git a/repl.asm b/repl.asm index 6a1472f..038bb1a 100644 --- a/repl.asm +++ b/repl.asm @@ -15,6 +15,7 @@ section .data prompt_str db `sped > `, 0x00 invalidcmd_str db `invalid command\n`, 0x00 invalidaddr_str db `invalid address\n`, 0x00 + oneline_str db `cannot delete line, as there is only one line\n`, 0x00 charcount_str db `read %i chars\n`, 0x00 currentline_str db `current line: %i\n`, 0x00 echo_str db `%s`, 0x00 ; print strings without format exploit @@ -195,6 +196,8 @@ repl: jne _repl_cmd_delete_end ; check to make sure we don't have only one line + cmp DWORD [buffer_lines], 1 + jle _repl_oneline ; delete the line push DWORD [buffer] @@ -205,12 +208,50 @@ repl: sub DWORD [buffer_lines], 1 + ; if it's the last line, move one down + mov eax, DWORD [buffer_lines] + cmp DWORD [cur_line], eax + jl _repl_continue + sub DWORD [cur_line], 1 + jmp _repl_continue _repl_cmd_delete_end: ; o appends text after line =-=-=-=-=-=-=-=-= mov eax, DWORD [ebp-CMDSTR] cmp BYTE [eax], 'o' + jne _repl_cmd_appenddown_end + + ; make room first + push DWORD [buffer] + push DWORD [buffer_lines] + mov eax, DWORD [cur_line] + add eax, 1 + push eax + call shiftRight + mov [buffer], eax + + ; input text + push 0 + call readLine + mov esi, eax + + ; insert new string + mov eax, [cur_line] + add eax, 1 + mov ecx, 4 + mul ecx + add eax, DWORD [buffer] + mov [eax], esi + + add DWORD [buffer_lines], 1 + + jmp _repl_continue + _repl_cmd_appenddown_end: + + ; O oppens text before line =-=-=-=-=-=-=-= + mov eax, DWORD [ebp-CMDSTR] + cmp BYTE [eax], 'O' jne _repl_cmd_appendup_end ; make room first @@ -231,12 +272,16 @@ repl: mul ecx add eax, DWORD [buffer] mov [eax], esi + + ; also move cursor down one + add DWORD [cur_line], 1 add DWORD [buffer_lines], 1 jmp _repl_continue _repl_cmd_appendup_end: + ; w writes file =-=-=-=-=-=-=-=-=-=-=-=-= mov eax, DWORD [ebp-CMDSTR] cmp BYTE [eax], 'w' @@ -265,6 +310,11 @@ repl: call printf jmp _repl_continue + _repl_oneline: + push oneline_str + call printf + jmp _repl_continue + _repl_continue: jmp _repl_loop -- 2.20.1