Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Context - A friend on Discord linked a basic leetcode problem, where in the code must return 0 if it can match the needle string in the haystack string, and if it fails, return -1. Did this 68k ASM version for funsies.
- entry:
- lea haystack, a0 ; Get string we're comparing.
- lea needle, a1 ; Get key we're looking for.
- loop:
- cmp.b (a0)+, (a1)+ ; Compare characters in key based on correct chars so far.
- bne.s @resetcount ; If they don't match, don't increment
- bra.s @cont
- @resetcount:
- lea needle, a1 ; Reload needle string from start.
- @cont:
- cmp.b #$FF, (a1) ; Have we hit the end of the needle string?
- beq.s @pass ; If so then we pass.
- cmp.b #$FF, (a0) ; Have we hit the end of the haystack string?
- beq.s @fail ; If so then we fail.
- bra.s loop ; Loop until we either pass or fail.
- @fail:
- moveq #0, d7 ; Report no match.
- bra.s freeze
- @pass:
- moveq #-1, d7 ; Report success.
- freeze:
- bra.s freeze ; Freeze program to allow memory examination.
- haystack:
- dc.b "sadbutsad", $FF
- needle:
- dc.b "sad", $FF
- end
Advertisement
Add Comment
Please, Sign In to add comment