Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 给定BX。将其镜像并放入CX。如何做到这一点?_Assembly - Fatal编程技术网

Assembly 给定BX。将其镜像并放入CX。如何做到这一点?

Assembly 给定BX。将其镜像并放入CX。如何做到这一点?,assembly,Assembly,给定BX。把它镜像。只能使用SHR、SHL和或XOR 例如:BX=1234h CX=4321h您没有提到是否允许使用其他寄存器,所以我假设是这样 我将只展示一些C代码,这些代码演示了如何使用给定的指令集执行所需操作,并将其转换为x86程序集,因为这应该很简单: CX = (BX & 1) << 12; AX = (BX & 2) << 12; CX |= AX; AX = (BX & 4) << 12; CX |= AX; AX = (

给定BX。把它镜像。只能使用SHR、SHL和或XOR


例如:BX=1234h CX=4321h

您没有提到是否允许使用其他寄存器,所以我假设是这样

我将只展示一些C代码,这些代码演示了如何使用给定的指令集执行所需操作,并将其转换为x86程序集,因为这应该很简单:

CX = (BX & 1) << 12;
AX = (BX & 2) << 12;
CX |= AX;
AX = (BX & 4) << 12;
CX |= AX;
AX = (BX & 8) << 12;
CX |= AX;

AX = (BX & 0x10) << 4;
CX |= AX;
AX = (BX & 0x20) << 4;
CX |= AX;
AX = (BX & 0x40) << 4;
CX |= AX;
AX = (BX & 0x80) << 4;
CX |= AX;

AX = (BX & 0x100) >> 4;
CX |= AX;
AX = (BX & 0x200) >> 4;
CX |= AX;
AX = (BX & 0x400) >> 4;
CX |= AX;
AX = (BX & 0x800) >> 4;
CX |= AX;

AX = (BX & 0x1000) >> 12;
CX |= AX;
AX = (BX & 0x2000) >> 12;
CX |= AX;
AX = (BX & 0x4000) >> 12;
CX |= AX;
AX = (BX & 0x8000) >> 12;
CX |= AX;
CX=(BX&1)4;
CX |=AX;
AX=(BX&0x1000)>>12;
CX |=AX;
AX=(BX&0x2000)>>12;
CX |=AX;
AX=(BX&0x4000)>>12;
CX |=AX;
AX=(BX&0x8000)>>12;
CX |=AX;

制作一个包含65536个条目的查找表
lut
,其中包含您需要的映射。然后使用如下代码:

        .data
lut:    .short 0x0000
        .short 0x1000
        ...
        .short 0xefff
        .short 0xffff

        .text
foo:
        xor %ecx,%ecx
        and $0xffff,%ebx
        or lut(,%rbx,2),%cx

纯8086组装解决方案如下:

mov bx, 1234h ; bx = 1234h === input
mov dx, bx    ; dx = 1234h
shr bx, 8     ; bx = 0012h
shl dx, 8     ; dx = 3400h
mov ax, bx    ; ax = 0012h
mov cx, dx    ; cx = 3400h
shr bx, 4     ; bx = 0001h
shl ax, 4     ; ax = 0120h
shr cx, 4     ; cx = 0340h
shl dx, 4     ; dx = 4000h
and ax, 00F0h ; ax = 0020h
and cx, 0F00h ; cx = 0300h
or  ax, bx    ; ax = 0021h
or  cx, dx    ; cx = 4300h
or  ax, cx    ; ax = 4321h === output

请阅读。告诉我们你尝试过什么,失败在哪里;不要把家庭作业丢给我们。你说的镜像是什么意思?BX=1234h将转换为CX=2C48h,对吗?如图所示,按位、按位,按字节BX=1234h CX=3412hCX=4321h。我写了这篇笔记,如果你能使用
ror
,你可以很容易地实现它,如
movcx,bx;ror bl,4;ror bh,4
。您只能使用
SHR
SHL
XOR
。你的回答中有一个
RET
。@JeremyP我非常抱歉。我已立即删除非法指令。您正在使用
mov
指令
mov
不是允许的指令之一。您可以使用异或dest、dest;或dest,src