Skip to Content
Amiga Assembly Library v41.21 — Motorola 68020 shared library for Commodore Amiga

RevertMem

Synopsis

RevertMem(start, end, type) A0 A1 D0:8

C Prototype

void RevertMem(APTR start, APTR end, ULONG type);

Description

This function reverses the contents of a memory area defined by start and end. It reverses the sequence of bytes, words, or longwords within the specified region. The first byte/word/longword becomes the last, the second becomes the second-to-last, and so on.

The reversal granularity is controlled by the type parameter, which specifies the number of bits to operate on (8, 16, or 32).

Inputs

  • start — Start address of the memory area to reverse.
  • end — End address of the memory area to reverse. This can be calculated by adding the number of bytes to operate on to start, regardless of whether the reversal is performed on bytes, words, or longwords.
  • type — Specifies the number of bits (8, 16, or 32) to operate on. The accepted values are:
    • TYPEF_BYTE — operates on bytes
    • TYPEF_WORD — operates on words
    • TYPEF_LONG — operates on longwords

Result

None.

Example

; ; Reverse 2 words at address: ; ; test: dc.b "ABCD" ; move.l assemblybase,a6 lea test,a0 lea 4(a0),a1 moveq #TYPEF_WORD,d0 JSR _LVORevertMem(a6) ; ; After the call to RevertMem() you will have: ; ; test: dc.b "CDAB" ;

Notes

As shown in the example, the end address is easily calculated starting from the start address. Keep in mind that the difference between end and start must always equal the number of bytes to operate on.

See Also

None.

Implementation

The original 68020 assembly implementation:

; (V41.1) - 21-Oct-1994 --- RevertMem() _LVORevertMem move.l a1,d1 ; D1 = number of bytes to reverse sub.l a0,d1 bhi.s RVM_CON move.l (sp)+,d2 rts RVM_CON move.l d2,-(sp) asr.w d0,d1 asr.w #1,d1 subq.w #1,d1 subq.w #1,d0 bmi.s RVM_BYT beq.s RVM_WOR RVM_LON move.l -(a1),d2 move.l (a0)+,(a1) move.l d2,-4(a0) dbf d1,RVM_LON move.l (sp)+,d2 rts RVM_WOR move.w -(a1),d2 move.w (a0)+,(a1) move.w d2,-2(a0) dbf d1,RVM_WOR move.l (sp)+,d2 rts RVM_BYT move.b -(a1),d2 move.b (a0)+,(a1) move.b d2,-1(a0) dbf d1,RVM_BYT move.l (sp)+,d2 rts
Last updated on