Advertisement
Guest User

Untitled

a guest
Apr 30th, 2014
67
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.     cmp al, 15h
  56.     xchg bl, al
  57.     jnz  do_print
  58.    
  59.     mov al, byte [i]            ;int to ascii
  60.     mov dl, 0Ah
  61.     div byte dl
  62.     add al, 30h
  63.     add ah, 30h
  64.     lea si, [bx + fbf]
  65.     mov [si], ax
  66.    
  67. do_print:
  68.     lea si, [bx + fbf]        
  69.     mov cl, 01h         ;repeat char count
  70.     call print_string      
  71.  
  72.    
  73.     inc byte [i]
  74.     cmp byte [i], 65h
  75.     jnz fizzbuzz
  76.    
  77.     cli
  78.     hlt
  79.    
  80.     i db 01h
  81.     fbf db 'Fizz',13,10,0,'Fizzz',0x8,0x7,'Buzz',13,10,0, 0,0,13,10,0
  82.  
  83. print_string:                   ; Routine: output string in SI to screen
  84.     mov ah, 0Eh             ; int 10h 'print char' function
  85.  
  86. .repeat:
  87.     lodsb                   ; Get character from string
  88.     cmp al, 0
  89.     je .done                ; If char is zero, end of string
  90.     int 10h                 ; Otherwise, print it
  91.     jmp .repeat
  92.  
  93. .done:
  94.     ret
  95.    
  96.  
  97.     times 510-($-$$) db 0   ; Pad remainder of boot sector with 0s
  98.     dw 0xAA55               ; The standard PC boot signature
  99.    
  100.     times 1024*1024 db 0       ;for Bochs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement