flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
LocoDelAssembly 14 Jan 2012, 19:29
You must have something wrong in how you check that int_var[0] is 50 (or the code is not an exact enough representation of your real compilable code). One mistake could be that you are pretending int_var[0] to be 4 bytes long (dword, int), so of course, when you write 30 in the second array slot you change the dword interpretation of int_var[0] to something different than 50 (50 + 30*2^8 + x*2^16 + y*2^24 = 7730 with x = y = 0 based on your experience when you don't write 30, but technically both x and y are unknown here).
Last edited by LocoDelAssembly on 14 Jan 2012, 19:34; edited 1 time in total |
|||
![]() |
|
Apos 14 Jan 2012, 19:34
Well... The 50 does end up being 7730... What do I have to do in order to only modify int_var[1]?
|
|||
![]() |
|
LocoDelAssembly 14 Jan 2012, 19:37
Then your number to string routine is working with the wrong size, you have byte sized numbers here, not dword. If you want int as per C definition then your code should be like this:
Code: int_var dd 2 dup(0) ... mov ecx, int_var ;ecx points to int_var mov dword [ecx], 50 ;int_var[0] = 50 add ecx, 4 ;ecx now points to int_var[1] mov dword [ecx], 30 ;int_var[1] = 30 sub ecx, 4 ;ecx now points to int_var[0] again |
|||
![]() |
|
Apos 14 Jan 2012, 19:42
That works. Thanks!
I think I used to do something like that in C when I was going to the next address. Can't remember correctly though... Skipping 4 rings a bell. _________________ "A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry |
|||
![]() |
|
AsmGuru62 15 Jan 2012, 15:27
I use a simple macro to write values into arrays:
Code: macro vSet32 vect,index,value { mov [vect + index*4], value } ... array dd 32 dup(0) ... mov esi, array vSet32 esi, 7, eax ; array[7]=eax vSet32 esi, 11, 627 ; array[11]=627 It is better to use a register as an index, because this instruction gets 3 bytes longer once an index exceeds 32. However, you also need to load that index into a register, which also takes room. You can make a macro for each data type, so you can't make that same mistake. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.