Page 1 of 1
Moving a Statement into Local Variable
Posted: Thu Aug 20, 2009 4:49 pm
by ClarionCoder51
I am attempting to put the prompt letter into a local variable. The only problem is, I need to know HOW to DEFINE a variable and HOW to move a text value, like
'A>', into it using it in a
mov statement. Every single possible combination of syntax and code that I could come up with doesn't work, so I'm hoping someone will atleast throw out an innertube so I won't drown in code in my sleep.
Re: Moving a Statement into Local Variable
Posted: Thu Aug 20, 2009 5:18 pm
by Troy Martin
EDIT: reading over your previous topic, I've shaved some stuff off.
Write a callable function called, say, strcpy, that copies a null-terminated string byte-by-byte from a string pointed to by SI to an array of bytes (another string, hehe) in DI. Voila.
You can't move/copy strings with the MOV instruction.
Re: Moving a Statement into Local Variable
Posted: Thu Aug 20, 2009 9:31 pm
by kop99
You can use "movsX", "cmpsX" assembly command for string operations.
Re: Moving a Statement into Local Variable
Posted: Fri Aug 21, 2009 2:35 am
by qw
You don't need a string if the prompt is just one letter.
Code: Select all
[section .data]
prompt_letter: db 0
[section .code]
mov byte [prompt_letter], 'A'
Maybe you'd better show us your code and tell us what assembler you are using (the above example is in NASM syntax).
Re: Moving a Statement into Local Variable
Posted: Fri Aug 21, 2009 4:44 am
by ClarionCoder51
Ok. In order to add '>' I would just call a separate string, like
Code: Select all
[section .data]
prompt_letter: db 0
prompt_arrow: db '>'
[section .code]
mov byte [prompt_letter], 'A'
lea si, prompt_letter
call print_string ; <--- That functon prints the string to vid memory
lea si, prompt_arrow
call print_string
...assuming that [prompt_letter] doesn't do a char return and puts '>' on the next line, which it shouldn't.
Re: Moving a Statement into Local Variable
Posted: Fri Aug 21, 2009 5:14 am
by qw
In NASM syntax, "lea si, prompt_arrow" should be "lea si, [prompt_arrow]" or a plain "mov si, prompt_arrow". And "print_string" should be printing a character, not a string.
Again, you'd better show us your code and tell us what assembler you are using.