.title Byte Processing Routines ; DECUS C Calling Format ; ; jsr r5,csv$ ;save r2,r3, and r4 ; ;r5 is parameter base ; ;c$pmtr(r5) is first argument ; ;c$pmtr+2(r5) is second argument ; ;... ; ;return args in r0 ; ... ; user code ; ... ; ; jmp cret$ ;restore r2-r5 and return ; rts pc ;does the same (cret$ follows csv$) ; ; csv$ and cret$ need be used only if arguments are used ; ; ; Macro routines for special functions ; .psect c$code ; ; intswap ; swap byte positions integer ; ; in: 0 1 ; lobyte hibyte ; out: 0 1 ; hibyte lobyte ; intswap:: jsr r5,csv$ mov c$pmtr(r5),r0 swab r0 ;swap bytes of integer rts pc ; ; longswap ; swap byte positions long ; ; in: 0 1 2 3 ; 2nd 3rd 0th 1st ; out: 0 1 2 3 ; 3rd 2nd 1st 0th ; longswap:: jsr r5,csv$ mov c$pmtr(r5),r0 ;high word swab r0 ;swap bytes of word mov c$pmtr+2(r5),r1 ;low word swab r1 ;swap bytes of word rts pc ; ; movebytes ; arbitrary byte moves of any count ; usage: ; movebytes(to,from,n); ; note: ; buffers should not overlap ; movebytes:: jsr r5,csv$ mov c$pmtr(r5),r2 ;destination buffer address mov c$pmtr+2(r5),r1 ;source buffer address mov c$pmtr+4(r5),r0 ;byte count beq 6$ ;none - exit cmp #9.,r0 ;break point for fast word copy bhi 3$ mov r1,-(sp) ;check mismatched byte boundarys add r2,(sp) ror (sp)+ ;'c'=1 if odd/even or even/odd bcs 3$ ;no choice - slow copy bit #1,r1 ;odd byte ? beq 1$ ;no - skip movb (r1)+,(r2)+ ;get to even byte dec r0 1$: mov r0,-(sp) ;save count asr r0 ;divide by 8. asr r0 asr r0 2$: mov (r1)+,(r2)+ ;copy word data quickly mov (r1)+,(r2)+ mov (r1)+,(r2)+ mov (r1)+,(r2)+ dec r0 ;loop for 4 word groups bne 2$ mov (sp)+,r0 ;retrieve count bic #^C7,r0 ;remaining bytes beq 6$ ;none - exit 3$: cmp #4.,r0 ;break point for fast byte copy bhi 5$ mov r0,-(sp) ;save count asr r0 ;divide by 4 asr r0 4$: movb (r1)+,(r2)+ ;copy byte data quickly movb (r1)+,(r2)+ movb (r1)+,(r2)+ movb (r1)+,(r2)+ dec r0 ;loop for 4 byte groups bne 4$ mov (sp)+,r0 ;retrieve count bic #^C3,r0 ;remaining bytes beq 6$ ;none - exit 5$: movb (r1)+,(r2)+ ;copy a byte at a time dec r0 bne 5$ 6$: rts pc ; ; comparen ; n byte compare ; usage: ; i = comparen(string1,string2,n); ; result: ; 1 on match ; 0 on no match ; comparen:: jsr r5,csv$ clr r0 ;no match mov c$pmtr(r5),r3 ;string1 mov c$pmtr+2(r5),r2 ;string2 mov c$pmtr+4(r5),r1 ;byte count beq 2$ ;none - exit 1$: cmpb (r2)+,(r3)+ ;the same ? bne 2$ ;nomatch - exit with r0 == 0 dec r1 ;loop for n bytes bne 1$ inc r0 ;match - exit with r0 == 1 2$: rts pc .end