[Coco] Assembler Program - Working!

William Astle lost at l-w.ca
Sun Aug 17 12:56:58 EDT 2008


Charles Shrader wrote:
> What helped were adding a # sign in front of my memory location STMP.
> How does the compiler treat a CMP function of a memory location if it
> has a # designation rather than just the memory location without?

Probably what you need to understand the difference is to look up the 
difference between immediate mode addressing and direct/extended addressing.

Suppose you have the following:

	LDA #5

That puts the value of 5 into A. That's pretty obvious. Now suppose you 
have the following:

	LDA 5

That would take the value at memory location 5 and put it into A. The 
first is immediate mode addressing which the second is either direct 
addressing or extended addressing. Which it is is not important as they 
have the same effect.

It seems to get a bit more confusing for people when symbols are 
involved. In the assembler, a symbol is simply a name for a value. 
Consider the following:

	....
	RTS
STMP	RMB 8

In the above, STMP gets assigned the current assembly address. There is 
nothing magic about symbols. The assembler doesn't treat them any 
differently than simple numbers and it certainly doesn't treat them 
differently based on how they are defined. So, if you need the value of 
a symbol, you use immediate mode (# prefix). If you need the contents of 
the memory location identified by the symbol, you leave off the # prefix.

Thus, you could have done something like this:

ODEV	EQU	0
DEVNUM	EQU 	$6F
	....
	LDA #ODEV
	STA DEVNUM

Now, the distinction between immediate mode and direct/extended mode 
applies to LD, SUB, SBC, ADD, ADC, BIT, AND, OR, EOR, and CMP. It means 
exactly the same in all cases. Immediate mode includes the value to be 
operated on in the instruction (it's immediately available) while direct 
or extended mode include a pointer to the value to be operated on in the 
instruction.

> I may need some more help in the future so don't be surprised if I
> surface again...  Assembler can be quite tricky.  Critique is also welcome!

We have a few folks around these parts that know a few things about 
assembly. :)

-- 
William Astle
finger lost at l-w.ca for further information

Geek Code V3.12: GCS/M/S d- s+:+ !a C++ UL++++$ P++ L+++ !E W++ !N w---
!D !M PS PE V-- Y+ PGP t+@ 5++ X !R tv+@ b+++@ !DI D? G e++ h+ y?



More information about the Coco mailing list