From: koning@koning.enet.dec.com (Paul Koning)
Newsgroups: comp.os.misc,comp.os.rsts,vmsnet.pdp-11
Subject: Re: Help on RT-11 macro language
Keywords: RT-11, macro
Date: 6 Jan 93 20:27:16 GMT
Reply-To: koning@koning.enet.dec.com
Organization: Digital Equipment Co., distributed systems architecture


In article <id.U6GW.CIK@ferranti.com>, peter@ferranti.com (peter da silva) writes:
|>In article <93Jan04.223305.29354@acs.ucalgary.ca> morrow@cns.ucalgary.ca (Bill Morrow) writes:
|>> I'm a bit confused by the unconditional branch instruction -
|>> where does this code end up after the 'BR 10$+2' step?
|>
|>All of the following assumes I'm not psychotic:
|>
|>Two bytes after the label marked "10$".
|>
|>Assume .=1000 (octal)
|>
|>Address	Data		  Code
|>1000	0		> DR3INT: 0
|>1002	<branch>	> 	BR	10$+2		<--- branch to where ?
|>1004	<branch>	> 	BR	20$+2
|>1006	<mov>		> 10$:	MOV	#107,DMACSR
|>	107
|>	DMACSR
|>1014	<tst>		> 	TST	ADCO		<--- here ?
|>	ADCO
|>1020	<branch>	> 	BEQ	11$
|>1022	<mov>		> 	MOV	#113,KWREG
|>	113
|>	KWREG
|>1030	<mov>		> 11$:	MOV	DR3INT+4,DR3INT
|>	DR3INT+4
|>	DR3INT
|>1036			> 	TR			<--- or here ?
|>			> 12$:    et cetera ad nauseum
|>
|>Since the MOV is a three-word instruction, it's branching into the middle
|>of the move instruction. Are you sure this isn't some sort of table being
|>interpreted as code?
|>
|>> My intuitive guess is that it ends up at 'TST ADCO',
|>> but the manual seems to be telling me it branches to
|>> the indicated address.
|>
|>I don't see how.
|>
|>> While you're here, does the 'MOV' instruction at 11$ really move
|>> the label 'DR3INT' to the same address as 10$?
|>
|>No, it moves the BR 20$+1 *instruction* to DR3INT. DEC's assemblers all
|>use "MOV <src>,<dst>".
|>
|>> What does 'TR' do? I can't find it in the instruction set
|>> or the macro language reference manual.
|>
|>I don't know offhand. Maybe a macro.
|>-- 
|>Peter da Silva                                            `-_-'
|>Ferranti International Controls Corporation                'U` 
|>Sugar Land, TX  77487-5012 USA
|>+1 713 274 5180                            "Zure otsoa besarkatu al duzu gaur?"
|>

Ye gods!

My first recommendation is to find out who programmed this and ask them
to sin no more. 

Apart from that... several points.

1. MOV x,y means move the CONTENT of x to y.  To move the value x, you'd
   write MOV #x,y. 

2. Assembly-time arithmetic: the assembler replaces each symbol by its value,
   and performs the arithmetic on the values.  Symbol "10$" has the value
   1006, so "10$+2" equals 1010.  Note this is arithmetic, not symbol
   manipulation or line number referencing, so "10$+2" does not mean either
   of the things you thought it might.

3. A Branch uses relative addressing (the instruction encoding actually
   contains the delta to the PC).  So the branch that the MOV at 11$
   moved into DR3INT is NOT a branch to 20$+2 when executed at DR3INT.
   Instead, it would be a branch to 20$-2, since it lives at an address 4 less
   than where it was assembled.

Conclusion:

a. The BR 10$+2 makes some sense if it's going to be moved into DR3INT, because
   then it becomes a BR 10$.

b. The BR 20$+2 makes no sense, since moving it to DR3INT makes it a BR 20$-2.
   If it had been a BR 20$+4, it would make sense (after moving it, it is
   a BR 20$).

c. If at all possible, you should throw out this code and rewrite it.

	paul
!-----------------------------------------------------------------------
! Paul Koning, NI1D, A-13683
! Digital Equipment Co., LKG1-2/A19, Littleton, MA 01460, USA
! (508) 486-7313 or (508) 952-3344, koning@koning.enet.dec.com
!-----------------------------------------------------------------------
! "The only purpose for which power can be rightfully exercised over 
!  any member of a civilized community, against his will, is to prevent
!  harm to others.  His own good, either physical or moral, is not
!  a sufficient warrant."    -- John Stuart Mill, "On Liberty" 1859
Newsgroups: comp.os.misc,comp.os.vms,comp.os.rsts,vmsnet.pdp-11