Hi,

I am learning ASM and have encountered a problem.

I have the following statements. When debugging I am seeing that the value in AL is not being inserted as 02h. On the other hand if I change "mov al, [myNumber]" to "mov al, 02h", I get the desired value.

Can any one please help?

.model small
.stack
.data
myNumber db 2

.code
jmp start

start:
mov al, [myNumber]

mov ax,4c00h
int 21h
end start

Thanks in advance,

I think because you don't set ds register with data segment
add this two line at the fisrt of your code segment

mov ax, @data
mov ds, ax

like this:

.model small
.stack
.data
myNumber db 2

.code
jmp start

start:   
mov ax, @data
mov ds, ax
mov al, [myNumber]

mov ax,4c00h
int 21h 
end start

Well first of all it depends on whether you are doing 16 or 32 bit and what assembler you are using. If this is 32 bit code you do not have to set the ds segment. As far as the assmbler I am only familiar with masm and nasm. The two have very different ways of declaring variables. If you are using masm then try this in your variable declaration:

mynumber db 02h

If it is nasm the statement you have sould not work becuase you would have to use resb in place of db and the 2 would be the number of bytes allocated. If you are using some other assembler you would need to look up the documentation or speak with someone that is experienced with that assembler. I hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.