Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TRANSFER macro &io,&data
- ldy &data
- &io
- sty &data
- mend
- SWAPARR macro &first,&second,&len
- jmp 1
- sa_i_# bss 1 ; loop index
- zero
- sta sa_i
- sa_loop lda sa_i
- cmp &len
- jnz sa_exit ; exit loop if i == len
- js sa_exit ; exit loop if i > len (invalid arg)
- inc ; i++
- sta sa_i
- *{
- lda &first+sa_i
- ldx &second+sa_i
- sta &second+sa_i
- stx &first+sa_i
- *}
- sa_exit nop
- mend
- MAXITEM macro &arr,&len
- ma_x bss 1 ; max item will store in the Y reg
- stx len ; we will view the array from the end
- decx ; do not go out of bounds
- ldax ; arr[X] -> A
- sta ma_x ; set the last element as max
- ma_loop decx
- max ; A <- X
- cmp &arr ;
- js ma_exit ; break if array pointer < array addr
- *{
- ldax ; arr[X] -> A
- cmp ma_x
- js ma_loop; continue if cur < max
- jz ma_loop; continue if cur == max
- sta ma_x
- jmp ma_loop
- *}
- ma_exit ldy ma_x ; result
- mend
- *======SORT MATRIX=====*
- org 20
- start nop
- *===>matrix creation
- TRANSFER in,_size ; matrix size
- may ; calculating matrix array length
- mul _size
- sta _length
- zero ; i = 0
- sta _i
- _loop1 lda _i ; while i < length
- cmp _length
- jz _exit1
- *{
- TRANSFER in,_mat_p+_i ; in -> array[i]
- lda _i ; i++
- inc
- sta _i
- *}
- _exit1 nop
- *===>finding max elem in each row
- zero ; i = 0
- sta _i
- _loop2 nop
- SWAPARR 1,1,1
- SWAPARR 1,1,1
- *===>sort max array and swap rows
- stop
- _i bss 1 ; index
- _size bss 1 ; matrix size
- _length bss 1 ; matrix array length
- _mat_p con _matrix ; matrix array pointer
- _mat_a bss _length ; matrix array
- _max_p con _max_a ; max array pointer
- _max_a bss _size ; array with max elems of each row
- _ptr bss 1 ; just a pointer
- *
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement