在装配中转移部门问题

时间:2015-05-21 21:55:50

标签: assembly x86

使用shr但仅在我使用shift for count 1不工作时才工作。 。 。 。只有2分工作才有效,但是当事情进展不顺利时。 这是例如代码:

.model small
.stack 100h
.data
num db 8
.code
main proc
mov ax , @data
mov ds , ax

mov al , num
shr al , 2 ; this instruction is giving the error   
mov dl ,al 
add dl , 48
mov ah ,2
int 21h

mov ax , 4c00h
int 21h

main endp
end main

2 个答案:

答案 0 :(得分:3)

在8086上,SHR指令可以使用shr al,1向右移动一个位置,或者可以使用shr al,cl移位多个位置。因此,如果您想要向右移动两个位置,您可以写两个移位指令:

shr al,1
shr al,1

或者你将值2放入cl并转移:

mov cl,2
shr al,cl

后来的英特尔处理器(我不记得是否是80286或80386)添加了shr al,x,其中x可以是1以外的数字。

如果您在编译时遇到该错误(即汇编程序发出错误),那么它会告诉您该指令对您选择为其生成代码的处理器无效。

如果你在运行时获得了非法指令,那是因为汇编程序为后来的处理器(例如80386)生成了代码,但是你在8086上运行代码,这不支持该指令

答案 1 :(得分:0)

有些装配工接受:

shr ax, 4

其他汇编程序需要使用CL:

mov  cl, 4
shr  ax, cl

还测试SHR是否需要8位或16位寄存器:

shr  al, cl          ;<==== THIS MIGHT BE REJECTED.
shr  ax, cl

这取决于您使用的汇编程序。接下来的两个链接有帮助:

http://www.masmforum.com/board/index.php?PHPSESSID=8d46cd4ecb1688be429ab49694ec53e6&topic=12565.0;wap2

http://people.sju.edu/~ggrevera/arch/references/MASM61PROGUIDE.pdf

相关问题