flat assembler
Message board for the users of flat assembler.

Index > Windows > [ SOLVED] Need help. Output arrays

Author
Thread Post new topic Reply to topic
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 12:44
Hello!
I am beginner at assembler
I can not bring an array of numbers to the console
Please help me Very Happy
Code:
format PE console
include 'win32axp.inc'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ns dd ?
hout dd ?
hinp dd ?

buffer dd 80 dup (?)
random_seed dd 0
zag    db 10,13,'Laboratory work',0
zag2   db 10,13,'Assembler. Compiled at Flat Assembler',0
zag3   db 10,13,'Compare two arrays and print numbers of iterations',0
msg1   db 10,13,'Arrays filling occurs automatically',0
msg2   db 10,13,'Options of filling : for 0 to 50',0
space  db 10,13,' ',0
output db 10,13,'The content of the array number 1:',0
output2 db 10,13,'The content of the array number 2:',0
output3 db 10,13,'Find equal:',0

Y dd  80 dup(?)
X dd  80 dup(?)
nWritten  dw ?
g_buffer rb  256
tmmp  dd ?
tmmp2 dd ?
inter dd ?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

start:

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [hout],eax

invoke GetStdHandle,STD_INPUT_HANDLE
mov [hinp], eax


invoke WriteConsole,[hout],addr zag,17,nWritten,NULL
invoke WriteConsole,[hout],addr zag2,39,nWritten,NULL
invoke WriteConsole,[hout],addr zag3,53,nWritten,NULL
invoke WriteConsole,[hout],space,1,nWritten,NULL
invoke WriteConsole,[hout],addr msg1,37,nWritten,NULL
invoke WriteConsole,[hout],addr msg2,34,nWritten,NULL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke WriteConsole,[hout],space,1,nWritten,NULL


mov edi,0
cycle50:
   cmp edi,324
   je tmp
   xor eax,eax
   stdcall RandomNum,0,50
   mov [Y+edi], eax
   xor eax,eax
   stdcall RandomNum,0,50
   mov [X+edi], eax
   add edi,4
jmp cycle50


tmp:
xor edi,edi
mov edi,g_buffer
xor edx,edx


cycle1:
cmp edx,320
 jg  theend
 mov eax,[Y+edx]
 call dec2str
 add edx,4
jmp cycle1
invoke WriteConsole,[hout],addr g_buffer,34,nWritten,NULL

theend:

invoke GetStdHandle,STD_INPUT_HANDLE
invoke ReadConsole,eax,buffer,10,ns,NULL
invoke ExitProcess,0



proc RandomNum,Min,Max   ; eax ---randomed number
        push ecx edx ebx edi esi
        rdtsc
        xchg    esi,eax
        xchg    edi,edx
        rdtsc
        xor     eax,edi
        xor     edx,esi
        xor     edx,edx
        mov     ecx,[Max]
        add     ecx,1h
        sub     ecx,[Min]
        div     ecx
        add     edx,[Min]
        mov     eax,edx
        pop esi edi ebx edx ecx
        ret
endp

dec2str:
        ; EAX = value
        ; EDI = buffer
        mov     ecx,10
    .stack_dec:
        xor     edx,edx
        div     ecx
        add     edx,'0'
        push    edx
        test    eax,eax
        jz      .purge_dec
        call    .stack_dec
    .purge_dec:
        pop     dword[edi]
        inc     edi
        ret
.end start                     


Last edited by DarkHunter on 22 Jun 2011, 15:35; edited 1 time in total
Post 22 Jun 2011, 12:44
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1389
Location: Piraeus, Greece
Picnic 22 Jun 2011, 14:23
Here is a something to start,

You are using edx to loop inside cycle1 but dec2str destroys edx.
Post 22 Jun 2011, 14:23
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 22 Jun 2011, 14:38
For starters, you are not resetting edi to g_buffer after you call dec2str.
Post 22 Jun 2011, 14:38
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 22 Jun 2011, 14:42
Hey, i wrote that one: dec2str in my BitBox utility Smile
It uses call/ret stacking which is why we cant preserve regs.
A better way is to count and use stack manually w/out call/ret.
Code:
dec2str:
        ; EAX = value 
        ; EDI = buffer 
        pusha
        mov     ebx,10
        xor     ecx,ecx
    .stack_dec: 
        xor     edx,edx 
        div     ebx
        add     edx,'0' 
        push    edx
        inc     ecx
        test    eax,eax 
        jnz     .stack_dec
    .purge_dec: 
        pop     eax
        stosw
        dec     edi
        loop    .purge_dec
        popa
        ret
    

