- 99 bottles of beer
- 28.1.03 17:08
- Autors: Lāčplēšplēsis
Kurš gan programmētājs nezin šo maģisko frāzi? Ja nezini, tad tūdaļ, tūdaļ. 99 bottles of the beer ir vienkārša hello world tipa programmiņa. Un tā ir uzrakstīta kā minimums 487 dažādās programmēšanas valodās.
; 99 Bottles of Beer program in Intel 8086 assembly language. ; Assemble to a .COM file for MS-DOS. ; ; Author: Alan deLespinasse ; aldel@alum.mit.edu ; www.aldel.com code segment assume cs:code,ds:code org 100h start: ; Main loop mov cx, 99 ; bottles to start with loopstart: call printcx ; print the number mov dx,offset line1 ; print the rest of the first line mov ah,9 ; MS-DOS print string routine int 21h call printcx ; print the number mov dx,offset line2_3 ; rest of the 2nd and 3rd lines mov ah,9 int 21h dec cx ; take one down call printcx ; print the number mov dx,offset line4 ; print the rest of the fourth line mov ah,9 int 21h cmp cx, 0 ; Out of beer? jne loopstart ; if not, continue int 20h ; quit to MS-DOS ; subroutine to print CX register in decimal printcx: mov di, offset numbufferend ; fill the buffer in from the end mov ax, cx ; put the number in AX so we can divide it printcxloop: mov dx, 0 ; high-order word of numerator - always 0 mov bx, 10 div bx ; divide DX:AX by 10. AX=quotient, DX=remainder add dl,'0' ; convert remainder to an ASCII character mov [ds:di],dl ; put it in the print buffer cmp ax,0 ; Any more digits to compute? je printcxend ; if not, end dec di ; put the next digit before the current one jmp printcxloop ; loop printcxend: mov dx,di ; print, starting at the last digit computed mov ah,9 int 21h ret ; Data line1 db ' bottles of beer on the wall,',13,10,'$' line2_3 db ' bottles of beer,',13,10,'Take one down, pass it around,',13,10,'$' line4 db ' bottles of beer on the wall.',13,10,13,10,'$' numbuffer db 0,0,0,0,0 numbufferend db 0,'$' code ends end start
- 5 rakstair doma
- 28.1.03 17:55
-
man ļoti patīk Brainfuck versija. Un vēl viena tur jautra bja uz S burta - tikai no 1niekiem un 0ītēm.
- Atbildēt
- 28.1.03 20:01
-
Bezvārdis
shamo arii es savos 14 maaku uztaisiit :))
program BottlesOfBeers(input, output);
var
bottles: integer;
begin
bottles := 99;
repeat
WriteLn(bottles, ' bottles of beer on the wall, ',
bottles, ' bottles of beer.');
Write('Take one down, pass it around, ');
bottles := bottles-1;
WriteLn(bottles, ' bottles of beer on the wall.');
until (bottles = 1);
WriteLn('1 bottle of beer on the wall, one bottle of beer.');
WriteLn('Take one down, pass it around,'
' no more bottles of beer on the wall')
end.
/OxyD/ - Atbildēt
- 28.1.03 21:25
-
404
- Atbildēt
- 29.1.03 12:10
-
Ummm??
- Atbildēt