99 Bottles of Beer In 571 Programming Languages

Discussion in 'OT Technology' started by Black Light, Nov 6, 2003.

  1. Black Light

    Black Light Guest

  2. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
  3. DatacomGuy

    DatacomGuy is moving to Canada

    Joined:
    Oct 14, 2002
    Messages:
    16,546
    Likes Received:
    0
    Location:
    Tampa, FL
  4. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    :cool:

    haha i love the asm ones!
     
  5. RaginBajin

    RaginBajin Have you punched a donkey today?

    Joined:
    Dec 24, 2001
    Messages:
    8,740
    Likes Received:
    0
    Location:
    NoVA
    That's totally awesome..
     
  6. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    I like the C++ Extreme Templating version. 196 lines :rofl:
     
  7. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    Programming language: FORTRAN
    program ninetynine
    implicit none
    integer i

    do i=99,1,-1
    print*, i,' bottles of beer on the wall, ',i,' bottles of beer'
    print*, 'take one down, pass it around, ',i-1,
    . ' bottles of beer on the wall'
    enddo
    end


    :bowdown:

    programming has just been downhill since the godly fortran.
     
  8. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    Programming language: Snobol
    * 99 BOTTLES OF BEER IN SNOBOL (UNTESTED)
    BEER = 99
    MOREBEER OUTPUT = BEER ' BOTTLES OF BEER ON THE WALL'
    OUTPUT = BEER ' BOTTLES OF BEER'
    OUTPUT = 'TAKE ONE DOWN, PASS IT AROUND'
    BEER = BEER - 1
    OUTPUT = BEER ' BOTTLES OF BEER ON THE WALL'
    GT(BEER,0) : S(MOREBEER)
    OUTPUT = 'NO MORE BOTTLES OF BEER ON THE WALL'
    OUTPUT = 'NO MORE BOTTLES OF BEER'
    OUTPUT = 'GO TO THE STORE AND BUY SOME MORE'
    OUTPUT = '99 BOTTLES OF BEER'
    END




    My mom knows how to program in this language... Snobol... yikes.
     
  9. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    Programming language: Spoon
    Taken from the example inside www.bluedust.com/pub/sources/spoon-v1.zip
    See also: http://www.bluedust.com/spoon/

    010111111111001000111111111111101000000110110010001000100000
    001101000100000001101101100100010101010110110000011010010001
    000110111010010000001101001001000100000001101101101111111111
    101100100010010010101101100100010101000100000001101101100000
    110100010001110100000011010001000110111111111111010010010101
    100000110110110000110000011111111111010001000110000100000011
    010010101000100011001000000011011011101001001000000110100010
    000000111011011001000101010000011011000001101101101100100010
    010101010110110110000011010010010001000110110111010010010000
    001101000100011101000000110110110000010001000100000001101100
    100000001100110100101011001000100010000000110110000011011111
    111110010001111111101111111101001000000110100100100010001010
    101011011000001101001000100011011101001000000110110010001101
    101101101100101001001001001001000000110110110110110110110010
    100100100010000000110100010000000111111001000111111111101000
    000110110010100101111001000111111111101000000110111100101001
    011111001000111111111110100000011011001010010011111110010100
    010100000000000000000000000000010100000000000000000000000010
    100100100010001001010101011011011000001101001001000100011011
    011101001001000000110110010001101101101111111111111111001010
    010010010010000001101101101101100100000001101011110010001111
    111111010000001101100101001011111111100100011111111111010000
    001101100000000101000000000000000000000000000000101001011111
    110010001100000000000000000000000000000001000000110110010100
    101111110010001111111111111010000001101100101011100101000101
    011111111111110010100101111111100100011000000000000000000000
    000000000010000001101100000000101001011111111100100011111111
    111010000001101100000000101000000101001011111111001000110000
    000000000000000000000000000100000011011110010100101111111100
    100011111111111101000000110111111001010000000000000000000000
    000000000000000001010000000000001010010111111100100011000000
    000000000000000000000000010000001101110010100101111111100100
    011111111111110100000011011000001010010110010001100000000000
    000000000000000000000001000000110110010101111111111100101000
    101001011111111100100011000000000000000000000000000000010000
    001101100000000000000000101000000000000101001001001000100010
    101010110110000011010010001000110111010010000001101100100011
    011011011011001010010010010010010000001101101101101101101100
    101001001001011110010001111111101000000110110000000010100101
    111001000111111111101000000110111100101001011111001000111111
    111110100000011011001010010011111110010100010100000000000000
    000000000000010100000000000000000000000010100100100010001001
    010101011011011000001101001001000100011011011101001001000000
    110110010001101101101111111111111111001010010010010010000001
    101101101101100100000001101011110010001111111111010000001101
    100101001011111111100100011111111111010000001101100000000101
    000000000000000000000000000000101001011111110010001100000000
    000000000000000000000001000000110110010100101111110010001111
    111111111010000001101100101011100101000101011111111111110010
    100101111111111001000110000000000000000000000000000000100000
    011011000001010000000000001010010111111100100011111111111101
    000000110111111001010111111111111100101011111111110010100000
    000000000000000010100101111111001000110000000000000000000000
    000000000100000011011100101001011111111001000111111111111010
    000001101100000101000000101000000000000000000000000000000101
    001011111110010001100000000000000000000000000000001000000110
    111001010010111111100100011111111111101000000110110000000010
    101111111111100101011111111001010000000000000000000000000000
    001010010111111110010001100000000000000000000000000000001000
    000110111100101001011111001000111111111111111010000001101100
    101011111111111110010100000000000000000000000000000000010100
    101111111001000110000000000000000000000000000000100000011011
    110010100101111111100100011111111111101000000110110010100101
    110010001100000000000000001000000110110010100101110010001111
    111101000000110110010100010100101111111110010001100000000000
    000000000000000001000000110110000000010100101111111001000111
    111111111010000001101111100101011111111111001010010111111110
    010001100000000000000000000000000000000001000000110111111001
    010010111110010001111111111111110100000011011001010010111001
    000111111110100000011011000001010000000000001010111111001010
    000000000000000000000001010000000000000000000000000000000001
    010010111111110010001100000000000000000000000000000000001000
    000110111001010000000000001010001000000011011011011000010001
    000000011010001000000011011011001000101010101101100000110100
    100010001101110100100000011010010010001000000011011011011111
    111111011001000100100101011011001000101010001000000011011011
    000001101000100011101000000110100010001101111111111110100100
    101011000001101101100001100000111111111110100010001100001000
    000110100101010001000110010000000110110111010010010000001101
    000100000001110110110010001010100000110110000011011011011001
    000100101010101101101100000110100100100010001101101110100100
    100000011011010010001000111010000001101101100000100010001000
    000011011001000000011001101001010110010001000100000001101100
    000110111111111100100011111111011111111010010000001101001001
    000100010101010110110000011010010001000110111010010000001101
    100100011011011011011001010010010010010010000001101101101101
    101101100101001001000100000001101000100000001111110010001111
    111111010000001101100101001011110010001111111111010000001101
    111001010010111110010001111111111101000000110110010100100111
    111100101000101000000000000000000000000000101000000000000000
    000000000101001001000100010010101010110110110000011010010010
    001000110110111010010010000001101100100011011011011111111111
    111110010100100100100100000011011011011011001000000011010111
    100100011111111110100000011011001010010111111111001000111111
    111110100000011011000000001010000000000000000000000000000001
    010010111111100100011000000000000000000000000000000010000001
    101100101001011111100100011111111111110100000011011001010111
    001010001010111111111111100101001011111111001000110000000000
    000000000000000000000100000011011000000001010010111111111001
    000111111111110100000011011000000001010000001010010111111110
    010001100000000000000000000000000000001000000110111100101001
    011111111001000111111111111010000001101111110010100000000000
    000000000000000000000000000010100000000000010100101111111001
    000110000000000000000000000000000000100000011011100101001011
    111111001000111111111111101000000110110000010100101100100011
    000000000000000000000000000000000010000001101100101011111111
    111001010001010010111111111001000110000000000000000000000000
    000000100000011011000000000000000001010000000000001010111001
    0100000000000010100010000000110110110110011
     
  10. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    Programming language: Beatnik
    See http://www.cliff.biffle.org/esoterica/beatnik.html for more
    informations about Beatnik.
    99 Bottles of Beer in Beatnik from Paul Dale.


    orb hunter outboards almehs iceleaf feeding cappers frase stint
    benzophenoxazine genius censual bet a scarpings a segue hoddin saccules
    arere benzoxyphenanthrene tipit pasteur aitus incrystallizable repolon
    unona a cordovan tien urent a learnership reacclimatized loris backfurrow
    bloodlust pulau misbuilt garad ume a stof releasable slog a stanine
    unvail seron a yuppies siri snars a waitingly immortalizer columnal
    tours mesmerises tulip alcoate ecritoires tip hatchety asper grossularia
    lapsed dottled runts a outfrown loro inust a undersweep refurbishment
    harmans roral alamosite toilets prerent sleekier notus eale bolti
    torturers irone theologicometaphysical pereion sosia a furcated po lood
    a contrabands hematomyelitis reffos slad cloyingly didus alnilam titre
    interzygapophysial septole lung fibrohemorrhagic tucum slid a purlieuman
    gau unais a bridemaids jacketed tawdrier nong pneumatist durant danseuse
    ringsiders selle nab smog ceratin tsars deflexionize arillode paddled daut
    a burin rimpi torrs a dumpiness outs sutra a confirmee monarchomachist
    tenesmic gout leis tealess scaturient leggier korun ungroaning netes
    grewhound berun averin sued zubeneschamali monists alias a auspicates ions
    ah a dewberries hypophrenosis glaciaria rales lockouts lingua unmitre
    antinormal saris sufflue reallot flurrs tup microspectroscopic barrier
    gaus a begunks red spa a smirkly expediently outslink rerun birthplace
    desine palsies awayes lum egress snurp bialate wiretap tirrs ids ananias
    wallet agas a habaneras rag suine a gossipping eulamellibranchia hu
    overspecialized oceanet ponderate serio epiloguize scian rarish unfilled
    unilinear estre a blowth tine intil a unimmerged typonymic anour epineural
    monal wellanear toruloid scillas tonna deanthropomorphization linolic
    sists lick avises riant a pentameran ago sorts a volubleness propagability
    returfer pandrop wergild wealsmen andy nam zygomaticomaxillary reedes
    riband annal a warlike a tored elatedness foetation pot benzophenoxazine
    arrouse ahem stilt a ungrapple lote duro a greasebush pyramidoprismatic
    turus unformularizable vogul lilos umbraculiferous herblet tensile
    vilely syes arras a gaup glissandos loge a boris partite coregnant
    eater plantarium crois bistres ame a braking tela arist a unsparingness
    tranquillizing plunks egol verbenaceous brere underslip outgoers moarian
    skittler roost sleeping lemes fling isotropies gear real boron petum dues
    a guayacan lull tegs a dandlingly mycorhiza guao quinquevalency edicts
    sprayer urian deconcentrate eaglet dicier gere phenolsulphonephthalein
    foder oriel buzzwigs orcines nassellarian gona drawstop entasia dueling
    tutor a impeding unto rim a warrantable saccharostarchy glossily aden
    sade aldols redoom nintu pythagoreanize felter cornetists sault a piste
    bolster arnee a puncher em aurei a misworded zenocentric lurches isles
    rens ahir wheres pudors drek romescot taler congealedness sapan uncolts
    urge hypsibrachycephalic mislies leare a autotheater sero lasso a cypraeid
    projiciently lairs blamer cubes goel misgovernment occlude brule wainman
    conal edible nevadite sward erose a lubricious gan pus a amidoacetal
    solemnizing inurements orias beek sauger dipole distringas urial sail
    usnic tenonitis gate mizzenmast holour begetters edea alternationist
    inlaid tasseled structural roter selenigenous lullian brattie onset
    a wombats tins arest a shovelnose hyperparasitize encomion trots noll
    auronal attenuant lido characterization simurg emplead geit rus toader
    serpens trioecious coo dispark disert abram doto a homaroid arar nills
    a misinterpret bolshevistically kedger tilia baluchithere veg alumnae
    diablerie lions nimbly carts unstrand seral benzdioxtriazine venge
    tolan nonoxidizable daks udos a countersign lene iglu a bacteroidal
    housewifeship remolades doer porogamous means bargee unhalted osmanli
    bodily slete babblement tannins streetful bestud scoriae relie a zolle
    tort ureas a manically superpublicity loure pharyngoepiglottic rosarians
    interleaf olena saices ameen hoolie koibal lutea contrafagotto remit
    osteoma dout tranquillized poulter sparely bluster dita a tambourgi
    gue rep a uninformed yezzy snipish talio excudit hant regosols
    ballistite reata unsampled essenis dumose mamey guns pilgrimatical
    cub danders obscener irous eructance stupa medius ace a isoclinics
    rast dog a reaedifye confluxibility untin ssu tatted unrotted goas
    thymolsulphonephthalein creeses pro landside imarets pia a huntington
    toil luds a belching hazily abnormal domiciles caducei sesti isogonal
    enrage presume trets a graven rescreens atilt a vindresser tri senna a
    sotnik ber a adoringly sall stoat a anodically unexhaustiveness manrider
    fleaseed ambients novelism earnests gies benzoxyphenanthrene oilless
    lanks atlee a farriery a rogan nutricial accessit dug zygomaticomaxillary
    ladler soredial least a interrupters stun deen a contributed whizzle poa
    oxyphosphate simians looie psychoneurosis shauling batta oligopnea sutlers
    soter a liangs arrowroot lorel a conte lunulites luctations tilts pfenning
    nilgau basoga tetra a revivers aria diau a reprehends nonsympathizer
    positioner lotes contributive meter nonattention astatines trendies
    orifice stod tatouays imid tubage fuligula norie ida corin aerotrain
    outer a overstay tina gool a rearrangement hypophyllous pul razzmatazes
    sourtop chords ornis oximeters sartain brittle steal zygomaticosphenoid
    evade con anorthographically esodic dag a repeatable snot saunt a katydid
    masquerading fringier rores vicarious leglen incisal metastasis land
    rigs etatist avania uca lymphotoxemia mullers ords a placoidei sets
    ador a syncretic hematozoal avocate norna a telic travel telfairia bit
    roll ulcer gopak pieing legman fettling ardu coadunative monel rougy fe
    pachycephalic pressor neons a ponderated sala aures a adjurers
    supersulphurize unirritated sauts propleural balti metaler pyning lento
    palliyan elitist sergette lind quadriphyllous kam laura a ulnocarpal
    nene sains a mittelhand clockmaker vallums trial squirmer stoep peludo
    catatonias tools potes auroral tattling ferriage alula ilia gram lanolines
    dari pterygopharyngeal wisent tiros a macruroid snit oisin a peltiferous
    brachistochronous fantoms toles dolichopodous gunge tordions cinch acetite
    gens mintages rondle recalling roping owing desi hypsibrachycephaly
    proteus guts primer sanko tests purgers insetted teaer a maumetries laid
    mutagens aulos a hepaticas dephilosophize worseness metatantalic sonnes
    tektite radicules unrepentance bionics bedrocks
     
  11. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    And the allpowerful Brainfuck...

    >+++++++++[<+++++++++++>-]<[>[-]>[-]<<[>+>+<<-]>>[<<+>>-]>>>
    [-]<<<+++++++++<[>>>+<<[>+>[-]<<-]>[<+>-]>[<<++++++++++>>>+<
    -]<<-<-]+++++++++>[<->-]>>+>[<[-]<<+>>>-]>[-]+<<[>+>-<<-]<<<
    [>>+>+<<<-]>>>[<<<+>>>-]>[<+>-]<<-[>[-]<[-]]>>+<[>[-]<-]<+++
    +++++[<++++++<++++++>>-]>>>[>+>+<<-]>>[<<+>>-]<[<<<<<.>>>>>-
    ]<<<<<<.>>[-]>[-]++++[<++++++++>-]<.>++++[<++++++++>-]<++.>+
    ++++[<+++++++++>-]<.><+++++..--------.-------.>>[>>+>+<<<-]>
    >>[<<<+>>>-]<[<<<<++++++++++++++.>>>>-]<<<<[-]>++++[<+++++++
    +>-]<.>+++++++++[<+++++++++>-]<--.---------.>+++++++[<------
    ---->-]<.>++++++[<+++++++++++>-]<.+++..+++++++++++++.>++++++
    ++[<---------->-]<--.>+++++++++[<+++++++++>-]<--.-.>++++++++
    [<---------->-]<++.>++++++++[<++++++++++>-]<++++.-----------
    -.---.>+++++++[<---------->-]<+.>++++++++[<+++++++++++>-]<-.
    >++[<----------->-]<.+++++++++++..>+++++++++[<---------->-]<
    -----.---.>>>[>+>+<<-]>>[<<+>>-]<[<<<<<.>>>>>-]<<<<<<.>>>+++
    +[<++++++>-]<--.>++++[<++++++++>-]<++.>+++++[<+++++++++>-]<.
    ><+++++..--------.-------.>>[>>+>+<<<-]>>>[<<<+>>>-]<[<<<<++
    ++++++++++++.>>>>-]<<<<[-]>++++[<++++++++>-]<.>+++++++++[<++
    +++++++>-]<--.---------.>+++++++[<---------->-]<.>++++++[<++
    +++++++++>-]<.+++..+++++++++++++.>++++++++++[<---------->-]<
    -.---.>+++++++[<++++++++++>-]<++++.+++++++++++++.++++++++++.
    ------.>+++++++[<---------->-]<+.>++++++++[<++++++++++>-]<-.
    -.---------.>+++++++[<---------->-]<+.>+++++++[<++++++++++>-
    ]<--.+++++++++++.++++++++.---------.>++++++++[<---------->-]
    <++.>+++++[<+++++++++++++>-]<.+++++++++++++.----------.>++++
    +++[<---------->-]<++.>++++++++[<++++++++++>-]<.>+++[<----->
    -]<.>+++[<++++++>-]<..>+++++++++[<--------->-]<--.>+++++++[<
    ++++++++++>-]<+++.+++++++++++.>++++++++[<----------->-]<++++
    .>+++++[<+++++++++++++>-]<.>+++[<++++++>-]<-.---.++++++.----
    ---.----------.>++++++++[<----------->-]<+.---.[-]<<<->[-]>[
    -]<<[>+>+<<-]>>[<<+>>-]>>>[-]<<<+++++++++<[>>>+<<[>+>[-]<<-]
    >[<+>-]>[<<++++++++++>>>+<-]<<-<-]+++++++++>[<->-]>>+>[<[-]<
    <+>>>-]>[-]+<<[>+>-<<-]<<<[>>+>+<<<-]>>>[<<<+>>>-]<>>[<+>-]<
    <-[>[-]<[-]]>>+<[>[-]<-]<++++++++[<++++++<++++++>>-]>>>[>+>+
    <<-]>>[<<+>>-]<[<<<<<.>>>>>-]<<<<<<.>>[-]>[-]++++[<++++++++>
    -]<.>++++[<++++++++>-]<++.>+++++[<+++++++++>-]<.><+++++..---
    -----.-------.>>[>>+>+<<<-]>>>[<<<+>>>-]<[<<<<++++++++++++++
    .>>>>-]<<<<[-]>++++[<++++++++>-]<.>+++++++++[<+++++++++>-]<-
    -.---------.>+++++++[<---------->-]<.>++++++[<+++++++++++>-]
    <.+++..+++++++++++++.>++++++++[<---------->-]<--.>+++++++++[
    <+++++++++>-]<--.-.>++++++++[<---------->-]<++.>++++++++[<++
    ++++++++>-]<++++.------------.---.>+++++++[<---------->-]<+.
    >++++++++[<+++++++++++>-]<-.>++[<----------->-]<.+++++++++++
    ..>+++++++++[<---------->-]<-----.---.+++.---.[-]<<<]
     
  12. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Was suprised that no one had submitted it on a TI-83/83+ yet, so I did:

    99->X
    While X>0
    ClrHome
    Output(1,1,X)
    Output(1,3," BOTTLES OF")
    Output(2,1,"BEER ON THE WALL")
    Output(3,1,X)
    Output(3,3," BOTTLES OF")
    Output(4,1,"BEER. TAKE ONE")
    Output(5,1,"DOWN, PASS IT")
    Output(6,1,"AROUND, ")
    X-1->X
    Output(6,9,X)
    Output(7,1,"BOTTLES OF BEER")
    Output(8,1,"ON THE WALL.")
    For(A,0,450)
    End
    End
     
  13. AccidenT

    AccidenT Remember I will always love you, as I claw your fu

    Joined:
    Oct 2, 2000
    Messages:
    1,880
    Likes Received:
    0
    Location:
    Portland, ME
    :dunno: the only reason that one is more concise than a lot of the others is because the author didn't use different print statements when there is only one bottle left
     
  14. Canucker

    Canucker Banned

    Joined:
    Sep 18, 2002
    Messages:
    34,010
    Likes Received:
    0
    :rofl:


    I know these two assembler languages:

    Code:
    
    
    [code] 	
    
    ;	$Id: 99bottlesofbeer.asm,v 1.3 2003/10/23 10:17:21 thilo Exp thilo $
    ;
    ;	99 bottles of beer on the wall for any recent midrange Microchip MCU with 14bit
    ;	programm word (PIC16CXXX/PIC16FXXX family) and USART module, e.g. all PIC16F87x
    ;
    ;	written by Thilo Manske 
    ;
    ;	needs 3 GP registers and 158 words (~277 bytes) of program memory
    ;	use gpasm to assemble (see http://gputils.sourceforge.net/)
    
    ;	adjust the following lines for your CPU
    	list	p=16f873
    	include "p16f873.inc"
    	__config _WDT_OFF & _XT_OSC
    
    ; GP registers, since they are in [0x70..0x7f] they are available in all banks
    ; and we don't have to care about bank switching when we access them
    	cblock 0x70
    	pointer
    	bottles10
    	bottles1
    	endc
    
    ;; macro to select the correct bank for <address>
    ;; The default BANKSEL macro always sets/clears both bank bits, but we only
    ;; use bank 0 and 1 and don't have to take care of RP1
    SELBANK 	macro	address
    	if address < 0x80
    		bcf	STATUS,RP0
    	else
    		bsf	STATUS,RP0
    	endif
    	endm
    
    ; start
    	org 0
    	SELBANK SPBRG
    	movlw	d'38'		; adjust this for your clock freq/baud rate
    	movwf	SPBRG
    
    	movlw	(1<<TXEN)	; enable the transmitter
    	movwf	TXSTA		; TXSTA is in the same bank as SPBRG
    
    	SELBANK	RCSTA
    	movlw	(1<<SPEN)	; enable the serial port
    	movwf	RCSTA
    
    restart:
    	movlw	9
    	movwf	bottles10
    	movwf	bottles1
    
    bigloop:
    	call	nbottlesofbeer
    	call	onthewall
    	call 	commacrlf
    	call	nbottlesofbeer
    	call	stopcrlf
    
    	movlw	takeonedowntxt
    	call	stringout
    	call	commacrlf
    
    	decf	bottles1,f
    	bnz	goon		; second digit==0?
    
    	tstf	bottles10,f	; and first digit==0 as well?
    	bz	outofbeer	; no more bottles of beer :(
    
    goon:
    	btfss	bottles1,7	; underflow in second digit?
    		goto	ok		
    
    	decf	bottles10,f	; yes
    
    	movlw	9
    	movwf	bottles1
    ok:
    	call	nbottlesofbeer
    	call	onthewall
    	call	stopcrlf
    	call	crlf
    	goto	bigloop
    	
    outofbeer:
    	movlw	nomoretxt
    	call	stringout
    	call	bottlesofbeer
    	call	stopcrlf
    
    	SELBANK	TXSTA
    	btfss	TXSTA,TRMT	; wait for the transmit buffer to drain
    		goto	$-1
    
    	sleep			; Good night!
    
    	goto	restart	; since we haven't enabled any interrupts, there isn't
    			; any chance the PIC will ever wake up and get here
    ; subroutines
    
    ;;	writes ".\r\n"
    stopcrlf
    	movlw	'.'
    	goto	$+2		; skip next instruction	
    ;;	writes ",\r\n"
    commacrlf:
    	movlw	','
    	call	charout
    ;; writes carriage return + linefeed
    crlf:
    	movlw	'\r'
    	call	charout
    	movlw	'\n'
    ;; puts char in w out on the serial bus
    charout:
    	SELBANK	TXSTA
    	btfss	TXSTA,TRMT	; send buffer empty?
    		goto $-1
    
    	SELBANK	TXREG
    	movwf	TXREG
    	return
    
    ;; writes "n bottles of beer"
    nbottlesofbeer:
    	movf	bottles10,w
    	bnz	firstdigit	; first digit zero?
    
    	decf	bottles1,w	; second digit one?
    	bz	onebottleofbeer	; one last bottle :-/
    	goto	seconddigit
    firstdigit
    	addlw	'0'
    	call	charout
    seconddigit
    	movf	bottles1,w
    	addlw	'0'
    	call	charout
    ;; writes "bottles of beer"
    bottlesofbeer
    	movlw	bottletxt
    	call	stringout
    	movlw 	's'
    	call	charout
    ;; writes "of beer"
    ofbeer
    	movlw	ofbeertxt
    ;; writes string w is pointing to
    stringout
    	movwf	pointer
    	call	getchar
    	addlw	0		; test for zero (flag is not set by retlw)
    	skpnz
    		return		; yes -> end of string
    	call	charout
    	incf	pointer,w
    	goto	stringout
    getchar				; this will look weird to people who don't know how
    	movwf	PCL		; you read data out of a PICs program memory ;)
    
    ;; writes "1 bottle of beer"
    onebottleofbeer
    	movlw	'1'
    	call	charout
    	movlw	bottletxt
    	call	stringout
    	goto	ofbeer
    ;; writes "on the wall"
    onthewall
    	movlw	onthewalltxt
    	goto	stringout
    
    ; "data subroutines"
    bottletxt
    	dt " bottle\0"
    ofbeertxt
    	dt " of beer\0"
    onthewalltxt
    	dt " on the wall\0"
    takeonedowntxt
    	dt "Take one down, pass it around\0"
    nomoretxt
    	dt "No more\0"
    
    	end	
    
    / bottles on the wall in 8051 assembler
    ;/
    ;/ bill webster 2003
    ;/____________________________________________________________________________

    ; sfr definitions
    SCON data 0x98
    SBUF data 0x99
    PCON data 0x87
    TMOD data 0x89
    TH1 data 0x8D
    B data 0xF0

    ; bit definitions
    TI bit 0x99
    TR1 bit 0x8E

    ;/ start vector
    ;/____________________________________________________________________________
    cseg at 0

    jmp start


    cseg at 0x30

    ;/ print number in r0 as decimal - limited to numbers in [0..99]
    ;/____________________________________________________________________________
    putn:
    mov a, r0
    mov b, #10
    div ab
    jz units
    call printDigit

    units:
    mov a, b

    ; fall through

    ;/ convert number in [0..9] to ascii digit & print
    ;/____________________________________________________________________________
    printDigit:

    add a, #'0'

    ; fall through

    ;/ character out
    ;/____________________________________________________________________________
    putch:

    jnb TI, putch
    clr TI
    mov SBUF, a
    ret

    ;/ print string at dptr
    ;/____________________________________________________________________________
    puts:
    clr a
    movc a, @a + dptr
    jnz more
    ret

    more:
    call putch
    inc dptr
    jmp puts

    ;/
    ;/____________________________________________________________________________
    start:

    ; initialize serial port
    orl TMOD, #0x20
    setb TR1
    mov SCON, #0x50

    mov TH1, #0xFE
    orl PCON, #0x80
    setb TI

    ; bottles to begin with
    mov r0, #99

    verse:
    call putn

    mov dptr, #line1
    call puts

    call putn

    mov dptr, #line2
    call puts

    dec r0
    call putn

    mov dptr, #line1
    call puts

    mov dptr, #eoln
    call puts

    cjne r0, #0, verse

    jmp $

    ;/ string constants
    ;/____________________________________________________________________________

    cr equ 0x0D
    lf equ 0x0A

    line1: db ' bottles of beer on the wall,'
    eoln: db cr, lf, 0

    line2: db ' bottles of beer,', cr, lf
    db 'Take one down, pass it around,', cr, lf, 0

    end


    [/code]
     
  15. s2k

    s2k OT Supporter

    Joined:
    Oct 8, 2002
    Messages:
    46,918
    Likes Received:
    15
    Location:
    corn field, iowa
    u guys wanna tell me whats going on in this thread :hs:
     
  16. warm

    warm Capitalism ftw

    Joined:
    Mar 9, 2003
    Messages:
    5,536
    Likes Received:
    0
    Location:
    Seattle/Kirkland
    :eek3: That's crazy talk!

    I like the Scheme one:
    Code:
    (define bottles
      (lambda (n)
        (cond ((= n 0) (display "No more bottles"))
              ((= n 1) (display "One bottle"))
              (else (display n) (display " bottles")))
        (display " of beer")))
    
    (define beer
      (lambda (n)
        (if (> n 0)
            (begin
              (bottles n) (display " on the wall") (newline)
              (bottles n) (newline)
              (display "Take one down, pass it around") (newline)
              (bottles (- n 1)) (display " on the wall") (newline)
              (newline)
              (beer (- n 1))))))
    
    (beer 99)
    :o
     
  17. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    I hate writing scheme so much :o
     
  18. XR250rdr

    XR250rdr OT Supporter

    Joined:
    Mar 1, 2004
    Messages:
    24,476
    Likes Received:
    21
    Location:
    Ca
    Its up to 621 now!

    no
     
  19. monolith

    monolith My soul grows ever weary and the end is ever near. OT Supporter

    Joined:
    May 9, 2004
    Messages:
    32,591
    Likes Received:
    260
    Location:
    Southern California
    Totally fucking cool!
     
  20. oz02

    oz02 New Member

    Joined:
    Mar 28, 2005
    Messages:
    53
    Likes Received:
    0
    Some people have too much time on their hands...
     
  21. monolith

    monolith My soul grows ever weary and the end is ever near. OT Supporter

    Joined:
    May 9, 2004
    Messages:
    32,591
    Likes Received:
    260
    Location:
    Southern California
    I remember BASIC

    :wtc:

    Code:
    10 REM Basic version of 99 bottles of beer
    20 FOR X=100 TO 1 STEP -1
    30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
    40 PRINT "Take one down and pass it around,"
    50 PRINT X-1;"bottle(s) of beer on the wall"
    60 NEXT
    :bowdown:
     

Share This Page