I'm having trouble assembling x86 assembly code into a bootable image file. Below is the code I'm working with:
org 0x7C00
bits 16
%define ENDL 0x0D, 0x0A
start:
jmp main
;
; Prints a string to the screen
; Params:
; - ds:si points to string
;
puts:
; save registers we will modify
push si
push ax
push bx
.loop:
lodsb ; loads next character in al
or al, al ; verify if next character is null?
jz .done
mov ah, 0x0E ; call BIOS interrupt
mov bh, 0 ; set page number to 0
int 0x10
jmp .loop
.done:
pop bx
pop ax
pop si
ret
main:
; setup data segments
mov ax, 0 ; can't set ds/es directly
mov ds, ax
mov es, ax
; setup stack
mov ss, ax
mov sp, 0x7C00 ; stack grows downwards from where we are loaded in memory
; print welcome message
mov si, welcome_msg
call puts
; jump to desktop
call desktop
.halt:
jmp .halt
desktop:
; clear screen
mov ah, 0x00 ; function 0 of int 10h: set video mode
mov al, 0x03 ; video mode 3 (text mode 80x25)
int 0x10
; print UI
mov si, desktop_ui
call puts
; get user input
mov si, user_input
call puts
mov ah, 0x0 ; function 0 of int 16h: read keyboard input
int 0x16
cmp al, 'l' ; check if input is 'logout'
je .logout
; handle user input
mov si, user_input
cmp si, logout_string ; compare user input with "logout"
je .logout
cmp si, files_string ; compare user input with "files"
je .files
cmp si, office_string ; compare user input with "office"
je .office
cmp si, about_string ; compare user input with "about"
je .about
; invalid input, loop again
jmp desktop
.logout:
; logout procedure
; (could perform cleanup tasks here if necessary)
jmp main
.files:
; handle files option
; (could implement file management functionality here)
jmp desktop
.office:
; handle office option
; (could implement office suite functionality here)
jmp desktop
.about:
; display about information
mov si, about_msg
call puts
jmp desktop
welcome_msg: db ' officerdownOS', ENDL, '----------------------------------------------------------------------------------------------', ENDL, ' TYPE LOGOUT TO LOGOUT', ENDL, ' --------------- --------------- ----------------', ENDL, ' PRODUCTIVITY! ? files', ENDL, ' ----------------- ---------------- -----------------', ENDL, ' Office Suite About files', 0
desktop_ui: db 'Enter your choice: ', 0
user_input: times 256 db 0
logout_string: db 'logout', 0
files_string: db 'files', 0
office_string: db 'office', 0
about_string: db 'about', 0
about_msg: db 'officerdownOS Normal v1.1', ENDL, 'Compiled 11/18/2023', ENDL, 0
; Fill remaining space in the boot sector with zeros
times (512-($-$$)) db 0
dw 0xAA55
When I run
nasm -f bin bootloader.asm -o bootloader.bin
I get the error
bootloader.asm:120: error: TIMES value -459
I've tried modifying the numbers, but I haven't been successful. I'm not exactly sure what to do, and I would appreciate any help or guidance on resolving this issue. Thank you!
I have further leaned that the file is too big. I want to keep the specified UI in this bootloader but I am not sure how. Here is the updated code:
org 0x7C00
bits 16
start:
jmp main
;
; Prints a string to the screen
; Params:
; - ds:si points to string
;
puts:
pusha ; save registers we will modify
.loop:
lodsb ; loads next character in al
or al, al ; verify if next character is null?
jz .done
mov ah, 0x0E ; call BIOS interrupt
mov bh, 0 ; set page number to 0
int 0x10
jmp .loop
.done:
popa ; restore registers
ret
main:
; setup data segments
xor ax, ax
mov ds, ax
mov es, ax
; setup stack
mov ss, ax
mov sp, 0x7C00 ; stack grows downwards from where we are loaded in memory
; print welcome message
mov si, welcome_msg
call puts
; jump to desktop
call desktop
.halt:
jmp .halt
desktop:
; clear screen
mov ah, 0x00 ; function 0 of int 10h: set video mode
mov al, 0x03 ; video mode 3 (text mode 80x25)
int 0x10
; print UI
mov si, desktop_ui
call puts
; get user input
mov si, user_input
call puts
mov ah, 0x0 ; function 0 of int 16h: read keyboard input
int 0x16
cmp al, 'l' ; check if input is 'logout'
je .logout
; handle user input
mov si, user_input
cmp si, logout_string ; compare user input with "logout"
je .logout
cmp si, files_string ; compare user input with "files"
je .files
cmp si, office_string ; compare user input with "office"
je .office
cmp si, about_string ; compare user input with "about"
je .about
; invalid input, loop again
jmp desktop
.logout:
; logout procedure
; (could perform cleanup tasks here if necessary)
jmp main
.files:
; handle files option
; (could implement file management functionality here)
jmp desktop
.office:
; handle office option
; (could implement office suite functionality here)
jmp desktop
.about:
; display about information
mov si, about_msg
call puts
jmp desktop
welcome_msg: db 'o','f','f', 4 DUP('i'),'c','e','r','d','o','w','n','O','S', 13, 10
db '----------------------------------------------------------------------------------------------', 13, 10
db ' TYPE LOGOUT TO LOGOUT', 13, 10
db ' --------------- --------------- ----------------', 13, 10
db ' PRODUCTIVITY! ? files', 13, 10
db ' ----------------- ---------------- -----------------', 13, 10
db ' Office Suite About files', 0
desktop_ui: db 'Enter your choice: ', 0
user_input: times 256 db 0
logout_string: db 'logout', 0
files_string: db 'files', 0
office_string: db 'office', 0
about_string: db 'about', 0
about_msg: db 'officerdownOS Normal v1.1', 13, 10
db 'Compiled 11/18/2023', 13, 10, 0
; Fill remaining space in the boot sector with zeros
times 510-($-$$) db 0
dw 0xAA55
and the error i get is:
bootloader.asm:121: error: TIMES value -457 is negative