10/25/2006


A student writes:

        Hey Dr. Patt,

Hey, Mr. Student,

        In class yesterday you talked about how you can place labels on certain
        lines of code while writing in assembly so you could use the labels
        instead of the offset to "jump" to the labeled location.  

Absolutely.  So, if you wrote LD R2,HERE, you are telling the computer to
take the contents of the memory location labeled HERE and load it into R2,
...provided the distance between the LD instruction and the location HERE
can be represented in bits[8:0] of the instruction.  I thought that this was
made clear in class and in the book (Chapter 5), but perhaps not.  Have you
read it in the book?  

        This may sound stupid, 

It does not.

        but let's say I use the LD command and try to load the contents
        of memory from an address labeled "done." Since the offset in machine
        language is only 9 bits, what if the address labeled "done" is farther
        than the offset can reach? 

It can't be done with the LD instruction because of the reasons you have
already stated.

        It's hard to explain what I'm trying to get
        at, but should I pretend that it's in machine language and maybe use a

I do not understand the reference to pretending it's in machine language,
but I will move on.

        different command so I can reach the "done" address (such as the LDR
        command) 

Aha!  Yes, if you want to load from far away, LDR is a good way to do it,
since the BaseReg contains 16 bits -- the full extent of the memory address
space.

        or does the assembler go to it, regardless of how far it is
        from the LD command (ignoring the offset)? I would think that the
        assembler works the same way as the machine language and would not be
        able to reach it, but I wasn't sure.

The assembler's job is translate assembly language instructions into machine
language instructions.  If the assembler can not do this, as is the case here,
it barfs.  What barf means in this context depends on who wrote the assembler.
In any case, it can't translate the instruction as you point out.  It may
provide a message to the programmer to help him/her find the bug.

So, now I will give you another one: What does the assembler do when it
encounters this assembly language instruction:  ADD R2,R3,#97

Good luck finishing the program by Thursday night.
Yale Patt

        Thanks,
        <<name withheld to protect one who mistakenly thinks he sounds stupid>>