Black White
Black White

Reputation: 1

check positive number assembly8086

iam trying to write an assembly code 8086 i have two array X AND Y size 10 and i want to enter a number and check if its positive y will be 1 if negative it will be 0 but my code just displayed what i enter a number but i want it like this example . example:

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

I wrote:

.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

Upvotes: 0

Views: 363

Answers (1)

Sep Roland
Sep Roland

Reputation: 39191

The list of problems is long. Check out these comments and try to see why the error exists.

                      <<<< 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 :

Next code, just like yours, inputs a single character from the keyboard and treats its ASCII code as the byte you want to store in the x array. For negative bytes you should input extended ASCII's. Use the Alt followed by a number up to 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

Upvotes: 1

Related Questions