boot_sect_stack.asm 793 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. mov ah, 0x0e
  2. mov bp, 0x8000 ; this is an address far away from 0x7c00 so that we don't get overwritten
  3. mov sp, bp
  4. push 'A'
  5. push 'B'
  6. push 'C'
  7. ; to show how the stack grows downwards
  8. mov al, [0x7ffe] ; 0x8000 - 2
  9. int 0x10
  10. ; however, don't try to access [0x8000] now, because it won't work
  11. ; you can only access the stack top so, at this point, only 0x7ffe (look above)
  12. mov al, [0x8000]
  13. int 0x10
  14. ; recover our characters using the standard procedure: 'pop'
  15. ; We can only pop full words so we need an auxiliary register to manipulate
  16. ; the lower byte
  17. pop bx
  18. mov al, bl
  19. int 0x10 ; prints C
  20. pop bx
  21. mov al, bl
  22. int 0x10 ; prints B
  23. pop bx
  24. mov al, bl
  25. int 0x10 ; prints A
  26. ; data that has been pop'd from the stack is garbage now
  27. mov al, [0x8000]
  28. int 0x10
  29. jmp $
  30. times 510-($-$$) db 0
  31. dw 0xaa55