Main | Assembly Programming | Input/Output | Memory | Computer Architecture | Advanced Topics |
Depending on an index sent by an outside device we want to be able to call one of ten subroutines in our 68000 program. For 0 sent we call Sub0, for 1 sent we call Sub1, …, for 9 sent we call Sub9.
The subroutine addresses are in a table of longwords, SubAdrs. The index value is passed to our code in d0. Write the code that uses table SubAdrs to make the call to the correct subroutine using only one JSR instruction. State any other assumptions you need.
Look up JSR in Appendix C, in particular the variety of addressing modes available.
movea.l #SubAdrs,a0 ;a0 points to the table asl.l #2,d0 ;change index to a longword offset movea.l 0(a0,d0),a0 ;get tabled value to a0 jsr (a0) ;go to routine [note that jsr uses the effective address]