assembly language

Bookmarking Digg Diigo DZone Earthlink Google
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Assembler (Intel x86)

Author:Roman Ovseytsev
Score: (3.00 in 19 votes)
; 99 Bottles of Beer.
; x86 Assembler for Windows console.
; by Roman Ovseytsev (,
; Assemble with MASM32:
; ml.exe /c /coff beer.asm
; link.exe /SUBSYSTEM:CONSOLE beer.obj

.model flat, stdcall
option casemap:none 

include \masm32\include\
include \masm32\include\

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib


strng1  db "%i bottle%sof beer on the wall, %i bottle%sof beer.",13,10,0
strng2  db "Take one down and pass it around, %i bottle%sof beer on the wall.",13,10,13,10,0
strng6  db "Go to the store and buy some more, 99 bottles of beer on the wall.",13,10
str1    db "s ",0
str3    db "no more",0


outnum  dd ?
outbuf  db 75 dup(?)


start PROC 

        invoke  GetStdHandle, -11
        mov     ebx, eax

        mov     esi, 99
        mov     edi, offset str1

l0:     invoke  wsprintf, ADDR outbuf, ADDR strng1, esi, edi, esi, edi

        cmp     esi, offset str3
        jne     @f
        mov     [outbuf], byte ptr "N"

@@:     invoke  WriteConsole, ebx, ADDR outbuf, eax, ADDR outnum, 0

        cmp     esi, offset str3
        je      l2

        dec     esi
        jnz     @f
        mov     [strng2+35], byte ptr "s"
        mov     esi, offset str3
        mov     edi, offset str1

@@:     cmp     esi, 1
        jne     l1
        inc     edi

l1:     invoke  wsprintf, ADDR outbuf, ADDR strng2, esi, edi
        invoke  WriteConsole, ebx, ADDR outbuf, eax, ADDR outnum, 0

        cmp     esi, offset str3
        jne     l0
        mov     [strng1+1], byte ptr "s"
        mov     [strng1+33], byte ptr "s"
        jmp     l0

l2:     invoke  WriteConsole, ebx, ADDR strng6, sizeof strng6, ADDR outnum, 0

        invoke  ExitProcess, 0

start ENDP

end start

Download Source | Write Comment

Alternative Versions

really uses assembler instructionsMarcin Koziol04/26/063


Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!




Security Code: