MASM程序集将8位寄存器移到16位寄存器(即mov cx,ch) [英] MASM Assembly move 8 bit register to the 16 bit register (ie. mov cx, ch)

查看:209
本文介绍了MASM程序集将8位寄存器移到16位寄存器(即mov cx,ch)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定学习汇编语言.我正在使用

I decided to learn an assembly programming language. I am using this 8086 tutorial. At the bottom the exercise is to find an error in some instructions and one of them is

mov cx, ch 

我在此主题上找到了类似的问题,解释了如何实现它,但现在我想知道为什么禁止执行此操作?

I found some similar question on SO on this topic explaining how to achieve it but now I'd like to know why this operation is forbidden?

让我们假设我在CH中有10d = 00001010b,并希望将其放入CL并同时擦除CH. mov cx, ch之所以这样做是因为它将10d显示为16位00000000 00001010并将其分别放入CH和CL(整个CX)

Let's assume I have 10d = 00001010b in CH and want to put it to CL and simultaneously erase CH. mov cx, ch seems to do it because it shows 10d as 16bit 00000000 00001010 and puts it respectively to CH and CL (entire CX)

这有什么问题,为什么给定的教程要求在该表达式中查找错误?

推荐答案

mov指令用于在大小相同的操作数之间移动.您想要的是将8位ch扩展到16位cx.有两个说明可用于此目的:

The mov instruction is used to move between operands of the same size. What you want to is extend the 8-bit ch into the 16-bit cx. There are two instructions available for that purpose:

movzx cx,ch  ; zero-extends ch into cx. the upper byte of cx will be filled with zeroes
movsx cx,ch  ; sign-extends ch into cx. the upper byte of cx will be filled with the most significant bit of ch

在这种特殊情况下完成同一件事的另一种方法是:

Another way of accomplishing the same thing in this particular case would be:

shr cx,8  ; zero-extend
sar cx,8  ; sign-extend

这篇关于MASM程序集将8位寄存器移到16位寄存器(即mov cx,ch)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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