;;----------------------------------------- ;;-- testLink-1.asm ;;-- Below, "EXTERNAL foo," signals to a linker that "foo" is in another file. ;;-- .obj files need symbol tables to keep track of these references. ;;-- We use the trick of having our non-local address memory at run time, ;;-- and jumping via register. Linker would fill in the ".FILL" with the address ;;-- needed when it was combining this code with "external" code. We don't have ;;-- a linker; so, we will have to do our linking by hand. The value can be ;;-- filled in by editing the .obj file, which is how the linker would do it. ;;-- Instead, we will edit the source code by hand. ;;----------------------------------------- ;;-- EXTERNAL foo .ORIG x0200 br next foo: .FILL x0000 ;;-- address to jump to, we fix this by hand. next: ld r4, foo jsrr r4 ;;-- The only problem with this is it uses absolute addresses, making ;;-- our code non-relocatable. Alternatively, we could use PC-relative ;;-- addressing, replacing the above code with this: jsr bar ;;-- address to jump to, linker should fix this. ;;-- That line will not assemble: the symbol "bar" would be undefined. ;;-- "EXTERNAL bar" would tell the assembler that "bar" is ;;-- in another file, and to put "bar" in the symbol table with ;;-- dummy value flag it to be fixed up by the linker. The linker ;;-- fixes the offset of the jsr instruction. We can fake this: ;;-- put "bar" at the end of this file, and again, do hand linking. ;;-- The problem with the jsr instruction is the limited range of ;;-- the 11-bit offset (+ or - 1024). The same is true for ;;-- the other PC-relative mode (LD, LDI, ST, STI, BR, LEA), which ;;-- are restrive (9-bit offset: + or - 256). Except for LEA, these all ;;-- have register-indirect versions (LDR, STR, JMP), and the above ;;-- can be used. We could do the halt bar: .FILL 0000 ;;--EXTERNAL (We would remove this when linking by hand.) .END