I am trying to fix the code for my project but i am a little overwhelmed. This is the last question I asked about my code.
I am here to upload the whole code:
.model small
.stack 100h
.data
indexul db 2 dup (0)
invalid db "Indexul introdus este invalid!",0,'$'
string db 'Introduceti indexul numelui pe care doriti sa-l stergeti:',0,'$'
punct db '.$'
prompt db 'Introduceti un nume:',0,'$'
list db 'Lista cu numele este:',0,'$'
nume dw 50 dup(0)
numes dw 0
numeIndex db 13, 10, 49, 46, 36
numePointer dw 50
menu db "Alege o optiune:",13,10
db "1. Nume",13,10
db "2. Lista cu numele",13,10
db "3. Sterge un nume",13,10
db "4. Exit",13,10,'$'
.code
start:
mov al, 0
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
mov numePointer, offset nume
call clear_screen
bucla:
;Move cursor to the next line
mov dl, 0dh
mov ah, 2
int 21h
mov dl, 0ah
int 21h
;Display menu
call display_menu
mov ah, 1
int 21h
cmp al, '1'
je scrienume
cmp al, '2'
je lista
cmp al, '3'
je sterge
cmp al, '4'
jmp exit
jmp bucla
mov dx, offset numePointer
scrienume:
mov dx, offset prompt
mov ah, 09h
int 21h
mov cx, 5
mov si, numePointer
read_char:
mov ah, 01h
int 21h
mov [si], al
inc si
loop read_char
mov byte ptr [si], '$'
inc si
mov numePointer, si ; numePointer = 6
jmp bucla
lista:
mov byte ptr [numeIndex 2], "1"
mov dx, offset nume
print_names:
push dx ; (1)
mov dx, offset numeIndex
mov ah, 09h
int 21h
inc byte ptr [numeIndex 2] ; "1" -> "2" -> "3" ...
pop dx ; (1)
mov ah, 09h
int 21h
add dx, 5 1
cmp dx, numePointer ; check if the current name is the last one
jb print_names
jmp bucla ; return to main loop
sterge:
; Prompt user for position of name to delete
mov dx, offset string
mov ah, 09h
int 21h
; Read position from user
mov ah, 01h
int 21h
sub al, 49 ; AL=["1","9"] 1-based input -> AL=[0,8] 0-based index
mov ah, 6
mul ah ; -> AX = {0,6,12,18,24,30,36,42,48}
add ax, offset nume
cmp ax, numePointer
jnb invalidPosition
mov di, ax
lea si, [di 6]
mov cx, numePointer
sub cx, si
cld
rep movsb
mov numePointer, di
dec numes
jmp bucla
invalidPosition:
; Display error message
mov dx, offset invalid
mov ah, 09h
int 21h
jmp bucla
exit:
;FINISH PROGRAM.
mov ax, 4c00h
int 21h
;---------------------------------------------
display_menu proc
mov dx, offset menu
mov ah, 9
int 21h
ret
display_menu endp
clear_screen proc
mov ah, 0
mov al, 3
int 10H
ret
clear_screen endp
end start
As i mentioned in the other questions, it only deletes the last name no matter what index i input.
CodePudding user response:
;INITIALIZE DATA SEGMENT. mov ax, @data mov ds, ax
You forgot to setup the ES segment register! You need it for the movsb
instruction.
;INITIALIZE DATA SEGMENT.
mov ax, @data
mov ds, ax
mov es, ax
nume dw 50 dup(0)
Better define this with db
and reserve room for at most 9 names, so 9 * (5 1):
nume db 54 dup(0)