.TITLE SWAB SWAP BYTES IN BUFFER WORDS .IDENT /C01/ .ENABL GBL,LC ; AUTHOR: Bradford Castalia ; DATE: SEP/88 ; CHANGES: ; MODULE FUNCTION: ; SWAB (BUFFER, COUNT) ; BUFFER - Address of buffer to be swabbed ; COUNT - Size (bytes) in buffer ; The bytes in each word of the buffer are byte swapped. ; If the buffer is not word aligned, or the byte count is not even ; a failure (0) status will be returned. ; If the conversion is successful, the target address is returned in R0. .LIST TTM ; TERMINAL LISTING MODE .NLIST BEX ; SUPPRESS BIN EXTENSION ; SYMBOL DEFINITIONS: ; Function arguments: .IF DF C$PMTR ARGS$$ = C$PMTR .IFF ARGS$$ = 4 .ENDC BUFFER = ARGS$$+0 COUNT = ARGS$$+2 .PSECT .PROG.,I SWAB:: JSR R5,CSV$ ; Establish the environment MOV BUFFER(R5),R0 BIT #1,R0 ; Word aligned (even) address? BNE FAIL ; No MOV COUNT(R5),R1 BEQ DONE ; Nothing to do! ASR R1 ; Convert COUNT from bytes to words BCS FAIL ; Odd number of bytes 2$: SWAB (R0)+ SOB R1,2$ DONE: MOV BUFFER(R5),R0 ; Return the BUFFER address JMP CRET$ FAIL: CLR R0 JMP CRET$ .END