# what does this assembler code do

Author Message
rammraju

New User

Joined: 05 Mar 2005
Posts: 65

Posted: Tue Oct 09, 2007 12:09 am

Hi,
can anyone please let me know what is happening in the following part of code. I am not finding the explanation for these instructions anywhere.

 Code: EXAMPLE1  START                  STM       14,12,12(13)                  LR        3,15                  USING     EXAMPLE1,3                  L         4,0(1)                  L         5,4(1)                  MVC       0(8,5),=C'11111111' LBL1             TM        0(4),C'AB'                  BO        LBL2                  MVI       0(5),C' ' LBL2             TM        0(4),C'CD'                  BO        LBL3                  MVI       1(5),C' ' LBL3             LM        14,12,12(13)                  BR        14                  LTORG                  CSECT                  DC        CL24'@@@001EXAMPLE2  11/11/11'                  END       EXAMPLE1

It would be helpful if i can get to know what is happening in each step.
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19245
Location: Inside the Matrix

 Posted: Tue Oct 09, 2007 3:04 am Hello, The assembler instructions in the posted code are among the most basic in the language. If these are not yet familiar to you, i'd suggest you do a bit more research. The first link shows a list of most assembler instructions. The second is to an IBM Introduction for Assembler. http://www.simotime.com/asmins01.htm http://ulita.ms.mff.cuni.cz/pub/predn/swi119/AssemblerIBM_390.pdf
CICS Guy

Senior Member

Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

Posted: Tue Oct 09, 2007 5:03 am

 rammraju wrote: It would be helpful if i can get to know what is happening in each step.

What's 'a matter Dick, couldn't you just try to answer the question?
 Code: EXAMPLE1  START                  STM       14,12,12(13)                  LR        3,15                  USING     EXAMPLE1,3 set up a base reg                  L         4,0(1) get the first parm                  L         5,4(1) get the second parm                  MVC       0(8,5),=C'11111111' Move X'FF' to the second parm LBL1             TM        0(4),C'AB' Eww, that's one I gotta look up....Testing the first byte of a passed parm with what should be an immeadiate, but is actually an addtess of X'C1C2' off of zero.....Or do I have it backward....grin.... Beyond this, I'm needing my POP and green card.....                  BO        LBL2                  MVI       0(5),C' ' LBL2             TM        0(4),C'CD'                  BO        LBL3                  MVI       1(5),C' ' LBL3             LM        14,12,12(13)                  BR        14                  LTORG                  CSECT                  DC        CL24'@@@001EXAMPLE2  11/11/11'                  END       EXAMPLE1
ApexNC

New User

Joined: 10 Feb 2006
Posts: 19
Location: USA

Posted: Fri Jan 04, 2019 5:01 pm

 dick scherrer wrote: [... The first link shows ...] The second is to an IBM Introduction for Assembler. [...] http://ulita.ms.mff.cuni.cz/pub/predn/swi119/AssemblerIBM_390.pdf

"OS/390 Assembler Programming Introduction" is no longer at the URL given above, but can still be found on archive.org, here:
web.archive.org/web/20070613131443/http://ulita.ms.mff.cuni.cz/pub/predn/swi119/AssemblerIBM_390.pdf
Garry Carroll

Senior Member

Joined: 08 May 2006
Posts: 1111
Location: Dublin, Ireland

Posted: Fri Jan 04, 2019 5:29 pm

 Quote: MVC 0(8,5),=C'11111111' Move X'FF' to the second parm LBL1 TM 0(4),C'AB' Eww, that's one I gotta look up....Testing the first byte of a passed parm with what should be an immeadiate, but is actually an addtess of X'C1C2' off of zero.....Or do I have it backward....grin.... Beyond this, I'm needing my POP and green card..... BO LBL2

Not moving X'FF' to second parm - overwriting the first 8 bytes of the parm with char '1'.

The TM is a single byte instruction to check an immediate mask, so only tests for bits b'11000001' (first byte of immediate C'AB') - any value with these bits 'on' will result in branch to LBL2.

Garry
Rohit Umarjikar

Global Moderator

Joined: 21 Sep 2010
Posts: 2772
Location: NYC,USA

 Posted: Sat Jan 05, 2019 1:55 am ApexNC, I don’t see a pdf in the link posted by you. However why are we discussing 12 years old post now ? If you would like to share any manuals related stuff then it’s best to share to any of the moderator so that it can be marked with sticky key. E.g ibmmainframes.com/viewtopic.php?t=2744
sergeyken
Warnings : 2

Senior Member

Joined: 29 Apr 2008
Posts: 1188

Posted: Sat Jan 05, 2019 8:24 am

The instruction
 Code: TM 0(4),C'AB'
doesn't make any sense, at all. The second operand must represent any value from the range 0-255 (that fits to one byte); The value C'AB' is a different entity.
Correct syntax might be
 Code: TM 0(4),X'AB'
but the subsequent logic remains unclear.
I also expect Assembly error at compilation, but I'm lazy to verify this senseless example.

After this point no need to further analyze this "example".
steve-myers

Active Member

Joined: 30 Nov 2013
Posts: 891
Location: The Universe

Posted: Sat Jan 05, 2019 2:20 pm

