Table for branch instructions



High Level Assembler(HLASM) for MVS & VM & VSE

Table for branch instructions

Postby michel123 » Wed Nov 16, 2011 3:40 pm

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?
michel123
 
Posts: 58
Joined: Tue Dec 28, 2010 12:28 am
Has thanked: 0 time
Been thanked: 0 time

Re: Table for branch instructions

 

Re: Table for branch instructions

Postby enrico-sorichetti » Wed Nov 16, 2011 4:10 pm

when defining something as A constant You can carry on address computation on the value to be assigned
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2644
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 130 times

Re: Table for branch instructions

Postby michel123 » Wed Nov 16, 2011 4:26 pm

Hello, I do not really understand your answer. Excuse me, I'm French and speaks very little English.

Do you have an example?
michel123
 
Posts: 58
Joined: Tue Dec 28, 2010 12:28 am
Has thanked: 0 time
Been thanked: 0 time

Re: Table for branch instructions

Postby Ronald Burr » Wed Nov 16, 2011 8:15 pm

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.
Ronald Burr
 
Posts: 7
Joined: Wed Mar 23, 2011 8:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Table for branch instructions

Postby steve-myers » Wed Nov 16, 2011 9:41 pm

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.
steve-myers
Global moderator
 
Posts: 1886
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 197 times

Re: Table for branch instructions

Postby michel123 » Thu Nov 17, 2011 8:16 pm

Well, I think I understand. Thank you for the examples.
michel123
 
Posts: 58
Joined: Tue Dec 28, 2010 12:28 am
Has thanked: 0 time
Been thanked: 0 time


Return to Assembler

 


  • Related topics
    Replies
    Views
    Last post