Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.arch Subject: Endian reversing MOVEs Message-ID: <759@atanasoff.cs.iastate.edu> Date: 3 Feb 89 17:37:08 GMT Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State U. Computer Science Department, Ames, IA Lines: 107 Well, all this talk about different ways to add endian features to architectures has finally gotten to me. So here is a couple of macros to do endian-reversing moves. What do you think? Any one think of a better method? This one is in VAXmacro, but it should be fairly readable. John Hascall ISU Comp Center -------------------------------cut, fold, spindle, etc here--------- .title ENDTEST .sbttl Ten little endians ; ; Facility: Endian switching macros ; Author: John Hascall ; Written: 2 Feb 1989 ; .page .sbttl Macros ; ; The following macros move a word (16bits) or a longword(32bits) ; while reversing their endian-ness. Note the the condition codes ; are set based on the source operand. ; ; Move and Reverse Endian-ness Word ; .macro MREW src,dst MOVW src,-(SP) ; stack source operand MOVB 0(SP),-(SP) ; re-stack HI byte MOVB 2(SP),-(SP) ; re-stack LO byte MOVW (SP)+,dst ; pop it into destination operand TSTW (SP)+ ; clear stack, set cond codes .endm ; ; Move and Reverse Endian-ness Longword ; .macro MREL src,dst PUSHL src ; stack source operand MOVB 0(SP),-(SP) ; re-stack HI byte MOVB 2(SP),-(SP) ; re-stack HI-MID byte MOVB 4(SP),-(SP) ; re-stack LO-MID byte MOVB 6(SP),-(SP) ; re-stack LO byte MOVL (SP)+,dst ; pop it into destination operand TSTL (SP)+ ; clear stack, set cond code .endm .page .sbttl Readonly and Read/Write Storage .psect READONLY,RD,NOWRT,NOEXE AB: .ascii 'AB' ABCD: .ascii 'ABCD' .psect DATA,RD,WRT,NOEXE DESCR2: .long 2 ; string descriptiors for LIB$PUT_OUTPUT .address TWO DESCR4: .long 4 .address FOUR TWO: .ascii ' ' ; where to put AB and ABCD FOUR: .ascii ' ' .page .sbttl Program ; ; test the MRE{W|L} macros ; .psect CODE,RD,NOWRT,EXE .entry ETEST,^M<> MREW AB,TWO PUSHAQ DESCR2 CALLS #1,g^LIB$PUT_OUTPUT ; expect: BA MREL ABCD,FOUR PUSHAQ DESCR4 CALLS #1,g^LIB$PUT_OUTPUT ; expect: DCBA MOVW AB,R0 MREW R0,TWO PUSHAQ DESCR2 CALLS #1,g^LIB$PUT_OUTPUT ; expect: BA MOVL ABCD,R1 MREL R1,FOUR PUSHAQ DESCR4 CALLS #1,g^LIB$PUT_OUTPUT ; expect: DCBA MREW AB,R0 MREW R0,TWO PUSHAQ DESCR2 CALLS #1,g^LIB$PUT_OUTPUT ; expect: AB MREL ABCD,R1 MREL R1,FOUR PUSHAQ DESCR4 CALLS #1,g^LIB$PUT_OUTPUT ; expect ABCD RET .end ETEST -----------------------------end snipping zone--------------------