flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Release a variable

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 120

Release a variable

Hello:)
Would there be a macro instruction, a function, or even an instruction that would delete a variable? So it's impossible to reuse it after? I've been thinking about the free () function of the standard C library, but I don't know where and how to import/use it. As far as we can, and it answers my problem.

Thank you, and have a nice day!

_________________
The best way to predict the future is to invent it.
Post 15 Feb 2018, 10:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15808
Location: Misner space

What variable do you want to delete? I runtime variable in global space? A runtime variable in local space? An assembly time variable defined with "="? A preprocessor variable defined with "equ" or "define"?
Post 15 Feb 2018, 11:20
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 120

Here's a part of my code:

Code:

macro writeln text 
{
push text
call [printf]
push CRLF
call [printf]
}



CRLF is a variable that makes a return to line, here:

Code:

CRLF db '',13,10,0



When I call my macro, like that:

Code:

writeln MyText



Everything works well, so I get MyText with a return to line.
However, when I call a second time in a row writeln with a second variable:

Code:

writeln MyText
writeln MySecondText



I'm getting this:

Quote:

MyTextMySecondText
MySecondText



And of course, I would like him to show me this:

Quote:

MyText
MySecondText



I imagined, at the end of my macro, to delete the variable. But on second thought, I don't think that's the best way to do it.
Have I met your expectations?
Thank you Smile

_________________
The best way to predict the future is to invent it.
Post 15 Feb 2018, 11:43
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15808
Location: Misner space

CRLF is not actually a variable, it is a pointer. You can't delete it, it is part of the address space (presumably in global memory, but you don't show where it is).

But the code you posted doesn't appear to be wrong. Perhaps you can post an entire example that shows the problem.


Last edited by revolution on 15 Feb 2018, 13:25; edited 2 times in total
Post 15 Feb 2018, 12:44
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 120

Here's the complete code:

Code:

format PE console
entry main
include 'INCLUDE\win32a.inc'
section '.idata' data readable import
library msvcrt'msvcrt.dll',\
kernel32'kernel32.dll'
import msvcrtprintf'printf'
import kernel32ExitProcess'ExitProcess'
section '.data' data readable writeable
CRLF db '',13,10,0
ARGof_writeln1 db "Hello, world!"
ARGof_writeln2 db "Bonjour le monde !"
section '.code' code executable
macro writeln text 
{
push text
call [printf]
push CRLF
call [printf]
}
macro end 
{
call [ExitProcess]
}
main:
push eax
mov eaxecx
writeln ARGof_writeln1 
writeln ARGof_writeln2 
end  



_________________
The best way to predict the future is to invent it.
Post 15 Feb 2018, 13:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15808
Location: Misner space

The problem here is that you haven't terminated the strings.

Code:
ARGof_writeln1 db "Hello, world!",0 ;<--- add a terminating zero byte
ARGof_writeln2 db "Bonjour le monde !",0 ;<--- add a terminating zero byte

Post 15 Feb 2018, 13:10
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 120

It's a stupid mistake, actually.
Thank you for your help Smile
Post 15 Feb 2018, 13:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.