I didnt test this but it looks correct, just drop it in place and go.


Last edited by bitshifter on 23 Jun 2011, 13:42; edited 1 time in total
Post 22 Jun 2011, 14:42
View user's profile Send private message Reply with quote
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 14:44
I 2 days trying to solve this problem ... This code is already 10th:)
At the beginning of visible variables tmmp, tmmp2, inter ... They have been used in my attempts ... If you specify the output without the loop, everything works

bitshifter, one minutes...
Post 22 Jun 2011, 14:44
View user's profile Send private message Reply with quote
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 14:51
Update:
if we use:
Code:
dec2str:
        ; EAX = value 
        ; EDI = buffer 
        pusha
        mov     ebx,10
        xor     ecx,ecx
    .stack_dec: 
        xor     edx,edx 
        div     ebx
        add     edx,'0' 
        push    edx
        inc     ecx
        test    eax,eax 
        jnz     .stack_dec
    .purge_dec: 
        pop     eax
        stosw
        loop    .purge_dec
        popa
        ret                

as I have in the title, it does not show
if we use you code + invoke WriteConsole in cycle1 then it print 1-2 elements and break Smile
Post 22 Jun 2011, 14:51
View user's profile Send private message Reply with quote
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 14:58
Code:
format PE console
include 'win32axp.inc'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ns dd ?
hout dd ?
hinp dd ?
buffer dd 80 dup (?)
random_seed dd 0
zag    db 10,13,'Laboratory work',0
zag2   db 10,13,'Assembler. Compiled at Flat Assembler',0
zag3   db 10,13,'Compare two arrays and print numbers of iterations',0
msg1   db 10,13,'Arrays filling occurs automatically',0
msg2   db 10,13,'Options of filling : for 0 to 50',0
space  db 10,13,' ',0
output db 10,13,'The content of the array number 1:',0
output2 db 10,13,'The content of the array number 2:',0
output3 db 10,13,'Find equal:',0

Y dd  80 dup(?)
X dd  80 dup(?)
nWritten  dw ?
g_buffer rb 500
tmmp  dd ?
tmmp2 dd ?
inter dd ?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

start:

invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [hout],eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov [hinp], eax


invoke WriteConsole,[hout],addr zag,17,nWritten,NULL
invoke WriteConsole,[hout],addr zag2,39,nWritten,NULL
invoke WriteConsole,[hout],addr zag3,53,nWritten,NULL
invoke WriteConsole,[hout],space,1,nWritten,NULL
invoke WriteConsole,[hout],addr msg1,37,nWritten,NULL
invoke WriteConsole,[hout],addr msg2,34,nWritten,NULL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke WriteConsole,[hout],space,1,nWritten,NULL

mov edi,0
cycle50:
   cmp edi,324
   je tmp
   xor eax,eax
   stdcall RandomNum,0,50
   mov [Y+edi], eax
   xor eax,eax
   stdcall RandomNum,0,50
   mov [X+edi], eax
   add edi,4
jmp cycle50


tmp:
xor edi,edi
mov edi,g_buffer
xor edx,edx


cycle1:
cmp edx,320
 je  theend
 mov eax,[Y+edx]
 call dec2str
 invoke WriteConsole,[hout],addr g_buffer,3,nWritten,NULL
 add edx,4
jmp cycle1


theend:
popad
invoke GetStdHandle,STD_INPUT_HANDLE
invoke ReadConsole,eax,buffer,10,ns,NULL
invoke ExitProcess,0



proc RandomNum,Min,Max   ;eax
        push ecx edx ebx edi esi
        rdtsc
        xchg    esi,eax
        xchg    edi,edx
        rdtsc
        xor     eax,edi
        xor     edx,esi
        xor     edx,edx
        mov     ecx,[Max]
        add     ecx,1h
        sub     ecx,[Min]
        div     ecx
        add     edx,[Min]
        mov     eax,edx
        pop esi edi ebx edx ecx
        ret
endp

dec2str:
        ; EAX = value 
        ; EDI = buffer 
        pusha
        mov     ebx,10
        xor     ecx,ecx
    .stack_dec: 
        xor     edx,edx 
        div     ebx
        add     edx,'0' 
        push    edx
        inc     ecx
        test    eax,eax 
        jnz     .stack_dec
    .purge_dec: 
        pop     eax
        stosw
        loop    .purge_dec
        popa
        ret

.end start     


Olly Dbg say to me "Access violation in...":
00402115 |. 8B82 64124000 |MOV EAX,DWORD PTR DS:[EDX+401264]
This is a mov eax,[Y+edx] at cycle1[code]
Post 22 Jun 2011, 14:58
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 22 Jun 2011, 15:05
Code:
format PE console
include 'win32axp.inc' 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.data 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ns dd ? 
hout dd ? 
hinp dd ? 

