git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

gbdk-lib/libc/asm/sm83/_strcmp.s

      1         .module strcmp
      2 
      3         .area   _HOME
      4 
      5 ; int strcmp(const char *s1, const char *s2) 
      6 _strcmp::
      7         lda     hl,2(sp)
      8         ld      a,(hl+)
      9         ld      e, a
     10         ld      a,(hl+)
     11         ld      d, a
     12         ld      a,(hl+)
     13         ld      h,(hl)
     14         ld      l,a
     15 1$:     
     16         ld      a,(de)
     17         sub     (hl)            ; s1[i]==s2[i]?
     18         jr      nz, 2$          ; -> Different
     19         ;; A == 0
     20         cp      (hl)            ; s1[i]==s2[i]==0?
     21         
     22         inc     de
     23         inc     hl
     24         jr      nz, 1$          ; ^ Didn't reach a null character. Loop.
     25         
     26         ; Yes. return 0;
     27         ld      d, a            ; Since a == 0 this is faster than a 16 bit immediate load.
     28         ld      e, a
     29         ret
     30 2$:
     31         ld      de,#-1
     32         ret     c
     33 
     34         ld      de,#1
     35         ret

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.