I am a very beginner in assembly. I want to print 2 members of an array.
This is how I first wrote my code:
mov PRIME_NUMBERS[1],2
mov ax,PRIME_NUMBERS[1]
call PRINT
mov PRIME_NUMBERS[2],3
mov ax,PRIME_NUMBERS[2]
call PRINT
and it prints "23" and it's ok, but when I code like:
mov PRIME_NUMBERS[1],2
mov PRIME_NUMBERS[2],3
mov ax,PRIME_NUMBERS[1]
call PRINT
mov ax,PRIME_NUMBERS[2]
call PRINT
it prints "7703و". The element number 1 seems to have been replaced by the number 770. I can not find my mistake!
my code :
.MODEL SMALL
.STACK 100H
.DATA
max_num_check dw ?
current_num dw ?
prime_numbers dw 100 DUP (0)
.CODE
MAIN PROC
;define data segment
mov ax,@DATA
mov DS,ax
;------------------
mov PRIME_NUMBERS[1],2
mov ax,PRIME_NUMBERS[1]
call PRINT
mov PRIME_NUMBERS[2],3
mov ax,PRIME_NUMBERS[2]
call PRINT
HLT
MAIN ENDP
; to print numbers , you should use mov ax,number and CALL PRINT
PRINT PROC
mov cx,0
mov dx,0
mov bx,10
l1:
cmp ax,0
je l2
div bx
push dx
inc cx
xor dx,dx
jmp l1
l2:
cmp cx,0
je end
pop dx
add dx,'0'
dec cx
mov ah,2h
int 21h
jmp l2
end:
xor ax,ax
ret
PRINT ENDP
MAX_NUM_TO_CHECK PROC
mov cx,0
here:
mov ax,cx
mul cx
cmp ax,current_num
jge store
inc cx
jmp here
store:
mov max_num_check,cx
ret
MAX_NUM_TO_CHECK ENDP
END MAIN