Fw: More ???s

steve ravet Steve.Ravet at arm.com
Mon May 31 21:59:36 GMT 1999



Bruce Plecan wrote:
> 
> 9500 would mean to start something new, by jumping to a subroutine?.

Yes.  JSR is an instruction that branches and also stores a return
address.  The address of the instruction following the JSR is pushed
onto the stack, then the instruction branches.  That way when the
subroutine executes the "RTS" instruction (return from subroutine) it
doesn't have to know "where" to go back to, it just gets the return
address off the stack and goes there.

> 
> The value at L01E6  "load to accumulator A"  means to place it at a location
> for further use.

That means bring it into the CPU for immediate use.  variables sit out
in RAM all the time, waiting to be used.  The CPU reads them into a
register when it needs them for a calculation.

I came up with this analogy yesterday.  Memory (RAM or ROM) is like your
toolbox, and CPU registers are like your hands.  You have a box full of
tools just waiting to be used.  You may use a bunch during the day but
only 1 or 2 at a time.  If you had 100 hands you could hold all the
tools you need but since you only have 2 you have to hold only the tools
you need right now.  When you're done with one you set it down and pick
up another.

Registers in the CPU are also limited, like 3 16 bit registers. 
Literally hundreds of thousands out in memory though.  So values sit
around in memory, waiting to be read in by the CPU to be used in a
calculation.

> 
> Now when it says to compare to memory what is that?.....

That's a misleading comment, first off.  The # sign is actually
important.  If a number has a pound sign in front of it, it means "use
this value".  That's obvious enough.  If there's no pound sign (#) in
front of a number it means "read this memory location and use the value
there".  As an example:

		cmpaa	#0x28
		cmpaa	0x28

The first instruction means "compare the value in register a to the
value 0x28".
The second instruction means "compare the value in register a to the
value stored at memory location 0x28".  Big difference.

6811 (and all other microprocessors) have what's called a condition code
register.  There are several bits there that are set after most
instructions.  One bit indicates if the result was a zero.  Another
indicates positive/negative.  Others indicate if the result of an
addition was too big to fit in the register (ie add 0xf0 and 0xf0 and
the result is 0x1e0, which is too big to fit into an 8 bit register). 
And so on.  Actually that's not a very good description of how the
hardware really works but it gets the idea across.

So the compare instruction "compares" the two values (subtracts them,
actually).  The result of the subtract is thrown away and only the
condition codes are left.  The next instruction after a compare is
almost always a conditional branch.  A conditional branch checks the
condition codes and branches (jumps to a new location) if the condition
codes matches what the instruction specifies.

BCS means "branch if carry set".  The "carry" bit is one of the
condition codes.  Look at the manual that  I posted before, on page
A-14, or any 6811 manual with instruction set details, on the page that
talks about "BCC".  You'll see a chart at the bottom of the table that
translates "condition codes" into real life.  BCS doubles as an
instruction "BLO" which means "branch if the register value is lower is
lower than the compared value".  Your code sequence, starting at ldaa,
loads a value from memory into the A register.  It then compares it to
0x28.  It then branches to another location if A was less than 0x28,
otherwise it falls though and executes the "adda" instruction.

Print that table out, it's handy to have when looking at disassembled
conditional branches so you can figure out what they're testing for.

> 
> Branch set carry?.
> 
> Add memory to A.
> 
> Knowing what is stored at  L01E6, ie a timing value would be a clue about
> what is being looked at?.

I can't tell what is being done here but someone who's stared at more
code than I have might be able to tell.  L01e6 is a timing value?  It
reads it in, compares it to 0x28, jumps somewhere else if it's less, and
adds 0x9c if it's greater or equal, then returns.  Might help to look at
what the code does if the value is "less than".  Also the first
subroutine, at ld776 might have some clues.

> 
> | 9500    L9500:  jsr     LD776        Jump to subroutine
> | 9503            ldaa    L01E6            Load Accumulator A
> | 9506            cmpa    #0x28           Compare A to memory
> | 9508            bcs     L950C            Branch if carry set
> | 950A            adda    #0x9C          Add memory to A
> | 950C    L950C:  rts                       Return from Subroutine
> 
> Grumpier
> | 950D    L950D:  lds     #0x02FF  Load Stack Pointer

--steve


-- 
Steve Ravet
steve.ravet at arm.com
Advanced Risc Machines, Inc.
www.arm.com



More information about the Gmecm mailing list