Advertisement
didzislauva

ASM hello world mašīnkodam/bootsektoram

Feb 23rd, 2022
1,670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ’;’ Semicolons are used as comment lines in assembly
  2.  
  3. ; Always keep you code neat by mentioning author,description,date, file name,etc.That is a good programming habit.
  4.  
  5. ;************************************************************
  6.  
  7. ; Author: Your Name goes here
  8.  
  9. ; Description: A tiny simple boot sector
  10.  
  11. ; Date: 0-0-0
  12.  
  13. ; File: bootsec.asm
  14.  
  15. ;************************************************************
  16.  
  17. bits 16 ; Tell the assembler that this is 16 bit code, remember Real Mode is 16bit
  18.  
  19. org 0x7C00 ;’org’ tells the assembler where to be loaded in the memory
  20.  
  21. start: ;This is the first function to be called, it’s like main in C or C++
  22.  
  23. jmp entry ;Just calling a function
  24.  
  25. printmsg db "This is LLU exercise",0 ;The message to be displayed
  26.  
  27. ;************************************************************
  28.  
  29. printf: ;Our printing function
  30.  
  31. lodsb ;Load a string at DS : SI to AX
  32.  
  33. or al, al ;ORing AL, just like AL | AL in C
  34.  
  35. jz done ;If any eggs jump to done
  36.  
  37. jmp print ;So, no eggs(0’s) go and print
  38.  
  39. print: ;This will print the character
  40.  
  41. mov ah,0Eh ;Set the function number in AH
  42.  
  43. int 10H ;Call our helpful BIOS to do the rest, we are lazy
  44.  
  45. jmp printf ;Go back to print the next character
  46.  
  47. done: ;This will return after the printing is done
  48.  
  49. ret
  50.  
  51. entry: ;This is called by start
  52.  
  53. xor ax, ax ;XORing is a faster way to set 0 as register to register
  54.  
  55. ;are done faster
  56.  
  57. mov ds, ax ;Set the Data Segment to value in AX, i.e: 0
  58.  
  59. mov es, ax ;Same but this is for Extra Segment
  60.  
  61. mov si, printmsg ;You might want your text to be displayed
  62.  
  63. call printf ;Call printf to print your name or text
  64.  
  65. ;Enabling A20 Gate, 20th bit through BIOS.We need to get more memory
  66.  
  67. mov ax, 0x2401 ;Set the function number
  68.  
  69. int 0x15 ;Call BIOS
  70.  
  71. ; Sets you up with 32bit Protected Mode.The first bit of the CR0 Register is the PMode bit
  72.  
  73. mov eax,cr0 ;Loads the Control Register to AX ,for getting into 32bit mode
  74.  
  75. or eax, 1 ;ORing, I need to go to a better place
  76.  
  77. mov cr0,eax ;Send the updated data to Control Register, we are in PMode
  78.  
  79. cli ;Don’t forget,Interrupts are the ones which will stop from halting
  80.  
  81. hlt ;Everything has an end, just halt, or else you are messed up
  82.  
  83. times 510 - ($-$$) db 0 ;Oh, hope you remember ,Got to be 512 bytes
  84.  
  85. dw 0xAA55 ;Boot Signature, a lot to forget
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement