; Guide to Assembly Language
        ; Section 7.8 Complete Program
        ; Copyright 2010, James T. Streib
        .model flat,c
        .stack 100h
scanf     PROTO arg2:Ptr Byte, inputlist:VARARG
printf    PROTO arg1:Ptr Byte, printlist:VARARG     
msg1fmt   byte 0Ah,"%s%d",0Ah,0Ah,0
msg1      byte "The contents of the accumulator are: ",0
temp      sdword ?
three     sdword 3
LOADACC   macro operand
        mov eax,operand      ;; load eax with the operand
ADDACC    macro operand
        add eax,operand      ;; add to eax the operand
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
        .while ecx >0
        add eax,ebx          ;; repetitively add
        dec ecx              ;; decrement ecx
        if operand LT 0      ;; if operand is negative
        neg eax              ; negate accumulator, eax
        pop ecx              ;; restore ecx and ebx
        pop ebx
main      proc
        LOADACC 1
        ADDACC 2
        ADDACC three
        MULTACC 4
        MULTACC -3
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
OUTACC    endp