检查正数集合8086 [英] check positive number assembly8086

查看:0
本文介绍了检查正数集合8086的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写汇编代码8086我有两个大小为10的数组X和Y,我想输入一个数字并检查其正y是否为1,如果为负则为0 但我的代码只显示了我输入的数字,但我希望它像这个例子一样。 示例:

X : 2 -5 -7 8 -4 9 11 -12 90 -50
Y : 1 0 0 1 1  0 1 1   0   1  0

我写道:

.MODEL SMALL
.DATA
x db 10 dup ("?")
y db 10 dup ("?")
.CODE
MOV AH,1
INT 21H
mov si,offset x
mov di,offset y
mov [si],al
cmp si,0
ja l1
jmp l2
l1 : mov al , 1
     mov [di],al
     jmp l3
l2 : mov ah , 0
     mov y[di] , al
     jmp l3

l3 :
MOV AH, 2
mov dl,al
INT 21H
cmp si,10
je l4
inc si
inc di

l4 : 
.EXIT
END

推荐答案

问题列表很长。查看这些注释,并尝试查看错误存在的原因。

                      <<<< add label for a 10-time repeat
MOV AH,1
INT 21H
mov si,offset x       <<<< move higher up for 1-time execution
mov di,offset y       <<<< move higher up for 1-time execution
mov [si],al
cmp si,0              <<<< the byte to compare is in AL
ja l1                 <<<< requires a SIGNED conditional, use JGE
jmp l2                <<<< reverse condition and drop this jump
l1 : mov al , 1
     mov [di],al
     jmp l3
l2 : mov ah , 0       <<<< should be AL
     mov y[di] , al   <<<< DI already refers to the y-array, use just [DI]
     jmp l3           <<<< redundant

l3 :
MOV AH, 2
mov dl,al
INT 21H
cmp si,10             <<<< 10 is wrong
je l4
inc si                <<<< move above checking iterator
inc di                <<<< move above checking iterator
                      <<<< needs jumping back in order to repeat
l4 :

下一段代码与您的代码一样,从键盘输入单个字符,并将其ASCII代码视为要存储在x数组中的字节。对于负字节,应输入扩展的ASCII。请使用Alt后跟一个最大为255的数字。

.CODE
 xor  bx, bx
again:
 mov  ah, 01h      ; DOS.GetCharacter
 int  21h          ; -> AL
 mov  x[bx], al
 mov  ah, 255
 shl  ax, 1
 not  ah
 mov  y[bx], ah    ; 1 for positive, 0 for negative
 inc  bx
 cmp  bx, 10
 jb   again
.EXIT

这篇关于检查正数集合8086的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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