flat assembler
Message board for the users of flat assembler.
Index
> Windows > [ SOLVED] Need help. Output arrays |
Author |
|
Picnic 22 Jun 2011, 14:23
Here is a something to start,
You are using edx to loop inside cycle1 but dec2str destroys edx. |
|||
22 Jun 2011, 14:23 |
|
mindcooler 22 Jun 2011, 14:38
For starters, you are not resetting edi to g_buffer after you call dec2str.
|
|||
22 Jun 2011, 14:38 |
|
bitshifter 22 Jun 2011, 14:42
Hey, i wrote that one: dec2str in my BitBox utility
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 |
|||
22 Jun 2011, 14:42 |
|
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... |
|||
22 Jun 2011, 14:44 |
|
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 |
|||
22 Jun 2011, 14:51 |
|
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] |
|||
22 Jun 2011, 14:58 |
|
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 |
|||
22 Jun 2011, 15:05 |
|
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. |
|||
22 Jun 2011, 15:15 |
|
bitshifter 22 Jun 2011, 15:18
No need to apologize for english, ever.
I wish i could go to university laboratory. |
|||
22 Jun 2011, 15:18 |
|
DarkHunter 22 Jun 2011, 15:30
del
|
|||
22 Jun 2011, 15:30 |
|
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. |
|||
23 Jun 2011, 13:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.