Greetings!
I was asked to make a 'rename' command using INT 21h/56h by doing the following:
1. Ask the user to enter the file he wants the name to be changed
2. Ask the name of the file that will be used as the new filename.
3. Return error codes depending on the situation.
With this code
;File fren
.model small
.code
org 100h
start:
jmp fren
prompt db "File to rename? $"
prompt2 db "Rename as what? $"
rename_msg db "File renamed. $"
err_nf db "File not found. $"
err_ip db "Invalid path. $"
err_ad db "Access denied. $"
err_nsd db "Not same device. $"
characters db 50 dup(0)
bytes_typed db 0
old db 30 dup,?, 30 DUP(' ')
new db 30 dup,?, 30 DUP(' ')
fren proc near
file1:
mov dx, offset prompt
mov ah, 9
int 21h
mov ah, 0ah
mov dx, offset old
int 21h
mov bh,0
mov bl, bytes_typed
add bx, offset characters
mov byte ptr[bx], 0
mov dx, offset characters
jmp file2
file2:
mov dx, offset prompt2
mov ah, 9
int 21h
mov ah, 0ah
mov dx, offset new
int 21h
mov bh,0
mov bl, bytes_typed
add bx, offset characters
mov byte ptr[bx], 0
mov dx, offset characters
jmp rename
rename:
mov ah,56h
lea dx,old
lea di,new
int 21h
cmp ax, 02h
je errnotfound
cmp ax, 03h
je errinvpath
cmp ax, 05h
je erraccden
cmp ax, 11h
je errnotsame
jmp display
errnotfound:
lea dx, err_nf
mov ah, 9
int 21h
jmp end
errinvpath:
lea dx, err_ip
mov ah, 9
int 21h
jmp end
erraccden:
lea dx, err_ad
mov ah, 9
int 21h
jmp end
errnotsame:
lea dx, err_nsd
mov ah, 9
int 21h
jmp end
display:
lea dx, rename_msg
mov ah,09h
int 21h
jmp end
end:
int 20h
fren endp
end start
The program will ask me the file to rename and what its new name should be. However, it will always return an invalid path error.
I just based this rename program from a 'delete' program (which works):
.model small
.code
org 100h
start:
jmp rubout
the_buffer db 50
bytes_typed db 0
characters db 50 dup(0)
prompt db "File to delete? $"
ok_msg db "baleeted, lulz $"
not_found_msg db "Not found. $"
deny_msg db "Access denied. Close file to delete first. $"
rubout proc near
mov dx, offset prompt
mov ah, 9
int 21h
mov ah, 0ah
mov dx, offset the_buffer
int 21h
mov bh,0
mov bl, bytes_typed
add bx, offset characters
mov byte ptr[bx], 0
mov dx, offset characters
mov ah, 41h
int 21h
jnc ok
cmp al, 2
je not_found
cmp al, 5
je deny
not_found:
mov dh, 10
mov dl, 0
mov bh, 0
mov ah, 2
int 10h
mov dx, offset not_found_msg
mov ah, 9
int 21h
jmp exit
deny:
mov dh, 10
mov dl, 0
mov bh, 0
mov ah, 2
int 10h
mov dx, offset deny_msg
mov ah, 9
int 21h
jmp exit
ok:
mov dh, 10
mov dl, 0
mov bh, 0
mov ah, 2
int 10h
mov dx, offset ok_msg
mov ah, 9
int 21h
jmp exit
exit:
int 20h
rubout endp
end start
I hope someone could help. Many thanks.