[A83] Re: Stuff


[Prev][Next][Index][Thread]

[A83] Re: Stuff




> The $ represents the current byte.  This can be useful in many situations
to
> avoid a call for one command.  For instance, you want to inc a variable
until
> it is 5, and then reset it to 0.  It can be done like so:

That was a short and simple answer, but I'd like to clarify it a bit.  It is
commonly said to be the instruction pointer, or the program counter, at the
start of that instruction, if used in an instruction (assuming the code is
absolute and run from the location for which it was assembled).  TASM
handles certain aspects differently than Assembly Studio 8x, and ZDS is
likely different as well.  Personally, I think Assembly Studio 8x's method
is easier to understand and cleaner.

The .org directive sets the value of the instruction pointer.  This is done
at the start of every program:

.org _asm_exec_ram

If you put a label immediately following that, then it would be equal to the
value of _asm_exec_ram.  Labels and $ are very simliar.  In fact, the
following two lines are equal:

Label:
Label = $

In Assembly Studio 8x, the .pad directive will set a new instruction
pointer, but pad the output with 0's until the instruction pointer is equal
to the address given.  In TASM, .org is equivalent to Assembly Studio 8x's
.pad.  .org merely changes the instruction pointer:

.org 0
Zero = $
.org 100
OneHundred = $

The example given for the use of $ was a bit pointless, because it is just
as easy to use a label in that situation (the desired address is not in the
middle of an instruction).  A much more common use is for self modifying
code.

 ld (Modify+1),100  ; change the value to be loaded into HL
 ld (BetterModify),200  ; calculation is done at modification point

Modify:
 ld hl,0
BetterModify =$-2    ; ld hl,nnnn is 3 bytes, value to change is 2 bytes
back






References: