Advertisement
Guest User

Untitled

a guest
Mar 11th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TRANSFER    macro   &io,&data
  2.     ldy &data
  3.     &io
  4.     sty &data
  5.     mend
  6. SWAPARR macro   &first,&second,&len
  7.     jmp 1
  8. sa_i_#  bss 1   ;   loop index
  9.     zero
  10.     sta sa_i
  11. sa_loop lda sa_i
  12.     cmp &len
  13.     jnz sa_exit ;   exit loop if i == len
  14.     js  sa_exit ;   exit loop if i > len (invalid arg)
  15.     inc     ;   i++
  16.     sta sa_i
  17. *{
  18.     lda &first+sa_i
  19.     ldx &second+sa_i
  20.     sta &second+sa_i
  21.     stx &first+sa_i
  22.        
  23. *}
  24. sa_exit nop
  25.     mend
  26. MAXITEM macro   &arr,&len
  27. ma_x    bss 1   ;   max item will store in the Y reg
  28.     stx len ;   we will view the array from the end
  29.     decx        ;   do not go out of bounds
  30.     ldax        ;   arr[X] -> A
  31.     sta ma_x    ;   set the last element as max
  32. ma_loop decx
  33.     max     ;   A <- X
  34.     cmp &arr    ;
  35.     js  ma_exit ;   break if array pointer < array addr
  36. *{
  37.     ldax        ;   arr[X] -> A
  38.     cmp ma_x
  39.     js  ma_loop;    continue if cur < max
  40.     jz  ma_loop;    continue if cur == max
  41.     sta ma_x
  42.     jmp ma_loop
  43. *}
  44. ma_exit ldy ma_x    ;   result
  45.     mend
  46. *======SORT MATRIX=====*   
  47.     org 20
  48. start   nop
  49. *===>matrix creation
  50.     TRANSFER in,_size   ;   matrix size
  51.     may     ;   calculating matrix array length
  52.     mul _size
  53.     sta _length
  54.     zero        ;   i = 0
  55.     sta _i
  56.  
  57. _loop1  lda _i  ;   while i < length
  58.     cmp _length
  59.     jz  _exit1
  60. *{
  61.     TRANSFER in,_mat_p+_i   ;   in -> array[i]
  62.     lda _i  ;   i++
  63.     inc
  64.     sta _i
  65. *} 
  66. _exit1  nop
  67. *===>finding max elem in each row
  68.     zero        ;   i = 0
  69.     sta _i
  70. _loop2  nop
  71.     SWAPARR 1,1,1
  72.     SWAPARR 1,1,1
  73. *===>sort max array and swap rows
  74.     stop
  75.  
  76. _i  bss 1   ;   index
  77. _size   bss 1   ;   matrix size
  78. _length bss 1   ;   matrix array length
  79. _mat_p  con _matrix ;   matrix array pointer
  80. _mat_a  bss _length ;   matrix array
  81. _max_p  con _max_a  ;   max array pointer
  82. _max_a  bss _size   ;   array with max elems of each row
  83. _ptr    bss 1   ;   just a pointer
  84. *
  85.     end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement