Created
January 5, 2025 06:46
-
-
Save weirddan455/5cae02fc3d6f932fe55025138ed2f47c to your computer and use it in GitHub Desktop.
Read after delete DOS test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org 100h | |
section .text | |
; open file | |
mov ah, 3dh | |
mov al, 0h | |
lea dx, [file_name] | |
int 21h | |
jc open_error_fn | |
mov [handle], ax | |
; delete file | |
mov ah, 41h | |
lea dx, [file_name] | |
int 21h | |
jc delete_error_fn | |
; read file | |
mov ah, 3fh | |
mov bx, [handle] | |
mov cx, 32 | |
lea dx, [str] | |
int 21h | |
jc read_error_fn | |
; append newline and M$ termination to file contents | |
lea dx, [str] | |
mov bx, dx | |
add bx, ax | |
mov word [bx], 13 | |
inc bx | |
mov word [bx], 10 | |
inc bx | |
mov word [bx], '$' | |
; print the string we read from the file | |
mov ah, 09h | |
int 21h | |
end: | |
mov ah, 0h | |
int 21h | |
open_error_fn: | |
lea dx, [open_error] | |
jmp print_error | |
delete_error_fn: | |
lea dx, [delete_error] | |
jmp print_error | |
read_error_fn: | |
lea dx, [read_error] | |
print_error: | |
mov ah, 09h | |
int 21h | |
jmp end | |
section .data | |
file_name: db 'test.txt', 0 | |
open_error: db 'Failed to open file', 13, 10, '$' | |
delete_error: db 'Failed to delete file', 13, 10, '$' | |
read_error: db 'Failed to read file', 13, 10, '$' | |
section .bss | |
handle: resb 2 | |
str: resb 64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment