; Guide to Assembly Language
        ; Section 7.8 Complete Program
        ; Copyright 2010, James T. Streib
        .listall
        .386
        .model flat,c
        .stack 100h
scanf     PROTO arg2:Ptr Byte, inputlist:VARARG
printf    PROTO arg1:Ptr Byte, printlist:VARARG     
        .data
msg1fmt   byte 0Ah,"%s%d",0Ah,0Ah,0
msg1      byte "The contents of the accumulator are: ",0
temp      sdword ?
three     sdword 3
        .code
LOADACC   macro operand
        mov eax,operand      ;; load eax with the operand
        endm
ADDACC    macro operand
        add eax,operand      ;; add to eax the operand
        endm
MULTACC   macro operand
        push ebx             ;; save ebx and ecx
        push ecx
        mov ebx,eax          ;; mov eax to ebx
        mov eax,0            ;; clear accumulator to zero
        mov ecx,operand      ;; load ecx with operand
        if operand LT 0      ;; if operand is negative
        neg ecx              ; make ecx positive for loop
        endif
        .while ecx >0
        add eax,ebx          ;; repetitively add
        dec ecx              ;; decrement ecx
        .endw
        if operand LT 0      ;; if operand is negative
        neg eax              ; negate accumulator, eax
        endif
        pop ecx              ;; restore ecx and ebx
        pop ebx
        endm
main      proc
        LOADACC 1
        ADDACC 2
        ADDACC three
        MULTACC 4
        MULTACC -3
        CALL OUTACC
        ret
main      endp
OUTACC    proc
        push eax   ; save eax, ecx, and edx
        push ecx
        push edx
        mov temp,eax
        INVOKE printf, ADDR msg1fmt, ADDR msg1, temp
        pop edx    ; restore eax, ecx, and edx
        pop ecx
        pop eax
        ret
OUTACC    endp
        end