交换头寸(HC11) [英] Swapping positions (HC11)

查看:141
本文介绍了交换头寸(HC11)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在玩我的 MC 68HC11 ;在C中,我可以通过执行以下操作来执行简单的字节交换:

I'm just playing with my MC 68HC11; in C i can perform a simple byte swap by doing something like this:

swapped = ((num>>24)&0xff) | // move byte 3 to byte 0
                    ((num<<8)&0xff0000) | // move byte 1 to byte 2
                    ((num>>8)&0xff00) | // move byte 2 to byte 1
                    ((num<<24)&0xff000000); // byte 0 to byte 3

但是现在我想使用汇编代码来实现一些困难:

But now i want to achieve something a little harder using assembly code:

我创建了一个ARRAY并添加了一些值(使用小端逻辑).我想读一下ARRAY并将所有值交换成大端逻辑,然后将它们存储在"BIGENDIAN"中. 我在想这样的事情:

I created an ARRAY and added some values (using little endian logic). I want to read that ARRAY and swap all the values into big endian logic and store them inside "BIGENDIAN". I was thinking something like this:

RWM     EQU $0
ROM     EQU     $C000
RESET       EQU     $FFFE

        ORG     RWM
BIGENDIAN   RMB  16 

        ORG     ROM
Main:       


END     BRA END

ARRAY   DW  $0124,$FEEB,$0011,$0070,$ABEF,$074B,$8004,$8080

        ORG RESET
        DW  Main

我尝试过,但是无法正常工作.

I tried but it did not work properly.

推荐答案

DW创建16位字. (您的C示例适用于32位字.)

DW creates 16-bit words. (Your C example is for 32-bit words.)

对于16位,一种可能是:

For 16-bit one possibility is this:

RAM                 equ       $0
ROM                 equ       $C000
Vreset              equ       $FFFE

                    org       RAM

BIGENDIAN           rmb       16

                    org       ROM

ARRAY               dw        $0124,$FEEB,$0011,$0070,$ABEF,$074B,$8004,$8080

Start               ldx       #ARRAY              ;X -> source
                    ldy       #BIGENDIAN          ;Y -> destination

Loop                ldd       ,x                  ;A = MSB, B = LSB (big endian view)
                    staa      1,y
                    stab      ,y

; one alternative for above two instructions
;                   pshb
;                   tab
;                   pula
;                   std       ,y

                    ldab      #2                  ;B = word size
                    abx                           ;X -> next word
                    aby                           ;Y -> next word

                    cpx       #ARRAY+::ARRAY
                    blo       Loop

Done                bra       *

                    org       Vreset
                    dw        Start

如果您要说的是32位字,那么应该将两个16位字视为一个字,我会进行修改.

If you meant 32-bit words, so two 16-bit should be considered one word, I'll revise.

这篇关于交换头寸(HC11)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