Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Source Help

Help with an "Array"

A community discussion post from the original code:zIRON forum.

Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

Help with an "Array"

Having some problems finding a way to make my default carddeck it´s basicly just an int array.

was thinking about switching to a linkedlist in which i also could store the names, but not sure.

function makedefaultdeck(DWord lang; int32* deck) {
	uses ecx ebx;
	// Make card deck
	ebx = lang;
	ecx = 0;
	while(ecx < 52) {
		deck[ecx] = ecx+1; // not sure the best way to do this in ziron
		ecx++;
	}
}

thanks in advance.

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

give something like this a try:

function makedefaultdeck(DWord lang; int32* deck) {
	uses edx; // if you really want to make sure edx is not changed;
                  // else it is not important

	// Make card deck
	// edx = lang; // didnt see this used so removed for now
	eax = 1;
	edx = deck;

	while (eax < 53) {
		[edx+eax-1] = eax;
		eax += 1;
	}
}
Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

Ah works as it should.. This is embarrasing.. i´ve basicly forgotten everything in the last 6-8months..

How would i print out the deck using in another function?

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b

Colin admin
Posts
928
Threads
49
Location
Bulgaria

don't quite understand your question but try along these lines:

procedure printdeck(int32* deck) {
	edx = deck;

	for (ecx = 0 to 52) {		
		print([edx+ecx], '\r\n'); 
	}
}

please explain a little more if this is not what you mean :)

Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

actually it was exactly what i meant but i got the same as when i made it.. a crash in the application. i will update compiler and try again.

if it doesn´t work i´ll send you the crash report information here later.

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b

Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

This is what i get in crashreport from drwatson32.exe when i try to run that procedure.

eax=00000000 ebx=7ffd4000 ecx=ffffffff edx=00402134 esi=00370031 edi=04030201 eip=00403223 esp=0012ff98 ebp=0012ffa0 iopl=0 nv up ei pl zr na po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246 funktion: testing
    00403212 0800             or      [eax],al
    00403214 55               push    ebp
    00403215 8bec             mov     ebp,esp
    00403217 57               push    edi
    00403218 51               push    ecx
    00403219 33c9             xor     ecx,ecx
    0040321b 8b7d08           mov     edi,[ebp+0x8]
    0040321e f7d1             not     ecx
    00403220 32c0             xor     al,al
    00403222 fc               cld
ERROR ->00403223 f2ae repne scasb es:04030201=??
    00403225 f7d1             not     ecx
    00403227 8d41ff           lea     eax,[ecx-0x1]
    0040322a 59               pop     ecx
    0040322b 5f               pop     edi
    0040322c c9               leave
    0040322d c20400           ret     0x4
    00403230 55               push    ebp
    00403231 8bec             mov     ebp,esp
    00403233 56               push    esi
    00403234 57               push    edi
----> Bakåtspårning i stacken <---- // Backtrace in stack WARNING: Stack unwind information not available. Following frames may be wrong. ChildEBP RetAddr Args to Child 0012ffa0 004033c7 04030201 00402134 00000000 string_sample+0x3223 0012ffb8 00403042 00402134 7c817067 00390034 string_sample+0x33c7 0012fff0 00000000 00403000 00000000 78746341 string_sample+0x3042

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b

Colin admin
Posts
928
Threads
49
Location
Bulgaria

That crash report looks very strange since a-lot of it looks messed up, also that is not showing the printdeck function I posted, can you show me exactly the function if you've made modifications too.

also try adding include for ch.zir

#include 'ch.zir';

just after your program declaration, and then to run it and tell me what it says then.

if the crash is only since printdeck try change it like so and let me know also:

procedure printdeck(int32* deck) {
  edx = deck;

  for (ecx = 0 to 52) {    
    eax = [edx+ecx];
    print(eax, '\r\n'); 
  }
}
Molotov member
Posts
49
Threads
21
Location
Behind Keyboard

Tried with #include 'ch.zir';

I get access violation error at adress 4207155

When i try the updated function i don´t see what i expected.

it should write: 1, 2, 3, 4, 5, and so on

But i get: 67305985, 84148994, 100992003, 117835012 and so on, then second to last it writes 52 then 0

does it write memory adresses? im lost.

"Lerning new things is what life is all about, if you are always doing the same old things day in and day out you might aswell just kill yourself." - ME d^_^b