; CS2011, A Term 1999
; Prof. Sergio A. Alvarez
;
; Note: this file contains an outline for use in HW4, 
;       not a complete program
; various directives and instructions are missing

title Recursive product(x,y)

.model small
.stack

.data
factor1prompt  db "Input the first factor:  ", 0
factor2prompt  db "Input the second factor: ", 0
outmessage     db "The result is:   ", 0
newline        db  0ah,0dh,0

.code

; external procedures from Irvine library irvine.lib
extrn Writestring:proc, Readint:proc, Writeint:proc

main proc
; computes integer products
; prompts user for two factors factor1, factor2
; writes product factor1*factor2 to console
; no error handling provided

.startup

; get factor1 from console
   mov dx,offset factor1prompt
   call Writestring
   call Readint

; push factor1 onto stack
   push ax

; get factor2 from console
   mov dx,offset factor2prompt
   call Writestring
   call Readint 

; push factor2 onto stack
   push ax

; compute product(x,y)
   call product

; report result using binary-to-ASCII conversion
   mov bx,10 ; radix for ASCII output
   call Writeint

.exit
main endp


product proc
; prototype is product(x,y) 
; recursive x*y modeled on the following definition:
;   x*0 = 0
;   x*(y+1) = x*y + x
; x, y passed on stack by value
; (x is pushed first, then y)
; value x*y returned in ax 
; procedure performs its own stack clean-up

product endp

end

