deleting line
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Sun, 20 Jun 2021 01:14:15 +0000 (21:14 -0400)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Sun, 20 Jun 2021 01:14:15 +0000 (21:14 -0400)
fileutils.S [deleted file]
fileutils.asm
macros.S [moved from utils.S with 69% similarity]
makefile
repl.S [deleted file]
repl.asm
sped.asm
utils.asm

diff --git a/fileutils.S b/fileutils.S
deleted file mode 100644 (file)
index 5a77864..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-
-%ifndef __FILEUTILS_S__
-%define __FILEUTILS_S__
-
-extern readFile
-extern readLine
-extern writeFile
-
-%endif
index 1d78439..6c30ca6 100644 (file)
@@ -1,5 +1,5 @@
 
-%include "utils.S"
+%include "macros.S"
 
 extern printf
 extern malloc
@@ -60,15 +60,15 @@ readFile:
 
     _readFile_loop:
 
-    ; check if eof was reached
-    cmp DWORD [ebp-IS_EOF], 1
-    je _readFile_exit
-
     push DWORD [ebp-FILE_HANDLE]
     call readLine 
 
     mov esi, eax
     mov [ebp-IS_EOF], ebx
+
+    ; check if eof was reached
+    cmp DWORD [ebp-IS_EOF], 1
+    je _readFile_exit
     
     ; push esi
     ; call printf
similarity index 69%
rename from utils.S
rename to macros.S
index 5c09a23..afde07d 100644 (file)
--- a/utils.S
+++ b/macros.S
@@ -2,6 +2,14 @@
 %ifndef __UTILS_S__
 %define __UTILS_S__
 
+%macro write_str 2
+    mov eax, 4
+    mov ebx, 1
+    mov ecx, %1
+    mov edx, %2
+    int 0x80
+%endmacro
+
 ; gets the nth string ptr in a str array
 ; of the form: str_offset buffer, n
 ; result is in eax
@@ -12,7 +20,4 @@
     add eax, DWORD %1
 %endmacro
 
-extern shiftLeft
-extern shiftRight
-
 %endif
index 18c299f..e77e686 100644 (file)
--- a/makefile
+++ b/makefile
@@ -10,7 +10,7 @@ make: sped
 %.o: %.asm
        $(ASM) $(ASMFLAGS) -o $@ $^
 
-sped: sped.o fileutils.o repl.o
+sped: sped.o fileutils.o repl.o utils.o
        $(CC) $(CFLAGS) -o $@ $^
 
 clean:
diff --git a/repl.S b/repl.S
deleted file mode 100644 (file)
index 18805a6..0000000
--- a/repl.S
+++ /dev/null
@@ -1,7 +0,0 @@
-
-%ifndef __REPL_S__
-%define __REPL_S__
-
-extern repl
-
-%endif
index 3c7f429..738da94 100644 (file)
--- a/repl.asm
+++ b/repl.asm
@@ -1,11 +1,14 @@
 
-%include "fileutils.S"
-
 extern printf
 extern fflush
 extern stdout
 extern free
 
+extern readLine
+extern writeFile
+extern shiftLeft
+extern shiftRight
+
 global repl
 
 section .data
@@ -190,8 +193,16 @@ repl:
     mov eax, DWORD [ebp-CMDSTR]
     cmp BYTE [eax], 'd'
     jne _repl_cmd_delete_end
-
     
+    ; check to make sure we don't have only one line
+
+    ; delete the line
+    push DWORD [buffer]
+    push DWORD [buffer_lines]
+    push DWORD [cur_line]
+    call shiftLeft
+
+    sub DWORD [buffer_lines], 1
 
     jmp _repl_continue
     _repl_cmd_delete_end:
index a14dbd4..544ec3c 100644 (file)
--- a/sped.asm
+++ b/sped.asm
@@ -1,21 +1,13 @@
 ; sped - the stupidly pointless editor
-; written by pinosaur
 
-%include "fileutils.S"
-%include "repl.S"
+%include "macros.S"
 
 extern printf
 
-global main
+extern readFile
+extern repl
 
-; macros
-%macro write_str 2
-    mov eax, 4
-    mov ebx, 1
-    mov ecx, %1
-    mov edx, %2
-    int 0x80
-%endmacro
+global main
 
 section .data
     banner_str db `SPED - the stupidly pointless editor\n`, 0x00
index fd8529d..9feb498 100644 (file)
--- a/utils.asm
+++ b/utils.asm
@@ -1,21 +1,72 @@
 
+%include "macros.S"
+
 extern memmove
+extern free
+extern realloc
 
 global shiftLeft
 global shiftRight
 
 section .text
 
+; shrinks array (4byte) by shifting blocks left
+; args: buffer, buffer_len, shift_pos (index that gets destroyed)
+; return:
+;   eax: location of new buffer
+; issues: 
 shiftLeft:
+    %define _BUFFER      16
+    %define _BUFFER_LEN  12
+    %define _SHIFT_POS   8
+    %define SHIFT_LEN    4
+    %define BLOCK_OFFSET 8 ; mem location of block to be destroyed
+    %define NEW_BUFFER   12
+
     push ebp
     mov ebp, esp
+
+    sub esp, 12
+
+    ; set vars
+    mov eax, DWORD [ebp+_BUFFER_LEN]
+    sub eax, [ebp+_SHIFT_POS]
+    sub eax, 1
+    mov [ebp-SHIFT_LEN], eax
+
+    str_offset [ebp+_BUFFER], [ebp+_SHIFT_POS]
+    mov [ebp-BLOCK_OFFSET], eax
     
+    ; free string to be destoryed first
+    mov eax, DWORD [ebp-BLOCK_OFFSET]
+    mov eax, [eax]
+    push eax
+    call free
+
+    ; move the memory
+    mov eax, DWORD [ebp-SHIFT_LEN]
+    mov ecx, 4
+    mul ecx
+    push eax
+    mov eax, DWORD [ebp-BLOCK_OFFSET]
+    add eax, 4
+    push eax
+    push DWORD [ebp-BLOCK_OFFSET]
+    call memmove
     
+    ; realloc to shrink the array
+
+    %undef _BUFFER
+    %undef _BUFFER_LEN
+    %undef _SHIFT_POS
     
     mov esp, ebp
     pop ebp
     ret
 
+; grows array by shifting blocks right
+; args: buffer, buffer_len, shift_pos (new uninitalized index)
+; return: location of new buffer
 shiftRight:
     push ebp
     mov ebp, esp
@@ -25,3 +76,4 @@ shiftRight:
     mov esp, ebp
     pop ebp
     ret
+