buffer dd 80 dup (?) 
random_seed dd 0 
zag    db 10,13,'Laboratory work',0 
zag2   db 10,13,'Assembler. Compiled at Flat Assembler',0 
zag3   db 10,13,'Compare two arrays and print numbers of iterations',0 
msg1   db 10,13,'Arrays filling occurs automatically',0 
msg2   db 10,13,'Options of filling : for 0 to 50',0 
space  db 10,13,' ',0 
output db 10,13,'The content of the array number 1:',0 
output2 db 10,13,'The content of the array number 2:',0 
output3 db 10,13,'Find equal:',0 

Y dd  80 dup(?) 
X dd  80 dup(?) 
nWritten  dw ? 
g_buffer rb  256 
tmmp  dd ? 
tmmp2 dd ? 
inter dd ? 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.code 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

start: 

invoke GetStdHandle,STD_OUTPUT_HANDLE 
mov [hout],eax 

invoke GetStdHandle,STD_INPUT_HANDLE 
mov [hinp], eax 


invoke WriteConsole,[hout],addr zag,17,nWritten,NULL 
invoke WriteConsole,[hout],addr zag2,39,nWritten,NULL 
invoke WriteConsole,[hout],addr zag3,53,nWritten,NULL 
invoke WriteConsole,[hout],space,1,nWritten,NULL 
invoke WriteConsole,[hout],addr msg1,37,nWritten,NULL 
invoke WriteConsole,[hout],addr msg2,34,nWritten,NULL 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
invoke WriteConsole,[hout],space,1,nWritten,NULL 


mov edi,0 
cycle50: 
   cmp edi,324 
   je tmp 
   xor eax,eax 
   stdcall RandomNum,0,50 
   mov [Y+edi], eax 
   xor eax,eax 
   stdcall RandomNum,0,50 
   mov [X+edi], eax 
   add edi,4 
jmp cycle50 


tmp:
mov edi,g_buffer 
xor edx,edx 


cycle1: 
cmp edx,320 
 jg  theend 
 mov eax,[Y+edx] 
 call dec2str 
 add edx,4
 mov al,' '
 stosb
jmp cycle1 

theend:
  mov al,0
  stosb
invoke WriteConsole,[hout],addr g_buffer,34,nWritten,NULL
invoke GetStdHandle,STD_INPUT_HANDLE 
invoke ReadConsole,eax,buffer,10,ns,NULL 
invoke ExitProcess,0 



proc RandomNum,Min,Max   ; eax ---randomed number 
        push ecx edx ebx edi esi 
        rdtsc 
        xchg    esi,eax 
        xchg    edi,edx 
        rdtsc 
        xor     eax,edi 
        xor     edx,esi 
        xor     edx,edx 
        mov     ecx,[Max] 
        add     ecx,1h 
        sub     ecx,[Min] 
        div     ecx 
        add     edx,[Min] 
        mov     eax,edx 
        pop esi edi ebx edx ecx 
        ret 
endp 

dec2str:
        ; EAX = value  
        ; EDI = buffer  
        push    edx
        mov     ebx,10 
        xor     ecx,ecx 
    .stack_dec:  
        xor     edx,edx  
        div     ebx 
        add     edx,'0'  
        push    edx 
        inc     ecx 
        test    eax,eax  
        jnz     .stack_dec 
    .purge_dec:  
        pop     eax
        stosb
        loop    .purge_dec 
        pop     edx
        ret 

.end start
    
Post 22 Jun 2011, 15:05
View user's profile Send private message Reply with quote
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 15:15
Bitshifter, thanks!
Sorry for my English - do not get anything priumyvat ... tired

A: No. This is part of the laboratory work of the university. This is the first laboratory in assembly language. Many simply learn by lecture, but these records are interrupt-DOS and 16-bit code. I wanted to explore more deeply.
Post 22 Jun 2011, 15:15
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 22 Jun 2011, 15:18
No need to apologize for english, ever.
I wish i could go to university laboratory.
Post 22 Jun 2011, 15:18
View user's profile Send private message Reply with quote
DarkHunter



Joined: 22 Jun 2011
Posts: 6
DarkHunter 22 Jun 2011, 15:30
del
Post 22 Jun 2011, 15:30
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 23 Jun 2011, 13:40
The code still has problems, i only made the dec2str part work.
I leave the rest as an exercise to you for fixing it up.
Post 23 Jun 2011, 13:40
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


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

Website powered by rwasa.