TEST db "test",0 mov eax,offset TEST mov dl, ; <-- will DL hold "t" in it ? mov dl, ; <-- will DL hold "e" in it ? if not, then how it is done ? why isn't refers to the contents of what is in address eax ?
Posted on 2001-03-02 15:51:00 by Peham
Peham, Try this,


    .data
    test db "test",0
    .code

    mov eax, offset test
    mov dl, byte ptr   ; "t"
    mov dh,          ; "e"
    mov cl,          ; "s"
    mov ch,          ; "t"
The BYTE size register specifies the size of the data being copied so you don't have to use "byte ptr" in this context. Regards, hutch@pbq.com.au This message was edited by hutch--, on 3/2/2001 4:55:06 PM
Posted on 2001-03-02 16:54:00 by hutch--
We can not use Test. test is a reserved text like mov ... We can use xtest or xmov. Ok, I also have a source: .386 .Model Flat ,StdCall option casemap:none include \masm32\include\windows.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib GetModuleHandleA PROTO :DWORD MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD ExitProcess PROTO :DWORD .Data xTEST db "test",0 ;Don't use TEST OK_t_Title db "Error encountered",0 OK_t_TextError db "t not found.",0 OK_e_Title db "Error encountered",0 OK_e_TextError db "e not found",0 FullOK_Title db "Everything works fine",0 FullOK_Text db "Well done.",0 .data? hInstance dd ? .Code Main: push 0h ;lpModuleHandle, 0=get program handle call GetModuleHandleA ;- API Function - mov hInstance,eax ;return value in eax=handle of program mov eax,offset xTEST mov dl, ; <-- will DL hold "t" in it ? cmp dl,74h ;is it ascii 't' ? je OK_t ;yes ;------------------------------------------------------------------------------ ; API "MessageBoxA" creates a message box ... ;------------------------------------------------------------------------------ push 0h ;uType, style, 0=MB_OK Button push OFFSET OK_t_Title ;lpCaption,pointer to title text push OFFSET OK_t_TextError ;lpText,pointer to text message box push 0h ;handle of owner window call MessageBoxA ;- API Function - jmp ExitPrg OK_t: mov dl, ; <-- will DL hold "e" in it ? cmp dl,65h ;is it ascii 'e' ? je OK_e ;yes ;------------------------------------------------------------------------------ ; API "MessageBoxA" creates a message box ... ;------------------------------------------------------------------------------ push 0h ;uType, style, 0=MB_OK Button push OFFSET OK_e_Title ;lpCaption,pointer to title text push OFFSET OK_e_TextError ;lpText,pointer to text message box push 0h ;handle of owner window call MessageBoxA ;- API Function - jmp ExitPrg OK_e: ;------------------------------------------------------------------------------ ; API "MessageBoxA" creates a message box ... ;------------------------------------------------------------------------------ push 0h ;uType, style, 0=MB_OK Button push OFFSET FullOK_Title ;lpCaption,pointer to title text push OFFSET FullOK_Text ;lpText,pointer to text message box push 0h ;handle of owner window call MessageBoxA ;- API Function - ExitPrg: push hInstance ;push our programm handle to exit call ExitProcess ;- API Function - end Main ;end of our program code, entry point ;============================================================================== ; To create the exe file use this commands with your Microsoft Assembler/Linker ;------------------------------------------------------------------------------ ; ml.exe /c /coff movEAX.asm ; link.exe /subsystem:windows movEAX.obj
Posted on 2001-03-02 17:37:00 by Test Department
TD, Thanks, its senile decay at 7am. Peham, TEST is an Intel mnemonic so the name cannot be used for a variable as well. Substitute this for the version above. .data Mytest db "test",0 .code mov eax, offset Mytest mov dl, byte ptr ; "t" mov dh, ; "e" mov cl, ; "s" mov ch, ; "t" Regards, hutch@pbq.com.au
Posted on 2001-03-02 18:51:00 by hutch--
To help clear up the confusion with byte ptr and , here are some basic examples:

mov dh, 
Here, the compiler knows 'dh' is 8 bits, and your intructing the processor to fill 'dh' with the value ([...]) found at the address of eax. Since the compiler knows the boundry is 8 bits, implied by the register 'dh' in the destonation, there is no problem at all.

mov dh, byte prt 
IS THE EXACT SAME THING.. (it is just over kill, and maybe a bit more readable) So, why would you want to use byte ptr or word ptr preceeding an "at-the-address-of" ([...]) statement?? The answer is seen here:

; ebx == some address
mov , 3
Here is a delema for the compiler, it says "move the value three to the memory location at the address of ebx". Sounds straight forward, but the compiler likes to think in bits, and then WANTS to ask back "so is 3 a byte?, or is it a word?, how about a DWORD...?". It doesnt know how many bits of memory to use to store the given value!! To correctly perform this, you then use the byte ptr to store 3 in one byte of memory at the specified address (and likewise word ptr would use up 2 bytes of memory to store 3 in memory, etc.) Proper solution:

; ebx == some address
mov byte ptr , 3
The memory location would look like: (remember little endian) Before: Some address: A4 02 87 .. .. After: Some Address: 03 02 87 .. .. If the mov was:

; ebx == some addrss
mov word ptr , 3
Before: Some address: A4 02 87 .. .. After: Some Address: 03 00 87 .. .. Bottom line, if your thinking you need to use (...) ptr, ask youself if the computer can figure out how many bits to move, by some DIRECT indication (like 'dh'). I hope this helps... NaN This message was edited by NaN, on 3/2/2001 11:46:38 PM
Posted on 2001-03-02 23:43:00 by NaN
ok. i just gave an example. i know "test" is reserved. let's suppose this : -.data? -TEST dd 10 dup(?) -.code -mov eax,offset TEST ; <---- let's say EAX now contains "406060". mov ,10 ;<---- 1 mov ,20 ;<---- 2 does left exp. equals to "[406064]" ? or is "2" should be : mov ,20 ;<---- 3 (because i address DWORD var)
Posted on 2001-03-03 03:59:00 by Peham
Ok here is the deal, First off, i actually tried your version (mov ,10), as i never had and wondered if it would work. The answer is no, you can not put the 'xxx prt' information within the "at-the-address-of" ( [..] ) operators. The answer to your question is: no to #2, and #3 in concept is correct. Remember that eax hold only a number. Thats it. How you choose to use that number is up to you. The compiler 'could' be made to realize your scenario #2, but then you would be restriced from accessing say bits 8-15 of a dword if you needed to in this style. For this reason it is simpler overall to leave it up to the programmer to 'KNOW' how many bytes to offset. Here is an example:

    .data
       tesst    db 100 dup(0)

    .code
         ...
        .elseif wParam == 1011
            
            mov  eax, offset tesst
            mov dword ptr , 35363738h   ; tesst: 38 37 36 35 00 00 .. ..
            mov dword ptr ,30303030h ; tesst: 38 30 30 30 30 00 .. ..
            
            invoke MessageBox,hWin,ADDR tesst,ADDR szDisplayName,MB_OK
So the message box, to no surprise has the number: "80000" in its display. ( 3xh are numbers in ascii where x is the # if your not familiar with this ). Notice the first byte in memory has presisted, as the i instructed in the second mov operation to add 1 to the number in eax, which represents (to us humans) an address in memory. If the offest was 4, the message would be: "87650000", as you were inquiring about. Hope this helps clear the confusion. NaN This message was edited by NaN, on 3/3/2001 5:01:09 PM
Posted on 2001-03-03 16:51:00 by NaN