Advertisement
ASMProgrammer

My BIOS

Jun 9th, 2024
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 2.83 KB | Software | 0 0
  1. .org 7C00h ; BIOS loading address
  2.    
  3. START:
  4.     mov AX, 0 ; Clear register AX
  5.     mov DS, AX ; Set DS to 0
  6.     mov ES, AX ; Set ES to 0
  7.     mov SI, 0 ; Reset starter index
  8.     mov DI, 0 ; Reset usage index
  9.     mov AH, 00h ; Reset keyboard
  10.     int 16h ; Call BIOS to reset keyboard
  11.     mov ah, 3Dh ; Open file
  12.     mov al, 0 ; Access code to read
  13.     mov dx, OFFSET file_name ; File name
  14.     int 21h
  15.    
  16.     mov bx, ax ; Save file descryptor
  17.    
  18. CHECK_KEY:
  19.     mov AH, 00h ; Get button
  20.     int 16h ; Call BIOS to get button
  21.    
  22.     cmp AL, 53h ; Compare with Delete key code
  23.     jne CHECK_KEY ; If Delete not pressed, re-run code
  24.     jz read
  25.    
  26.     ; Run the following BIOS screen functions to print messages
  27.     mov AH, 09h ; Print text on top screen
  28.     mov DX, msg
  29.     int 21h
  30.    
  31.     mov AH, 0
  32.     int 16h ; Wait press button on keyboard
  33.     cmp ah, 28h ; Run code if pressed button Escape or F10
  34.     je quit ; Run if pressed ESC
  35.     je save_exit ; Run if pressed F10
  36.    
  37.     jmp $ ; Infinite loop
  38.    
  39. quit:
  40.     mov ah, 09h        ; Print text "Esc - Quit F10 - Save & Exit Setup" int bottom screen
  41.     mov dx, quit_msg
  42.     int 21h
  43.  
  44.     int 20h            ; Start operating system
  45.    
  46.     ; Your code to start operating system
  47.  
  48. save_exit:
  49.     ; Open file
  50.     mov eax, 5 ; System call to open file
  51.     mov ebx, file_name ; Filename flag
  52.     mov ecx, 0 ; Open file flag (O_CREAT | O_WRONLY)
  53.     mov edx, 0644 ; File access permission
  54.     int 0x80 ; Call system call
  55.    
  56.     ; Write data to file
  57.     mov eax, 4 ; System call to write in file data
  58.     mov ebx, eax ; File descryptor
  59.     mov ecx, pc_health_status ; Write data of your pc status
  60.     mov edx, pc_health_len ; Line length
  61.     int 0x80 ; Call system call
  62.    
  63.     ; Close file
  64.     mov eax, 6 ; System call to close file
  65.     int 0x80 ; Call system call
  66.  
  67.     int 20h            ; Start operating system
  68.    
  69.     ; Your code to start operating system
  70.  
  71. read:
  72.     mov ah, 3Fh ; Read from file
  73.     mov bx, ax ; Get file descryptor
  74.     lea dx, buffer ; Buffer to save data from file
  75.     mov cx, 255 ; Count bytes to read (maximum 255)
  76.     int 21h
  77.    
  78.     ; If reader value assign `null` close
  79.     or ax, ax
  80.     jz close_reader ; Close file call
  81.    
  82.     ; Write data to screen
  83.     mov ah, 9 ; Print line to screen
  84.     lea ds, buffer ; Get value from buffer
  85.     int 21h
  86.    
  87.     jmp read ; Read next line
  88.    
  89. close_reader:
  90.     mov ah, 3Eh ; Close file
  91.     mov bx, ax ; Get file descryptor
  92.     int 21h
  93.  
  94. section .data
  95.     buffer db 1000 dup(0)
  96.     file_name db "bios.ini", 0
  97.     pc_health_status db "PCHealtStatus=Normal", 0
  98.     pc_health_len equ $ - pc_health_status
  99.     msg db "LMScript BIOS", 0
  100.     quit_msg db "Esc - Quit F10 - Save & Exit Setup", 0
  101.    
  102. TIMES 510 - ($ - START) DB 0 ; Fill unused bytes with zeros
  103.  
  104. DW 0xAA55 ; End loading sector signature
Tags: bios
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement