Skip to content

Commit

Permalink
more efficient register usage in hist_store
Browse files Browse the repository at this point in the history
  • Loading branch information
jwt27 committed Feb 7, 2020
1 parent f7b941e commit 865682b
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/DEBUG.ASM
Original file line number Diff line number Diff line change
Expand Up @@ -8444,40 +8444,39 @@ hist_recall endp
; HIST_STORE - Store line in input history
; Entry SI Input line
; CX Line length
; Uses BX,CX,DX,DI
; Uses BX,CX,DX,DI,SI

hist_store proc
push si
push ax
mov dx,si
mov bx,[line_hist_begin]
mov di,[line_hist_end]
test di,di
jz first
add di,sizeof llnode
push si
push cx
repe cmpsb ;check if last entry is identical
pop cx
pop si
je fail ;don't store duplicates
push cx
mov cx,offset line_history + LINE_HISTORY_LEN
sub cx,di
mov al,CR
repne scasb ;find end of last node
pop cx
mov si,di
check_overflow:
mov di,si
add di,cx
add di,sizeof llnode ;di = end of new node
cmp di,offset line_history + LINE_HISTORY_LEN
mov dx,di
add dx,cx
add dx,sizeof llnode ;dx = end of new node
cmp dx,offset line_history + LINE_HISTORY_LEN
jb no_overflow ;does it fit?
cmp si,offset line_history
cmp di,offset line_history
je fail ;fail if new node would be larger than buffer
mov si,offset line_history ;restart from beginning
mov di,offset line_history ;restart from beginning
jmp check_overflow
no_overflow:
cmp si,bx
cmp di,bx
ja no_overlap ;can't overlap if buffer isn't full yet
check_overlap:
cmp di,bx
Expand All @@ -8490,18 +8489,15 @@ no_overlap:
mov [bx.llnode.prev],0 ;[bx] is now the first node
mov [line_hist_begin],bx
mov bx,[line_hist_end]
mov [line_hist_end],si ;add node at the end
mov [bx.llnode.next],si
mov [si.llnode.prev],bx
mov [si.llnode.next],0
mov di,si
mov [line_hist_end],di ;add node at the end
mov [bx.llnode.next],di
mov [di.llnode.prev],bx
mov [di.llnode.next],0
store:
add di,sizeof llnode
mov si,dx
rep movsb ;store string in new node
fail:
pop ax
pop si
ret

first:
Expand Down

0 comments on commit 865682b

Please sign in to comment.