1. I saw many times :
print chr$ ("hello world")
But
print "hello world"
works perfectly. So why bother with the chr$ macro to display a string ?
2. Another question : how to display a string stored in memory like this one :
hello byte "hello world !"
3. And is that the right way to store a string in memory, or there's another one.
Thank you.
.DATA
hello db 'Hello World',0
.CODE
print offset hello
you could also
mov eax,offset hello
print eax
i didn't know the print macro would do that - it probably uses chr$, though :U
the chr$ macro creates a string similar to the one we defined, and passes the address
the advantage is - you can see the text inline
the disadvantage is - you only get that address once - with the DB method, you can access the label as many times as you like
the chr$ macro is used to create a string with multiple elements
mov ecx, chr$("hello", 13, 10, "world", 13, 10)
is the same as
.data
str1 BYTE "hello", 13, 10, "world", 13, 10, 0
.code
mov ecx, OFFSET str1
print "Hello", 13, 10 is also valid syntax, i.e. you can append a CrLf that way.
lea eax, hello
is the same as
mov eax, offset hello
Not sure which is better though, I haven't studied it that in depth before.
LEA is generally used if the address is on the stack, however it has other uses
MOV is smaller or faster - i forget which - lol
LEA calculates and Loads the Effective Address
if the address is a constant, there is no need to do all that - just use MOV
LEA can also be used to make calculations without altering the flags
lea edi,[edi+4] ;adds 4 to EDI
it is used for other similar tricks, too
I think it was mostly due to the flags that our instructor (whew! almost 20 years ago) suggested we use LEA... at that time we used the flags for quite a number of conditionals.
well - it is an easy way to avoid problems with local variables, too
if you try to use MOV with OFFSET of a local, it spits out an error, of course
knowing when to use LEA/MOV or ADDR/OFFSET is a little like learning to balance the stack :P
Quote from: dedndave on February 21, 2011, 06:00:43 PM
knowing when to use LEA/MOV or ADDR/OFFSET is a little like learning to balance the stack :P
I really need to find and break out some books and re-study those little things. I miss my QUE books for advanced assembly. :(