Link to home
Start Free TrialLog in
Avatar of eylkrn
eylkrn

asked on

variabled in assembler - question

Hello,

I have a question , about variables in masm.
I've coded the following program(attached). the program get 4 numbers from num1,num2,num3,num4 and print them on the screen at the corrdinate of dx.
anyway , I'm  experiencing some wierd problems:

1) why can't I declare the variables in .data , the program doesnt work the same. why?
2) I cant debug my program if I decalre the variables at code segment. I see the machine code instead of my program. why?
3) how can I declare the variables in the data segment and that the program will run ok.
4) if I add another variables (for examples: num db 1) before the num1 variables then the program is running ok, why?


Thanks,
Eyal Keren


my program:
----------------

.model small
.stack 100h
.data

.code


num1 db 5h
num2 db 3h
num3 db 8h
num4 db 2h



mov ax,02h
int 10h

add num1,30h ;converting the number wanted to its ascii code
add num2,30h
add num3,30h
add num4,30h



mov bx,0
mov ax,0b800h
mov ds,ax
;mov ax,3441h
;mov [bx],ax

mov al,030h ;  COLOR
mov dx,0000h ; CORDINATES "0000h" is considerred to be first line,first column

cmp dl,0 ;checks if x-axis is zero, no need in shifting inside the row
jz yy
call x_pos ;else, calling the x-shifting procedure

yy:cmp dh,0 ;checks if y-axis is zero, no need in shifting rows
jz zz
call y_pos ;else, calling the y-shifting procedure

zz: ; printing on the screen after going to the right cordinates

mov ah,al
mov al,[num1] ;should be num1 insteed, and its value and not ascii code
mov [bx],ax
add bx,2
mov al,[num2] ;should be num2 insteed, and its value and not ascii code
mov [bx],ax
add bx,2
mov al,[num3] ;should be num3 insteed, and its value and not ascii code
mov [bx],ax
add bx,2
mov al,[num4] ;should be num4 insteed, and its value and not ascii code
mov [bx],ax
;

kkk: jmp kkk ; stuck the program, so we can see the result on the screen


x_pos proc
;dec dl
loop1: add bx,2
       dec dl
      jnz loop1

ret
x_pos endp

y_pos proc
;dec dh
loop2: add bx,0a0h
      dec dh
      jnz loop2

ret
y_pos endp

mov ah,4ch; Exit Code
int 21h
end

   


SOLUTION
Avatar of dimitry
dimitry

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eylkrn
eylkrn

ASKER

Hi,

thanks zvika for your remark.

I've solved my problem with anothed method:

.data
num1 db 1dh
num2 db 19h
num3 db 22h
num4 db 19h
.code
mov ax, @data
mov es,ax

and now I can call my variables using es:num1, es:num2 and so on.

Eyal