Page 1 of 1

Table for branch instructions

PostPosted: Wed Nov 16, 2011 3:40 pm
by michel123
Hello,

I found on the Internet is an example of branch table, and I asked about the DC.

Depending on the type of treatment it plugs into a label specifies using two tables.

A table for the connection:
TABLE1 EQU * ---Start of Branch table---
B ERROR 00 = Invalid input value
B ADD 04 = Input value was "A"
B SUBTRACT 08 = Input value was "S"
B MULTIPLY 12 = Input value was "M"
* ---End of Branch table
ERROR EQU *
* print or display error message or similar
ADD EQU *
* perform addition and continue with rest of program
B NEXT
SUBTRACT EQU *
* etc
INPUT DS C The input character is in this byte.

A table for indexing according to the code :
TABLE2 DC Al1(00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00) X'00'-X'10'
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00) ...
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,00,00,00,00,00,00,00,00,00)00,00,00,00,00,00)
DC Al1(00,04,00,00,16,00,00,00,00,00,00)00,00,12,00,00) x'C0' - X'CF' (04 is at offset X'c1')
* etc

My question :
Why define this second table with DC AL1 rather than DC XL1?
What is the advantage of using a constant address?

Re: Table for branch instructions

PostPosted: Wed Nov 16, 2011 4:10 pm
by enrico-sorichetti
when defining something as A constant You can carry on address computation on the value to be assigned

Re: Table for branch instructions

PostPosted: Wed Nov 16, 2011 4:26 pm
by michel123
Hello, I do not really understand your answer. Excuse me, I'm French and speaks very little English.

Do you have an example?

Re: Table for branch instructions

PostPosted: Wed Nov 16, 2011 8:15 pm
by Ronald Burr
michel123 wrote:
Why define this second table with DC AL1 rather than DC XL1?
What is the advantage of using a constant address?

a) No reason other than personal preference, though it is perhaps more "intuitive" for the reader
to see "normal" numeric values (e.g. AL1(12)) in TABLE2 rather than the actual hexadecimal values (e.g. X'0C').
b) In this simple exercise there is no advantage that I can see, it would have been just as simple, and just as efficient
to use a series of CLI/BE instructions (e.g.
        CLI INPUT,C'A'
        BE  ADD
        CLI INPUT,C'S'
        BE  SUBTRACT
        CLI INPUT,C'M'
        BE  MULTIPLY
        B   ERROR

However, this example was only meant to highlight the use of a branch table,
not necessarily the use of TABLE2 to set the branch table offset. In the real world, the branch table offset
could have been set by a rather complex subroutine that performed dozens of tests to determine the offset.

For what it's worth, I would have coded TABLE2 as either

TABLE2  DC  193AL1(0)
        DC  AL1(4)        Branch offset for the letter 'A'
        DC  2AL1(0)
        DC  AL1(16)       Branch offset for the letter 'M'
        DC  8AL1(0)
        DC  AL1(12)       Branch offset for the letter 'S'
        DC  50AL1(0)

or as

TABLE2  DC  193X'00'
        DC  X'04'         Branch offset for the letter 'A' (4)
        DC  2X'00'
        DC  X'10'         Branch offset for the letter 'M' (16)
        DC  8X'00'
        DC  X'0C'         Branch offset for the letter 'S' (12)
        DC  50X'00'

as I think that it would be clearer and more readily understood.

Re: Table for branch instructions

PostPosted: Wed Nov 16, 2011 9:41 pm
by steve-myers
Three reasons.
  • Personal preference
  • You can do arithmetic in the entries. For example -
             PRINT DATA
    TABLE    DC    (C' ')C'.',AL1(*-TABLE)
             DC    (256-(*-TABLE))C'.'
             ORG   TABLE+C'A'
             DC    9AL1(*-TABLE)
             ORG   TABLE+C'J'
             DC    9AL1(*-TABLE)
             ORG   TABLE+C'S'
             DC    8AL1(*-TABLE)
             ORG   TABLE+C'0'
             DC    10AL1(*-TABLE)
             ORG   ,
    (Run the preceding code through the Assembler. The first two lines in TABLE are often combined into one line.)
  • You can express values as decimal numbers rather than hexadecimal values.

Re: Table for branch instructions

PostPosted: Thu Nov 17, 2011 8:16 pm
by michel123
Well, I think I understand. Thank you for the examples.