; Guide to Assembly Language
     ; Section 5.6 Complete Program
     ; Copyright 2019, James T. Streib
     .listall
     .686
     .model flat,c
     .stack 100h
scanf     PROTO arg2:Ptr Byte, inputlist:VARARG
printf    PROTO arg1:Ptr Byte, printlist:VARARG
     .data
in1fmt    byte "%d",0
msg1fmt   byte "%s",0
msg3fmt   byte "%s%d",0Ah,0Ah,0
errfmt    byte "%s",0Ah,0Ah,0
errmsg1   byte 0Ah,"Error: Negative x and/or y",0
errmsg2   byte 0Ah,"Error: Undefined answer",0
msg1      byte "Enter x: ",0
msg2      byte "Enter n: ",0
msg3      byte 0Ah,"The answer is: ",0
x         sdword ?
n         sdword ?
ans       sdword ?
i         sdword ?
     .code
main      proc
     INVOKE printf, ADDR msg1fmt, ADDR msg1
     INVOKE scanf, ADDR in1fmt, ADDR x
     INVOKE printf, ADDR msg1fmt, ADDR msg2
     INVOKE scanf, ADDR in1fmt, ADDR n
     .if x<0 || n<0
     INVOKE printf, ADDR errfmt, ADDR errmsg1
     .else
     .if x==0 && n==0
     INVOKE printf, ADDR errfmt, ADDR errmsg2
     .else
     mov ecx,1
     mov ans,1
     .while ecx <= n
     mov eax,ans
     imul x
     mov ans,eax
     inc ecx
     .endw
     mov i,ecx
     INVOKE printf, ADDR msg3fmt, ADDR msg3, ans
     .endif
     .endif
     ret
main      endp
     end