My favorites | Sign in
Project Logo
                
Search
for
Updated Nov 05, 2008 by odin243
Labels: Phase-Implementation, Featured
ProcedureMultiply  

Procedure/routine documentation: Multiply:

Writer's name: Thomas Tharp

Most recent update Date: 4 Nov. 2008

Brief description: Takes in two integer arguments and returns an integer equal to their product.

Inputs: and Preconditions: Requires two words of input (in the form of two integers)

I use:

Outputs and Postconditions:

I Change in computer:

Status: CLEAN AND DONE

Internal documentation:

;//--- --- Multiply() begin--- ---; 
br Mdriver
;//;;;;;;;;;;;;;;;;;int Multiply(int M1, int M2);;;;;;;;;;
M1: .equate 4
M2: .equate 2
MProd: .equate 6

Multiply: lda 0x0000,i
sta MProd,s
lda M1,s
Mwhile: BREQ MendWHLE
asra
sta M1,s
BRC Mone
BR MendONE
Mone: lda MProd,s
adda M2,s
sta MProd,s
MendONE: lda M2,s
asla
sta M2,s
lda M1,s
BR Mwhile
MendWHLE: RET0
;//;;;;;;;;;;;;;;;;;;;end of Multiply procedure;;;;;;;
;Driver for int Multiply(int,int)
str1: .ascii "\nPlease enter the first number: \x00"
str2: .ascii "\nPlease enter the second number: \x00"
Mnum1: .equate 0
Mnum2: .equate 2
MProduct: .equate 4
MDvars: .equate 6
Mdriver: subsp MDvars,i
stro str1,d
deci Mnum1,s
stro str2,d
deci Mnum2,s
;//;;;;;;;;;;;;;;Begin call for Multiply(Mnum1,Mnum2)
lda Mnum1,s
sta -4,s;//stores Mnum1 above the sp, leaving room for the return value
lda Mnum2,s
sta -6,s;//stores Mnum2 above Mnum1
subsp 6,i;//pushes return, Mnum1, and Mnum2 above the SP
call Multiply
addsp 6,i;//pops entire call frame, returning SP to end of the driver stack frame
lda -2,s;//pulls the return value from above the SP where the procedure stored it
;//;;;;;;;;;;;;;;;End call for Multiply
sta MProduct,s; stores the return in a local for later use
charo '\n',i
deco Mnum1,s
charo '*',i
deco Mnum2,s
charo '=',i
deco MProduct,s
addsp MDvars,i
STOP
.end
;//--- --- --Multiply() end--- ---;

Comment by siev...@wells.edu, Nov 05, 2008

If anyone but you uses it, your locals "should" conform to our differential naming code, but since nobody's last name begins with M I guess you're ok.


Sign in to add a comment
Hosted by Google Code