.data add_scr: .space 1 # scratch memory used by add macro scr: .space 1 # scratch used by caller .text ... add retproto, retaddr, multret, add_scr subz scr,scr,mult # unconditional jump to mult retaddr: ... # code that follows the call to mult retproto: subz scr,scr,0 # not executed directly mult: # start of subroutine -- your multiplication code goes here. ... ... multret: .space 1 # one word of space to hold return instructionHere, I am assuming that we have a macro assembler that will assemble the following macro:
add: .macro a,b,c,scr subz scr,scr, next # scr = 0 subz scr,a, next # scr = scr - a = -a subz scr,b, next # scr = scr - b = -a-b subz c,c, next # c = 0 subz c,scr, next # c = c - scr = -(-a-b) = a+b .endmacrowhich translates the function call example code above into
.data add_scr .space 1 # scratch memory used by add macro .text ... subz add_scr,addr_scr, next subz addr_scr,retproto, next subz add_scr,retaddr, next subz multret,multret, next subz multret,addr_scr, next subz scr,scr,mult # unconditional jump to mult retaddr: ... # code that follows the call to mult retproto: subz scr,scr,0 # not executed directly mult: # start of subroutine -- your multiplication code goes here. ... ... multret: .space 1 # one word of space to hold return instruction
bsy@cse.ucsd.edu, last updated