Moving a Statement into Local Variable

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ClarionCoder51
Member
Member
Posts: 28
Joined: Sun Aug 16, 2009 11:52 am
Location: Georgia, USA

Moving a Statement into Local Variable

Post 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. ](*,)
"The n00b zone is for loading and unloading newbies only."
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Moving a Statement into Local Variable

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
kop99
Member
Member
Posts: 120
Joined: Fri May 15, 2009 2:58 am

Re: Moving a Statement into Local Variable

Post by kop99 »

You can use "movsX", "cmpsX" assembly command for string operations.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Moving a Statement into Local Variable

Post 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).
User avatar
ClarionCoder51
Member
Member
Posts: 28
Joined: Sun Aug 16, 2009 11:52 am
Location: Georgia, USA

Re: Moving a Statement into Local Variable

Post 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.
"The n00b zone is for loading and unloading newbies only."
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Moving a Statement into Local Variable

Post 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.
Post Reply