datarea segment
status db 20 dup(?)
datarea ends
code segment
main proc far
assume cs:code,ds:datarea
start:
;set up stack for return
push ds
sub ax,ax
push ax
;set ds register to current data segment
mov ax,datarea
mov ds,ax
;main part of program goes here
mov al,status
and al,2ah
jz rountine_4
xor al,2ah
jz rountine_1
bsf bl,al ;这两行注释掉就没错了,但看不出有什么错来,请大家帮忙看看,指点指点,谢谢啦!
bsr cl,al ;
cmp bl,cl
je rountine_2
rountine_3:
mov dl,'1'
mov ah,2
int 21h
rountine_2:
mov dl,'2'
mov ah,2
int 21h
rountine_1:
mov dl,'3'
mov ah,2
int 21h
rountine_4:
mov dl,'0'
mov ah,2
int 21h
main endp
code ends
end start
------解决方案--------------------------------------------------------
1. bsf,bsr 是386后的指令。在代码开头加上.386
2. bsf,bsr 的操作数是字,或双字。bl,cl,al,是8位寄存器,换成bx,cx,ax的字寄存器,根据需要可能要先进行高8位的清零操作。
3. 在main endp 前加上
mov ax,4c00h
int 21h
------解决方案--------------------------------------------------------
不只是要加 .386 语句这么简单。按照 Masm 的约定,dos16 类的程序,还应在之前加上 .model 语句:
.model small
.386
而且,最好能使用 Masm6.0 或更高版本来进行编译。因为我试过 Masm5,生成的代码还是 32位数据的,和原意有异。
------解决方案--------------------------------------------------------
我再补充一下:
.386 是个模式定义,用来告诉编译器当前程序使用的指令集[8086 or 80386等]
.model 定义当前程序的工作模式
.model small ;表示创建的代码和数据分别使用一个64KB段的exe程序