home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / emulate / sparc / argv.s < prev    next >
Text File  |  1992-01-28  |  787b  |  58 lines

  1. !
  2. ! echo command line arguments
  3. !
  4.     add    %sp,64,%l0
  5.     ld    [%l0],%l1   ! argc
  6.     inc    4,%l0
  7. L1:
  8.     call    print_string
  9.     ld    [%l0],%o0
  10.     deccc    %l1
  11.     bg    L1
  12.     inc    4,%l0
  13.  
  14.     ld    [%sp+64],%o0  ! exit with status = argc
  15.     mov    1,%g1
  16.     ta    0
  17.     nop
  18.  
  19.     .seg "data"
  20. cr:
  21.     .ascii "\n"
  22.  
  23.     .seg "text"
  24. !
  25. ! write string pointed to by %o0 to stdout,
  26. ! followed by newline
  27. !
  28. print_string:
  29.     save    %sp,-96,%sp
  30.     call    strlen
  31.     mov    %i0,%o0
  32.     mov    %o0,%o2  ! length count
  33.     mov    1,%o0    ! write to stdout
  34.     mov    %i0,%o1  ! buffer
  35.     mov    4,%g1
  36.     ta    0
  37.     mov    1,%o0    ! now write newline
  38.     set    cr,%o1
  39.     mov    1,%o2    ! 1 byte
  40.     ta    0
  41.     ret
  42.     restore
  43.  
  44. !
  45. ! determine length of string pointed to by %o0
  46. !
  47. strlen:
  48.     mov    %o0,%l3
  49.     clr    %o0
  50. L2:
  51.     ldub    [%l3],%l4
  52.     inc    %l3
  53.     tst    %l4
  54.     bne,a    L2
  55.     inc    %o0
  56.     retl
  57.     nop
  58.