Cerca un carattere in una stringa

Character search

;—————————————————————–

; String handling in assembly

;     c) Character search

;—————————————————————–

        ORG 0000h

        JP   0100h                 ;(link to the Hardware RESET)

        ORG 0100h

START :       ld sp,0fff0h ; stack pointer initialization

             ld A,00h

            CALL subprog

             ld (8000h),hl

            ld (8002h),de

            ld (8004h),A

             ld hl,8000h

            ld A,55h    ; Char “U” the second char

            CALL subprog2

           HALT           

;This subprogram will define the string>

subprog : ld h,55h ; this subprogram will write the string “LUCA\0″

         ld l,4ch

         ld d,41h

         ld e,43h

         RET

;This subprogram will search the char>

subprog2 : ld b,a

          ld a,00h

          add A,(hl)

          jp z, exit

          ld A,b

          cp (hl)

           jp z, found

    continue : inc hl

           inc bc

           jp subprog2

    exit : ret

     found : inc hl

          inc bc

          ret

Lascia un commento