A89: Re: compilers


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

A89: Re: compilers




 > That brings me to a VERY important question... how come I cannot read or
 > write from numerical address in as92? If I tell it:
 > 
 > [...]
 > 
 > Including every single variaion of #'s and parenthesis I can think of (such

Well, the syntax of assembly languages is usually strictly specified 
and thus random combination of syntactical elements will not result 
valid code too often. 

The # sign in Motorola assembly is a sign of an immediate operand,
that is, one which is encoded within the instruction rather than which 
the address is given/calculated.

In the light of the above

  move #1,#2
  
means "let two be equal to one" while 

  move #1,2
  
means "let the memory word at address 2 be equal to one", and

  move 4,2
  
means "let the memory word at address two be equal to the content of
the memory word at address four". 

The paren around an expression usually means indirection, that is, you 
refer the content of memory at address <expression> rather than the
value of the <expression> itself. For example
 
  move a1,(a2)
  
means "move the content of a1 to the memory at address of the content
of a2". In this regard the proper syntactical form for absolute
addresses would be

  move (2),(4)
  
However, since when you want 2 be interpreted as a literal constant
you have to put the # in front of it the assembler can decide that you 
mean indirection just by the lack of the hashmark. This renders the
paren around absolute addresses superfluous and the assembler allows
you to omit them:

  move 2,4
  move (2),4
  move 2,(4)
  move (2),(4)
  
all mean the same. This, however, is only true for absolute addresses,

  move a1,a2
  move a1,(a2)
  move (a1),a2
  move (a1),(a2)
  
mean four very different things.

It should be further noted that on some members of the m68k processor 
family have double indirect, inidirect indexed, indexed indirect
and similar addressing modes which involve even more parens thus
random parenthesis placement is even more dangerous than with a
vanilla 68000.

Some assemblers, notably the GNU assembler accepts the so-called MIT
syntax which resembles the PDP-11 syntax. Parens are not used in that, 
instead, indirection is expressed by the use of the @ symbols, that is

  move.l (a2),a1
  
would be

  movel a2@,a1
  
Other GNU tools such as objdump or gdb use that too and therefore
understanding it is rather useful if one uses the GNU tools (such 
as TI-GCC).

Finally, a non-technical note. In situations like this reading manuals 
and textbooks has been many times proven helpful. So much so that there
even is an abbreviation for that: RTFM stands for "You should consult 
your books first !" or something like that :-)

Regards,

Zoltan


References: