A bit of assembler advice needed

Soldato
Joined
4 Mar 2006
Posts
3,712
Location
Wales
A bit of assembler advice needed (today)

Hey all, I really should learn things as I go along.


Anyway in my writing of a little program in assembler, I've noticed I tend to use eax and ebx for most things.

This isn't a problem, but in this program I need to store a couple of user inputted strings, one a single letter and the other a proper string (Their name).


Would I have to store these in eg the ecx and edx registers, or is there a way (which I'd assume is the case) of storing them into a particular variable.

If so how would I declare an empty variable, and what command would I use to put the values into the variables.

Thanks :)
 
Last edited:
EDIT: Ok, I've worked out that "storing" them in registers is stupid.

but do I for example use

lea variable, ebx

or

mov variable, ebx


Or something else to do this?
 
Declaring reserved memory and such for variables depends on the syntax of the particular assembler you're using. Theres no instructions, as such, for declaring a variable or how a variable is passed between functions, but there are assembler-specific directives for doing so.

To declare a 100-byte variable suitable for a string :

MASM: my_string db 100 dup (?)
NASM: my_string resb 100

In MASM, using a variable (label) name attempts to give the _value_ of the variable to the instruction you're using it with, whereas with NASM, it provides the address.

To get the address of the string (they all do the same thing, effectively)

MASM : mov edx, offset ptr my_string
MASM : lea edx, my_string
NASM : mov edx, my_string
NASM : lea edx, [my_string]

Now you have the address of the string in a register, you can write to the contents of the memory however you want, and pass the address to other functions if needed.

edit: I left out the GAS ways of doing it, since you said eax/ebx rather than %eax/%ebx :)
 
Back
Top Bottom