Mon, 9th Nov 2015, 01:57 Re: programming subroutines in the LC-3 Editor

A student writes:

> Dr. Patt,
> I understand how subroutines work however I'm a bit confused as to how to
> actually write a subroutine in the LC-3 editor. For Lab 3 in particular,
> how would we write code that should begin at a different location other
> than x3000 (PUSH subroutine). I understand that the .ORIG pseudo-op sets
> the memory address of the first line of code, but how would we set the
> memory address to a different location in order to write locations
> beginning at that memory location?
> <name withheld to protect the student who wants to know how to load his code>

Good question!  You need your code to start at x3000 and you need subroutines
to start at other locations.  The simple solution, making sure that there is
no overlap between your main program and any of the subroutines is to simply
assemble each piece of code, starting with .ORIG <<location>>, where
<<location>> is where you want that piece of code to reside in memory.
Then load each of the .obj files, making sure that the last .obj file
you load into memory is your main program (which starts at x3000),
so the Simulator will load PC with x3000 before you hit "Run."

Do you see why you need to make sure there is no overlap?

Yale Patt