Trouble with 'backspace'

[b][red]This message was edited by dbustad at 2003-10-27 13:20:27[/red][/b][hr]
[b]Never mind. My question was answered in a better explained post I made in this same messageboard, i.e. Simple Command Shell.[/b]

Hi. I'm just learning assembler, and I've created a simple program that relies on the BIOS (no OS). At the moment, all it does is it takes what you type in, and when you press enter it shows you what you typed (I know, really simple). The problem arises when I press backspace. I've built in a subroutine to handle backspaces (i.e. take one character off the command buffer, remove the character from the screen, and move the cursor back one space). The problem is this. Sometimes, my backspace subroutine works perfectly - the character is removed, the cursor moves, and the buffer is one character shorter. BUT sometimes, it doesn't work, and when I press backspace, it doesn't do any of the things I just mentioned (from when it works properly). I'm including the code, and I hope someone can help me out... Thanks in advance. - Dale.

[code]

; ************************ CODE SEGMENT *******************************

mov BYTE [intCmdLen], 0x00
mov di, strCmdBufr
mov si, strPrompt
call dispstr

prompt:
call getkey

cmp al, 0x00
je .extended_key
cmp al, 0xE0
je .extended_key

cmp al, 0x08
je .backspace_key

cmp al, 0x0D
je .enter_key

mov bh, [intCmdMax]
mov bl, [intCmdLen]
cmp bh, bl
je prompt

mov [di], al
inc di
inc BYTE [intCmdLen]

mov ah, 0x0E
mov bl, 0x07
int 0x10

jmp prompt

.extended_key:
jmp prompt

.backspace_key:
mov bh, 0x00
mov bl, [intCmdLen]
cmp bh, bl
je prompt

mov ah, BYTE [intCmdLen]
cmp ah, BYTE [intPmptLen]
je prompt

dec BYTE [intCmdLen]
dec di

mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
int 0x10

mov ah, 0x09
mov al, ' '
mov bh, 0x00
mov bl, 0x07
mov cx, 0x01
int 0x10

jmp prompt

.enter_key:
mov BYTE [di], 0x00
mov si, strCRLF
call dispstr
mov si, strCmdBufr
call dispstr
mov si, strCRLF
call dispstr
mov si, strCRLF
call dispstr

mov BYTE [intCmdLen], 0x00
mov di, strCmdBufr
mov si, strPrompt
call dispstr

jmp prompt

; *********************************************************************

getkey:
mov ah, 0
int 0x16
ret

; *********************************************************************

dispstr:
lodsb
or al, al
jz .done

mov ah, 0Eh
mov bx, 0007h
int 10h
jmp dispstr
.done:
ret

; *********************************************************************

...

; ************************ DATA SEGMENT *******************************

strPrompt db "CMD - ", 0
intPmptLen db 0x06
intCmdMax db 0xFC

; ************************ EXTRA SEGMENT ******************************

strCmdBufr resb 0xFF
intCmdLen db 0x00

[/code]

That's the code (at least this part of the program). Thanks for any help you can lend me!

Oh, and just so you know, I'm using NASM 0.98.38.

Addendum (10/23):

I've checked a few times, and now it seems like the problem only happens when I have 6 characters in the buffer. This might have something to do with the intPmptLen being equal to 6, but I can't figure out what I'm doing wrong. Thanks, again.



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories