Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 16
- boot:
- cli
- mov ax, 07C0h
- mov ds, ax
- mov gs, ax
- mov fs, ax
- mov es, ax
- mov ax, 07E0h
- mov ss, ax
- mov bp, ax
- mov sp, 0FFh
- sti
- ;;;;;;;;;;;;;;; main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}
- fizzbuzz: ;(!(i%5)^!!(i%3)*3)*6
- xor ax, ax
- mov al, byte [i] ;i%5
- mov dl, 05h
- div byte dl
- test ah, 07h ;!
- pushf
- pop cx
- and cx, 40h
- shr cx, 06h
- xor ah, ah
- mov al, byte [i] ;i%3
- mov dl, 03h
- div byte dl
- test byte ah, 03h ;!!
- push cx
- pushf
- pop cx
- and cx, 40h
- shr cx, 06h
- xor cx, 01h
- mov al, cl
- pop cx
- mov dx, 03h ;*3
- mul dx
- xor al, cl ;^
- mov dl, 07h ;*7 instead of 6 for extra char byte CrLf
- mul dl
- cmp al, 15h
- xchg bl, al
- jnz do_print
- mov al, byte [i] ;int to ascii
- mov dl, 0Ah
- div byte dl
- add al, 30h
- add ah, 30h
- lea si, [bx + fbf]
- mov [si], ax
- do_print:
- lea si, [bx + fbf]
- mov cl, 01h ;repeat char count
- call print_string
- inc byte [i]
- cmp byte [i], 65h
- jnz fizzbuzz
- cli
- hlt
- i db 01h
- fbf db 'Fizz',13,10,0,'Fizzz',0x8,0x7,'Buzz',13,10,0, 0,0,13,10,0
- print_string: ; Routine: output string in SI to screen
- mov ah, 0Eh ; int 10h 'print char' function
- .repeat:
- lodsb ; Get character from string
- cmp al, 0
- je .done ; If char is zero, end of string
- int 10h ; Otherwise, print it
- jmp .repeat
- .done:
- ret
- times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
- dw 0xAA55 ; The standard PC boot signature
- times 1024*1024 db 0 ;for Bochs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement