Guest User

Untitled

a guest
Nov 10th, 2015
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .code16
  2. .global _start
  3.  
  4. .equ STACK_SEGMENT, 0x8E00
  5. .equ ORG_SEGMENT, 0x0
  6.  
  7. .text
  8. _start:
  9.         cli
  10.         jmp $ORG_SEGMENT, $(asmain)
  11.  
  12. asmain:
  13.  
  14.         xor %ax, %ax
  15.         mov %ax, %ds
  16.         mov %ax, %es
  17.         mov %ax, %ss
  18.  
  19.         mov $STACK_SEGMENT, %sp
  20.    
  21.         mov $0xDEAD, %ax # Print a determined value to check if the function
  22.                          # itself is working.
  23.         call printRegister
  24.         call putSeparator
  25.  
  26.         mov $msg, %ax # FIXME
  27.         call printRegister # Nothing is printed; the '.' is never printed.
  28.                            
  29.        
  30. .end:
  31.         mov $'.', %al
  32.         call printChar
  33.  
  34. .stop:
  35.         cli
  36.         hlt
  37.         jmp .stop
  38.  
  39. printChar:
  40.         # print char in %Al
  41.        
  42.         mov $0xE, %ah # interrupt service
  43.         mov $0x3, %bh # BH = page number = 0 ; BL = 3 = Cyan (ignored)
  44.         pusha # BIOS might be nasty
  45.         int $0x10
  46.         popa
  47.  
  48.         ret
  49.  
  50. putSeparator:
  51.         mov $'_', %al
  52.         call printChar
  53.         ret
  54.  
  55. printRegister:
  56.  
  57.         test %ax, %ax # test for 0, that would
  58.         jne .go
  59.         mov $'0', %al
  60.         call printChar
  61.         ret
  62.        
  63. .go:
  64.         mov $10, %bx
  65.         xor %cx, %cx # number of elements pushed.
  66.         xor %dx, %dx # high part of dividend
  67. .loop:
  68.         div %bx     # result = %AX ; remaineder = %DX
  69.        
  70.         # we're not done yet:
  71.         # Increment n. of elements
  72.         add $1, %cx  # elements to show
  73.        
  74.         add $0x30, %dx # convert to ASCII
  75.         push %dx
  76.        
  77.         test %ax, %ax # should we continue?
  78.         je .show
  79.  
  80.         # Prepare %AX for next divs.
  81.         xor %dx, %dx
  82.         jmp .loop          
  83.        
  84. .show:
  85.         pop %dx
  86.        
  87.         mov %dl, %al # load character -- already printable
  88.         call printChar
  89.          
  90.         sub $1, %cx
  91.         test %cx, %cx
  92.         jnz .show
  93.  
  94.         ret
  95.  
  96. msg: .asciz "You shall not see this message on real hardware."
  97.  
  98. .space 510 - (. - _start)
  99. .word 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment