Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;----------------------------------------------------------------------------------------------------------------------
- ;; strcmp
- ;; Test a string until a difference occurs. A will be the difference (1st different char - 2nd different char).
- ;; This means that A < 0 (signed 8-bit) then first string comes before second string. If A == 0 (or Z flag is set), strings are the
- ;; same up until they are terminated (with a 0).
- ;;
- ;; Input:
- ;; DE = 1st string (signed characters)
- ;; HL = 2nd string (signed characters)
- ;;
- ;; Output:
- ;; A = difference of first different character (0 if strings are the same)
- ;; ZF = 1 if strings are the same
- ;;
- strcmp:
- push bc
- push de
- push hl
- .l1 ld a,(de)
- cpi ; ZF affected by comparison
- jr nz,.no_match ; If ZF=0, then a difference is discovered
- inc de
- ; Both characters are the same, so check for null termination for both
- and a
- jr nz,.l1
- jr .end
- .no_match ; A = difference (or 0 if both terminated)
- dec hl
- sub (hl)
- .end pop hl
- pop de
- pop bc
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement