Hi,
I have a problem with using variables in assembly.
I´m new to assembly and I am trying to use Roby´s programming tutorial: http://geocities.com/SiliconValley/Park/3230/x86asm/asml1001.html

The problem is that when I have declared a variable and try to move it. For example:
ideal
p286n
model tiny

codeseg
org 100h

var1 dw 2244h
entry:
jmp start

start:
mov bx, [var1]

mov ax, 4c00h
int 21h
end entry

And then debug it. It seems like the variable is blank: 0000

Am I missing something, is there no problem or is it something completely different?

Hope you can help thanks :)

Recommended Answers

All 4 Replies

I am assuming codeseg is the start of your code segment and I believe that is where your problem is. Your variable needs to be defined in the data segment. I am not sure what assembler you are using but I am only familiar with NASM and MASM. In MASM you would declare it in the .data section and NASM in the .bss section. Then you would use a mov statement to actually move a value to the variable or you could initialize it with a value. The following code statements would work in MASM.

.data
var1  dword ?     ;uninitialized variable

.code
mov var1, 2244h   ;move 2244hex into var1

I am assuming codeseg is the start of your code segment and I believe that is where your problem is. Your variable needs to be defined in the data segment. I am not sure what assembler you are using but I am only familiar with NASM and MASM. In MASM you would declare it in the .data section and NASM in the .bss section. Then you would use a mov statement to actually move a value to the variable or you could initialize it with a value. The following code statements would work in MASM.

.data
var1  dword ?     ;uninitialized variable

.code
mov var1, 2244h   ;move 2244hex into var1

For the tutorial I am using the TASM assembler.

Have just written the variables as I saw I could in the tutorial where there is not written any .data section.

Thinks it´s a bit irritating that from guide to guide it´s different how they write even though they use the same assembler....

Any good hints for a better tut? (Doesn´t matter what assembler it´s for as long as it is for DOS or Windows)

Not really. I haven't done a lot of tutorials on line. The basic principle of the code I posted will be the same but the syntax differs between assmblers. I ran into that when I started writing with NASM. I had been used to MASM. I would suggest looking at the documentation for TASM to see how the data and code segments are set up. To do the same thing I did above in NASM would look something like this:

section .bss
var1 dword 1

section .text
global_start
mov dword [var1], 2244h

So what you need to do is find the correct syntax for tasm but as far as I know you would still have to use a mov statment to move a value into the variable.

Looked at some other tutorials that used TASM and there they defined .data...

Think the only problem was the guides examples.

Thanks:)

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.