Example using .csect pseudo-op with td storage-mapping class

The source for the main C prgram td1.c

  1. The following is the source for the C main program td1.c:
    
    /* This C module named td1.c   */
    extern long   t_data;
    extern  void mod_s();
    main()
    {
             mod_s();
             printf("t_data is %d\n", t_data);
    }
    
  2. The following is the assembler source for module mod1.s:
    
            .file  "mod1.s"
            .csect .mod_s[PR]
            .globl .mod_s[PR]
            .set    RTOC, 2
            l   5, t_data[TD](RTOC)  # Now GPR5 contains the
                                     # t_data value 0x10
            ai  5,5,14
            stu 5, t_data[TD](RTOC)
            br
            .globl  t_data[TD]
            .toc
            .csect  t_data[TD]  # t_data is a global symbol
                                # that has value of 0x10
                                # using TD csect will put this
                                # data into TOC area
            .long    0x10
    
  3. The following commands assemble and compile the source programs into an executable td1:
    
    as -o mod1.o mod1.s
    cc -o td1 td1.c mod1.o
    
  4. Running td1 prints the following:
    
    t_data is 30