Skip to content

Commit 865682b

Browse files
committed
more efficient register usage in hist_store
1 parent f7b941e commit 865682b

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

src/DEBUG.ASM

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8444,40 +8444,39 @@ hist_recall endp
84448444
; HIST_STORE - Store line in input history
84458445
; Entry SI Input line
84468446
; CX Line length
8447-
; Uses BX,CX,DX,DI
8447+
; Uses BX,CX,DX,DI,SI
84488448

84498449
hist_store proc
8450-
push si
84518450
push ax
8452-
mov dx,si
84538451
mov bx,[line_hist_begin]
84548452
mov di,[line_hist_end]
84558453
test di,di
84568454
jz first
84578455
add di,sizeof llnode
8456+
push si
84588457
push cx
84598458
repe cmpsb ;check if last entry is identical
84608459
pop cx
8460+
pop si
84618461
je fail ;don't store duplicates
84628462
push cx
84638463
mov cx,offset line_history + LINE_HISTORY_LEN
84648464
sub cx,di
84658465
mov al,CR
84668466
repne scasb ;find end of last node
84678467
pop cx
8468-
mov si,di
84698468
check_overflow:
8470-
mov di,si
8471-
add di,cx
8472-
add di,sizeof llnode ;di = end of new node
8473-
cmp di,offset line_history + LINE_HISTORY_LEN
8469+
mov dx,di
8470+
add dx,cx
8471+
add dx,sizeof llnode ;dx = end of new node
8472+
cmp dx,offset line_history + LINE_HISTORY_LEN
84748473
jb no_overflow ;does it fit?
8475-
cmp si,offset line_history
8474+
cmp di,offset line_history
84768475
je fail ;fail if new node would be larger than buffer
8477-
mov si,offset line_history ;restart from beginning
8476+
mov di,offset line_history ;restart from beginning
84788477
jmp check_overflow
84798478
no_overflow:
8480-
cmp si,bx
8479+
cmp di,bx
84818480
ja no_overlap ;can't overlap if buffer isn't full yet
84828481
check_overlap:
84838482
cmp di,bx
@@ -8490,18 +8489,15 @@ no_overlap:
84908489
mov [bx.llnode.prev],0 ;[bx] is now the first node
84918490
mov [line_hist_begin],bx
84928491
mov bx,[line_hist_end]
8493-
mov [line_hist_end],si ;add node at the end
8494-
mov [bx.llnode.next],si
8495-
mov [si.llnode.prev],bx
8496-
mov [si.llnode.next],0
8497-
mov di,si
8492+
mov [line_hist_end],di ;add node at the end
8493+
mov [bx.llnode.next],di
8494+
mov [di.llnode.prev],bx
8495+
mov [di.llnode.next],0
84988496
store:
84998497
add di,sizeof llnode
8500-
mov si,dx
85018498
rep movsb ;store string in new node
85028499
fail:
85038500
pop ax
8504-
pop si
85058501
ret
85068502

85078503
first:

0 commit comments

Comments
 (0)