home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / 68k_book / arp_src / prg_6bp.s < prev    next >
Text File  |  1985-11-20  |  4KB  |  129 lines

  1.  ; Program Name: PRG_6BP.S
  2.  ;      Version: 1.002
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Before this program is executed, trap 11 must be installed via the
  11.  ; execution of program PRG_6AP.TOS.  In addition, this program uses traps
  12.  ; installed by CUSTOM.PRG.  Execute from the desktop or via SPAWN.TTP.
  13.  
  14.  ; Program Function:
  15.  
  16.  ;     Prints the content of register A7 during various stages of execution
  17.  ; while the state of the processor is varied from user mode to supervisor
  18.  ; mode, from supervisor mode back to user mode, from user mode to supervisor
  19.  ; mode a second time and from supervisor mode back to user mode a second time.
  20.  
  21.  ;     In this program, custom trap #11 is used to toggle the state of the
  22.  ; processor.
  23.  
  24. calculate_program_size:
  25.  lea        -$102(pc), a1       ; Fetch basepage start address.
  26.  lea        program_end, a0     ; Fetch program end address.
  27.  trap       #6                  ; Return unused memory to op system.
  28.  
  29. print_heading:
  30.  lea        heading, a0
  31.  bsr.s      print_string
  32.  
  33.  ; NOTE: During this section of the program, no user stack has yet been
  34.  ;       assigned, therefore, the user stack address is that of the default
  35.  ;       user stack assigned by the system when execution commences.
  36.  
  37. print_address_of_default_user_stack:
  38.  lea        header_1, a0
  39.  bsr.s      print_string
  40.  move.l     a7, d1              ; Convert address to ASCII hexadecimal.
  41.  trap       #5
  42.  bsr.s      print_string
  43.  bsr.s      print_newline
  44.  
  45. invoke_custom_super_mode_trap:
  46.  trap       #11                 ; Sets bit 13 of SR to 1 and prints SSP.
  47.  
  48. print_current_SSP:              ; SSP = address of supervisor stack.
  49.  lea        header_2, a0        ; Did invocation of trap #11 alter the address
  50.  bsr.s      print_string        ; in the supervisor stack pointer?
  51.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  52.  trap       #5
  53.  bsr.s      print_string
  54.  bsr.s      print_newline
  55.  bsr.s      print_newline
  56.  
  57. enter_user_mode:
  58.  andi.w     #$DFFF, SR          ; Sets bit 13 of status register to zero.
  59.  
  60.  ; NOTE: During this section of the program, a user stack is assigned.  The
  61.  ;       user stack address is that of the label "stack".
  62.  
  63. print_address_of_assigned_user_stack:
  64.  lea        header_3, a0
  65.  bsr.s      print_string
  66.  lea        stack, a7
  67.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  68.  trap       #5
  69.  bsr.s      print_string
  70.  bsr.s      print_newline
  71.  
  72. invoke_custom_super_mode_trap_again:
  73.  trap       #11                 ; Sets bit 13 of SR to 1 and prints SSP.
  74.  
  75. print_current_SSP_again:        ; Did invocation of trap #11 alter the address
  76.  lea        header_4, a0        ; in the supervisor stack pointer?
  77.  bsr.s      print_string
  78.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  79.  trap       #5
  80.  bsr.s      print_string
  81.  bsr.s      print_newline
  82.  
  83. enter_user_mode_again:
  84.  andi.w     #$DFFF, SR          ; Sets bit 13 of status register to zero.
  85.  
  86. print_address_of_assigned_user_stack_again:
  87.  lea        header_5, a0
  88.  bsr.s      print_string
  89.  move.l     a7, d1              ; Convert to ASCII hexadecimal.
  90.  trap       #5
  91.  bsr.s      print_string
  92.  bsr.s      print_newline
  93.  
  94. terminate:
  95.  trap       #8
  96.  
  97.  ;
  98.  ; SUBROUTINES
  99.  ;
  100.  
  101. print_string:         
  102.  pea        (a0)
  103.  move.w     #9, -(sp) 
  104.  trap       #1        
  105.  addq.l     #6, sp    
  106.  rts
  107.  
  108. print_newline:
  109.  lea        newline, a0
  110.  bsr.s      print_string
  111.  rts
  112.  
  113.  data
  114. newline:   dc.b $D,$A,0
  115. heading:   dc.b 'PRG_6BP Execution Results => Content of A7:',$D,$A,$D,$A,0
  116. header_1:  dc.b   '  NO USER STACK ASSIGNED',$D,$A
  117.            dc.b   '    Start of program:          ',0
  118. header_2:  dc.b   '    After trap 11 invocation:   ',0
  119. header_3:  dc.b   '  USER STACK ASSIGNED',$D,$A
  120.            dc.b   '    After force to user mode:  ',0
  121. header_4:  dc.b   '    After trap 11 invocation:   ',0
  122. header_5:  dc.b   '    After force to user mode:  ',0
  123.  bss
  124.  align 
  125.                ds.l   96
  126. stack:         ds.l    0
  127. program_end:   ds.l    0
  128.  end