------------------------- Week 11 Notes for DAT2343 ------------------------- -Ian! D. Allen - idallen@idallen.ca - www.idallen.com Quiz Question ------------- Write an LMC subroutine "MOD" (modulus) that takes two arguments and returns the remainder of the first argument divided by the second, e.g. rem = MOD(7,1) ; rem <- 0 rem = MOD(7,2) ; rem <- 1 rem = MOD(7,3) ; rem <- 1 rem = MOD(7,4) ; rem <- 3 rem = MOD(7,5) ; rem <- 2 rem = MOD(7,6) ; rem <- 1 rem = MOD(7,7) ; rem <- 0 Topics ------ 370_LMC_link.html Generation of Executable Code from Source Program Files 373_LMC_object_file_format.txt External "Object" Files and Libraries 300_real_compile_link.txt Real-World Compile, Assemble, and Link Example 350_LMC_sample6.txt negative flag and a FOR loop 350_LMC_sample7.txt subroutine call/return and linkage ; Mod subroutine ; rem = mod(arg) ; ARG - input argument ; returns 2-modulus (remainder) of the argument, i.e. arg%2 ARG DAT ; input argument must be stored here first RETURN DAT ; space for CALL return value MOD LDA ARG ; arg -= 2 SUB TWO STO ARG SKP ; skip and go to top of loop if arg >= 2 JMP DONE ; done if arg < 2 JMP MOD DONE LDA ARG ; arg += 2 ADD TWO JMP RETURN TWO DAT 002 ; constant -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/