So to look for a file named “HELLO”, we just compare the first 8 bytes of each entry in memory with 'HELLO '.
🧾 Assembly Code
org 0x7C00 bits 16
start: jmp main
a; ============================= ; Print string pointed by SI ; ============================= puts: push si push ax .print: lodsb or al, al jz .done mov ah, 0x0E int 0x10 jmp .print .done: pop ax pop si ret
; ============================= ; Get a key from keyboard (result in AL) ; ============================= getchar: mov ah, 0x00 int 0x16 ret
; ============================= ; Read a line into ES:DI ; Max 32 chars, terminates on Enter ; ============================= read_line: xor cx, cx .next_char: call getchar cmp al, 0x0D ; Enter key? je .done
; Echo the character mov ah, 0x0E int 0x10 stosb inc cx cmp cx, 32 jne .next_char .done: mov al, 0 stosb ret
; ============================= ; Read sector into ES:BX ; DL = sector number ; ============================= read_sector: push ax push dx mov ah, 0x02 mov al, 1 mov ch, 0 mov cl, dl inc cl ; Convert to 1-based mov dh, 0 mov dl, 0x00 int 0x13 pop dx pop ax ret
; === Ask for user input === mov si, newline call puts mov si, msg_prompt call puts
mov di, 0x9100 mov es, ax call read_line
; === Final greeting === mov si, newline call puts
mov si, msg_hello call puts
mov ax, es mov ds, ax mov si, 0x9100 call puts
mov si, newline call puts
mov si, msg_tail call puts
hang: jmp hang
notfound: mov si, msg_nf call puts jmp hang
; ============================= ; Data ; ============================= filename: db 'HELLO ' msg_boot: db 'Booting OS...', 0x0D, 0x0A, 0 msg_nf: db 'File Not Found!', 0x0D, 0x0A, 0 msg_prompt: db 'Enter your name: ', 0 msg_hello: db 'Hello your username is: ', 0 msg_tail: db 0x0D, 0x0A, 'welcome to the', 0x0D, 0x0A, 0 newline: db 0x0D, 0x0A, 0
times 510 - ($ - $$) db 0 dw 0xAA55org 0x7C00 bits 16
start: jmp main
; Print string at SI puts: push si push ax .loop: lodsb or al, al jz .done mov ah, 0x0E int 0x10 jmp .loop .done: pop ax pop si ret
; Get a character from keyboard getchar: mov ah, 0x00 int 0x16 ret
; Read up to 32 characters to ES:DI read_line: xor cx, cx .next: call getchar cmp al, 0x0D je .done mov ah, 0x0E int 0x10 stosb inc cx cmp cx, 32 jne .next .done: mov al, 0 stosb ret
; Read 1 sector from DL into ES:BX read_sector: push ax push dx mov ah, 0x02 mov al, 1 mov ch, 0 mov cl, dl inc cl mov dh, 0 mov dl, 0x00 int 0x13 pop dx pop ax ret
; --- Data --- filename: db 'HELLO ' msg_boot: db 'Booting OS...', 0x0D, 0x0A, 0 msg_nf: db 'File Not Found!', 0x0D, 0x0A, 0 msg_prompt: db 'Enter your username: ', 0 msg_hello: db 'Hello ', 0 msg_tail: db ', welcome to the OS!', 0x0D, 0x0A, 0 newline: db 0x0D, 0x0A, 0