1. There are a couple of Assembler errors in this "example."
 Code: 000014 0000 0000      00000           8 LBL1             TM        0(4),C'AB' ASMA031E Invalid immediate or mask field ASMA435I Record 8 in XXXXXX.X1.ASM on volume: XXXXXX 000020 0000 0000      00000          11 LBL2             TM        0(4),C'CD' ASMA031E Invalid immediate or mask field ASMA435I Record 11 in XXXXXX.X1.ASM on volume: XXXXXX Assembler Done      2 Statements Flagged /   8 was Highest Severity Code
An instruction like TM can specify one byte of data within the instruction. Perhaps, instead of C'AB', X'AB' was intended. Other "immediate" instructions can have two or even four bytes of data embedded in the instruction.
2. START, CSECT, USING, LTORG, END - System/360 Assembler programs - the programs that analyze user assembler programs to build the binary code the machines eventually execute - have a number of "Assembler instructions" that direct the Assembler to do something rather than emit binary code. START, CSECT, USING, LTORG and END are all Assembler instructions. These "instructions" are sometimes called pseudo ops.
3. START and CSECT are similar, though the difference between them is very subtle. Both instructions define a CSECT, or "control section." A CSECT is just a block of data, which can be a program, or data, that must be kept together. One "assembly," the data from one run of the Assembler program, can have several CSECTs in the assembly. The Binder - in z/OS the program that takes the binary data produced by the Assembler to produce a loadable, executable program - combines the CSECTs. The CSECT without a label defines a CSECT with no name. Sadly, this is perfectly legal; in fact, a load module can have several unnamed CSECTS.
4. USING - Many instructions have to access storage. Rather than specify a storage address directly in an instruction, A storage address is specified in an instruction as a base register and an value that is added to the contents the vase register. A programmer can specify these values directly -- 12(13), where the base register is register 13, and 12 is the value added to the base register. It's often more convenient to specify a symbolic label, for example LBL3 in "BO LBL3" and request the Assembler program to calculate the base register and offset.
 Code: Loc  Object Code    Addr1 Addr2  Stmt   Source Statement 000024 4710 302C            0002C    12                  BO        LBL3
The address in the machine instruction is 302C; the base register is register 3 and the offset is 02C. As a convenience to the programmer, the Assembler computes the relative location of the address and stores it in the Addr1 and Addr2 columns.
5. LTORG - As a convenience to the programmer, the Assembler provides the programmer a way to specify fixed data as an inline literal in the form (for example) =C'11111111' The Assembler will normally store these literals some place.

The default location may not be acceptable, so the LTORG Assembler instruction can be used to select the location of the literal pool. Large programs often have several literal pools.
6. END - As Homer Simpson often says, "Duh!" This one is pretty obvious. You can specify an address on the END statement. This address can be conveyed to the Binder as the location where the program will start executing. Hint: specify an address that is also an external symbol.
An external symbol is the label in a CSECT or START statement. There are other ways to create an external symbol which will not be discussed in this post.
What actually happens when the program executes can not be determined since there are known Assembler errors.

Our late colleague Dick Scherrer commented more than 11 years ago that the computer instructions in this "example" are very basic. People like CICS guy should do more research. If they still do not understand something they should post the piece they do not understand and someone should be able to help them.
sergeyken
Warnings : 2

Senior Member

Joined: 29 Apr 2008
Posts: 1188

Posted: Mon Jan 07, 2019 9:43 am

This code is supposed to be called as
 Code: . . . . . . . . . . . . . .          CALL  EXAMPLE1,(STRING,FLAGS) . . . . . . . . . . . . . . STRING   DC    CL8'????????'    output string field FLAGS    DC    B'xxxxxxxx'      input flags . . . . . . . . . . . . . .

 Code: EXAMPLE1  START ,           create Control Section named EXAMPLE1           STM       14,12,12(13)    save registers on input           LR        3,15               copy entry point address           USING     EXAMPLE1,3  let use R3 as program base reg           L         4,0(1)        get address of output STRING           L         5,4(1)        get address of input FLAGS           MVC       0(8,5),=C'11111111'     initialize STRING with '11111111' LBL1      TM        0(4),C'AB'     error! trying to check something in FLAGS; must be (5)           BO        LBL2               if checked condition OK, bypass to LBL2           MVI       0(5),C' '         if check failed, replace FLAGS(?) with B'01000000' LBL2      TM        0(4),C'CD'   error! trying to check something in FLAGS; must be (5)           BO        LBL3              if checked condition OK, bypass to LBL3           MVI       1(5),C' '        if check failed, then FULL MESS!! LBL3      LM        14,12,12(13)   restore registers to initial state           BR        14                return to caller           LTORG   ,             define place for literals (=C'11111111')           CSECT   ,             define unnamed Control Section (for nothing!)           DC        CL24'@@@001EXAMPLE2  11/11/11' place eye catcher to read the dump if needed           END       EXAMPLE1      end of code; set entry point to EXAMPLE1

Two lines marked with error! demonstrated for sure that the code developer had not a minor idea about Assembler basics in his mind; he just copied-and-pasted unknown code from unknown place, adding some typos. If so, what is the need to analyze, and to explain this senseless and useless code? It even cannot be compiled!
Nic Clouston

Global Moderator

Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

 Posted: Mon Jan 07, 2019 4:49 pm This topic is 11 years old. Locked.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Cobol code- to find a string in a str... COBOL Programming 3 IEF085I REGION UNAVAILABLE,ERROR CODE... Java & MQSeries 0 Assembler test under mask question PL/I & Assembler 5 How to convert RESP code 12 to text? CICS 9 Execute step regardless of previous s... JCL & VSAM 2
Search our Forums: