flat assembler
Message board for the users of flat assembler.

Index > Windows > Push address for scanf

Author
Thread Post new topic Reply to topic
zeritonik



Joined: 10 Jul 2022
Posts: 1
zeritonik 10 Jul 2022, 16:26
I want to input array using scanf, but I don't know the proper way to do push address of element.
Code:
LENGTH = 4
ELEMENT = 2
arr rw LENGTH
scanf_si db "%hi", 0

mov ecx, LENGTH
mov di, 0
input_arr:
push arr + di ; invalid expression
push scanf_si
call [scanf]
add di, ELEMENT
loop input_arr
    

If I store array address in register and push it, code will work fine, but I know, that address can be calculated this way in some situations. I want to know if I can push address without using registers[/b]
Post 10 Jul 2022, 16:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 10 Jul 2022, 18:23
Code:
arr rb LENGTH ; you probably want to reserve bytes, not words
push arr ; use the address directly    
Post 10 Jul 2022, 18:23
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1660
Location: Toronto, Canada
AsmGuru62 10 Jul 2022, 21:19
Also, call to [scanf] will most likely destroy ECX register and LOOP instruction will continue for more times, or less, than needed.
Post 10 Jul 2022, 21:19
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 10 Jul 2022, 21:59
I missed that you are using di as an index. You can do this:
Code:
mov di, arr
push di
;....
add di, ELEMENT
;...    
Post 10 Jul 2022, 21:59
View user's profile Send private message Visit poster's website 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.