![]() |
|
|
#1 |
|
Guest
Posts: n/a
|
Yea, i know what you think, no data types in asm. You are right so shut up and read! Smile
Well there is nothing special about memory. Its an addressable space which contains data. Application allocates or deallocated memory so it can have more memory if needed. Smallest cell (if we can call it like that) of memmory is called a bit. Bit can be either 0 or 1. Bits are not addressable in memory. However we can get bit values using bit shifting in c++, dunno how to do that in asm, but for you, newbies, its not *must to know* info. Bigger data type will be byte. It can get any value from 0 to 255. 1 byte = 8 bits. Bytes are addressable data type so you can reach any byte in app if you know its address. Version of byte in asm will be al, ah, bl, bh and so on. How do we know these byte registers? Its simple, wanna make rax to contain byte value? see, rax is 64 bit value of ax register (ax is 16 bits), ax can return its high bytes or low bytes. so al is lower bytes of ax and ah is higher part of the ax bytes. You can put in 2 bytes in ax, store two values in one register. This is cool actualy Very Happy Next data type is 2 bytes or 16 bits. It is contained in ax, bx, cx etc.. registers. 32 bit values are contained in eax, ebx, ecx etc... registers, see, e letter appears in front of ax, it means extended ax. and finaly our beloved 64bit registers: rax, rbx. rcx.... here r appears in front of register. i dont remmember wtf it means but its not important any way, what is important is that these registers can carry looooooots of data. maybe you dont think that 8 bytes are a lot, but they are. Incredible numbers are stored in 64bit integers. In example everyone knows function time(). it returns time in seconds counted from 1970 01 01 (if my memory does not fail me) - start of the unix era. At some point 32 bit integer became just too small to contain count of the secconds that passed from that time. Well, 64bit integers saved us! k, now we know what data types we can have in asm, now we need to know how correctly to put them into memory. Code: Code:
mov rax, 123456h ;we put address of space in memory to rax register mov [rax], 1 ;here we move 1 to the location of rax Code: Code:
mov rax, 123456h mov rbx, [rax] now be avare of one thing! if you want to read 16 bits of data, read 16 bits! Same is for writing data. this is how we do that: Code: Code:
mov rax, 123456h mov bx, [rax] example of writing data: Code: Code:
mov [rax], bx what if you have address of something in rax and you know stuff you need is somewhere in address relative to rax, about 0x10 bytes further? not a problem! we do it like this: Code: Code:
lea rax, [rax+10h] Code: Code:
add rax, 10h instead of this: Code: Code:
mov rax, rbx add rax, 10h Code: Code:
lea rax, [rbx+10h] ah, al - bool, char ax - small int eax - int SIZE in x86 platform rax - __int64 SIZE_T in x64 platform So thats it i think. Now you know how to manipulate memory addresses, how to move suoff to and from memory, how to move correct size of needed memory... Good luck in extending l2server ;] Some useful stuff by others: Quote: Originally Posted by Fr3DBr ax = short =) "okay it can be a wchar_t but why making things complicated ? bool = logical condition var (true/false) takes 1 bit... but it fits a byte in win32/64 platform. char = 1 byte (Win32/64) wchar_t = 2 bytes (Win32/64) Used to Store Extended Characters (AKA Unicode) short = 2 bytes (Win32/64) int = 4 bytes (Win32/64) int64 = 8 bytes (Win32/64) long = 4 bytes (Win32/64) long long = 8 bytes (Win32/64) al = 1 byte -> bool or char ax = 2 bytes -> short or wchar_t eax = 4 bytes -> int, long or short (depends of platform) rax = 8 bytes -> int, long, int64, long long (depends of platform) xmmX = 16 bytes -> no equivalence, you have to split the value in 2 integers ou doubles. There are more that are even specific... (X64) Quote: Originally Posted by Fyyre I also recommend http://vx.org.ua/29a/29a-4/29a-4.215 if you're looking to make smaller code... Восстановлено из публичного снимка Wayback Machine. Тема могла сохраниться частично. В снимке указана только дата, без времени: 1 April 2008. Открыть источник. |
|
|