Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     BITS 16
  2.  
  3. boot:
  4.     cli
  5.    
  6.     mov     ax, 07C0h
  7.     mov     ds, ax
  8.     mov     gs, ax
  9.     mov     fs, ax
  10.     mov     es, ax
  11.    
  12.     mov     ax, 07E0h
  13.     mov     ss, ax
  14.     mov     bp, ax
  15.     mov     sp, 0FFh
  16.    
  17.     sti
  18.  
  19.  ;;;;;;;;;;;;;;; main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}
  20.  
  21. fizzbuzz:                       ;(!(i%5)^!!(i%3)*3)*6
  22.     xor     ax, ax
  23.    
  24.     mov     al, byte [i]        ;i%5
  25.     mov     dl, 05h
  26.     div     byte dl          
  27.  
  28.     test    ah, 07h             ;!
  29.     pushf
  30.     pop     cx
  31.     and     cx, 40h
  32.     shr     cx, 06h
  33.    
  34.     xor     ah, ah
  35.     mov     al, byte [i]        ;i%3
  36.     mov     dl, 03h
  37.     div     byte dl
  38.  
  39.     test    byte ah, 03h        ;!!
  40.     push    cx
  41.     pushf
  42.     pop     cx
  43.     and     cx, 40h
  44.     shr     cx, 06h
  45.     xor     cx, 01h
  46.     mov     al, cl
  47.     pop     cx
  48.    
  49.     mov     dx, 03h             ;*3
  50.     mul     dx
  51.     xor     al, cl              ;^
  52.     mov     dl, 07h             ;*7 instead of 6 for extra char byte CrLf
  53.     mul     dl
  54.    
  55.     xchg    bl, al
  56.     lea     si, [bx + fbf]
  57.     cmp     bl, 15h
  58.     jnz     do_print
  59.    
  60.     mov     al, byte [i]        ;int to ascii
  61.     mov     dl, 0Ah
  62.     div     byte dl
  63.     add     al, 30h
  64.     add     ah, 30h
  65.     mov     [si], ax
  66.    
  67. do_print:    
  68.     mov     cl, 01h        
  69.     call    print_string      
  70.  
  71.    
  72.     inc     byte [i]
  73.     cmp     byte [i], 65h
  74.     jnz     fizzbuzz
  75.    
  76.     cli
  77.     hlt
  78.    
  79.     i   db 01h
  80.     fbf db 'Fizz',13,10,0,'Fizzz',0x8,0x7,'Buzz',13,10,0, 0,0,13,10,0
  81.  
  82. print_string:                  
  83.     mov     ah, 0Eh            
  84.  
  85. .repeat:
  86.     lodsb                  
  87.     cmp     al, 0
  88.     je      .done              
  89.     int     10h                
  90.     jmp     .repeat
  91.  
  92. .done:
  93.     ret
  94.    
  95.  
  96.     times 510-($-$$) db 0   ; pad
  97.     dw 0xAA55               ; boot sig
  98.    
  99.     times 1024*1024 db 0       ;for Bochs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement