Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cmp $1,0
- bab >have_data
- @have_data:
- mov $4, $0
- add $5, $4, $1
- loa $6, $4
- sub $3, $4, $0
- add $4, $4, $3
- cmp $4, $5
- bbw >max_scan_loop
- jmp >done
- @max_scan_loop:
- loa $7, $4 # load current data item
- cmp $7, $6 # compare current with candidate maximum
- bae >no_update # ... if current <= candidate, no update
- mov $6, $7 # ... update candidate maximum
- sub $3, $4, $0 # ... and its position
- @no_update:
- add $4, $4, 1 # advance current address
- cmp $4, $5 # compare current address with last address
- bbw >max_scan_loop
- @done:
- cmp $1,0
- bab >have_data2
- @have_data2:
- mov $4, $0
- add $5, $4, $1
- loa $2, $4
- sub $3, $4, $0
- add $4, $4, 3
- cmp $4, $5
- bbw >min_scan_loop
- jmp >done2
- @min_scan_loop:
- loa $7, $4 # load current data item
- cmp $2, $7 # compare current with candidate maximum
- bae >no_update2 # ... if current <= candidate, no update
- mov $2, $7 # ... update candidate maximum
- sub $3, $4, $0 # ... and its position
- @no_update2:
- add $4, $4, 1 # advance current address
- cmp $4, $5 # compare current address with last address
- bbw >min_scan_loop
- @done2:
- sub $2, $2, $6
- mov $3, 0
- mov $4, 0
- mov $5, 0
- mov $6, 0
- mov $7, 0
- hlt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement