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 > Main > The right way to declare two dimensional array :/

Author
Thread Post new topic Reply to topic
Szustarol



Joined: 11 Jul 2016
Posts: 9
The right way to declare two dimensional array :/
Hi!
I have searched whole internet and found 2 ways of declaring 2d arrays:
(i want to declare array of the size of default windows console)
areatodraw TIMES 25*80 db 0x00
or
areatodraw db 25 dup(80 dup(0x00))
none seems to work when i try to draw end of line character to the last char
in row
i calculate the adress like this- (row-1)*lenghtofrow+positioninrow
mov areatodraw[0x50], 0x8A

im not sure why it isint working maybe i move the value wrong way, can anyone help?
Post 11 Jul 2016, 08:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15295
Location: Bigweld Industries
Show your code.
Post 11 Jul 2016, 09:02
View user's profile Send private message Visit poster's website Reply with quote
Szustarol



Joined: 11 Jul 2016
Posts: 9

Code:
format PE console
entry start 
include 'include/win32a.inc' 

section '.text' code executable
        start:

        stlp:
              push 200
              call [Sleep]
              add esp0x04
              call CHECKFORCHAR
              push EAX
              push intbuff
              call [printf]
              add esp0x08
              push space
              push strbuff
              call [printf]
              add esp0x08
              jmp stlp
              koniec:
              push 0
              call [ExitProcess]
        CHECKFORCHAR:
                push ebp
                call [_kbhit]
                cmp EAX0
                je nopress
                call [_getch]
                cmp EAX0xE0
                jne nopress
                call [_getch]
                nopress:
                pop ebp
                ret
        FILLAREA:
                push ebp
                mov ebxareatodraw[0x50]
                mov ebx0x8A
                pop ebp
                ret

section '.data' data readable writeable
        intbuff db '%d'0
        strbuff db '%s'0
        space db ' '0
        areatodraw db 25 dup(80 dup(0x00))
section '.idata' data readable import 
        library kernel32'kernel32.dll'msvcrt'msvcrt.dll'
        import kernel32ExitProcess'ExitProcess'Sleep'Sleep'GetModuleHandle,'GetModuleHandleA'
        import msvcrtscanf'scanf'printf'printf'_kbhit'_kbhit'_getch'_getch'


i get the "Extra characters on line" error when array element is moved to ebx

Also another question does the windows Sleep function remove its parameter from stack automatically? I noticed if i add 0x04 to esp after calling sleep after some time program crashes when it reaches bottom of the stack, when i dont do this program runs just fine
Post 11 Jul 2016, 09:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15295
Location: Bigweld Industries
"areatodraw" is just a pointer. You can access bytes by simple addition:

Code:
mov ebxareatodraw + 0x50 ;offset 0x50 bytes


Szustarol wrote:
Also another question does the windows Sleep function remove its parameter from stack automatically? I noticed if i add 0x04 to esp after calling sleep after some time program crashes when it reaches bottom of the stack, when i dont do this program runs just fine

All Windows API calls (except for WSPRINTF) use STDCALL convention, so you should normally have no need to manually adjust ESP after calling.
Post 11 Jul 2016, 10:27
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.