News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MASM High Level Questions

Started by n00b!, June 10, 2008, 10:28:15 AM

Previous topic - Next topic

jj2007

Masm can be sure that [eax+ecx] is a 32-bit address. So far, so good...

cmp [eax + ecx], 22h  ; so what do you mean here, the byte 22h, the word 22h, or the dword 22h?

cmp [eax + ecx], ax  ; you mean the word ax
cmp [eax + ecx], al   ; you mean the byte al
cmp [eax + ecx], ah  ; you mean the byte ah, thanks for telling me...

Hope it's clear enough...

n00b!

1. Ah, ok.
But what do I have to write instead of
cmp [eax + ecx], 22h


2. Sorry, i missed something:

.data
  text db "test",0

.code
  mov [edx + text], al


I used inside the brackets a variable..
I noticed that when i declare text as DWORD I have to use eax instead of al...
But how exactly does a variable effect the whole instruction?

hutch--

noob,

The problem is that MASM is a fully specified language which means that it can handle the notation that specifies the size of a memory operand but it is also smart enough to know the memory size in most instances. When it cannot it displays an error if the size is not specified.


cmp [eax + ecx], 22h


The problem here is that [eax+ecx] is a memory address and there is no way to determine if you write a BYTE, WORD or DWORD to that address.

To clear this up so the assembler knows what size it should be you specify the size as follows.


cmp BYTE PTR [eax+ecx], 22h


If its a 16 bit value use WORD and if its a 32 bit value use DWORD.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

n00b!

Ah.. Ok, so... would the following be correct?

mov [eax+ ebx], BYTE ptr [ecx + edx]         ;MASM know the size (BYTE ptr)

mov BYTE ptr [eax + ebx], [ecx + edx]        ;MASM know the size (BYTE ptr)

mov eax, [ecx + edx]                         ;MASM know the size (eax = 4bytes)

mov [ecx + edx], bx                          ;MASM know the size (bx  = 2bytes)

mov [eax+ ebx], [ecx + edx]                  ;would not work, MASM don't know the size

mov al, 22h                                  ;MASM know the size (al  = 1byte)


text db "Hello", 0

mov [edx + text], 22h                        ;MASM know the size (text = 1byte)??

num dd 55

mov eax, [num + ecx]                         ;MASM know the size (num  = 4bytes)??

mov bl, [num + ecx]                          ;would not work, bl = 1byte/num = 4bytes??

mov bl, BYTE ptr [num + ecx]                 ;MASM know the size (BYTE ptr)??


Is  "[num + ecx]"  equal  "addr num + ecx"  or  "55 + ecx"?

jj2007

Well, more or less. Why don't you just put it in some proggie and wait for the error messages?

No 1, 2, 5 don't work because there is no direct move from memory to memory. You can use the m2m macro but only for DWORDS.

; mov [eax+ ebx], BYTE ptr [ecx + edx]         ;MASM know the size (BYTE ptr)
; mov BYTE ptr [eax + ebx], [ecx + edx]        ;MASM know the size (BYTE ptr)
mov eax, [ecx + edx]                         ;MASM know the size (eax = 4bytes)
mov [ecx + edx], bx                          ;MASM know the size (bx  = 2bytes)
; mov [eax+ ebx], [ecx + edx]                  ;would not work, MASM don't know the size
mov al, 22h                                  ;MASM know the size (al  = 1byte)
mov [edx + text], 22h                        ;MASM know the size (text = 1byte)??
mov eax, [num + ecx]                         ;MASM know the size (num  = 4bytes)??
; mov bl, [num + ecx]                          ;would not work, bl = 1byte/num = 4bytes??
mov bl, BYTE ptr [num + ecx]                 ;MASM know the size (BYTE ptr)??

jj2007

Here is a skeleton for testing what works and what doesn't. Code before "start:" will be assembled but not executed, so you can use the area between .code and start: for testing syntax.

include \masm32\include\masm32rt.inc

.data?
buffer db 256 dup (?)

.data
AppName  db "Test bits and pieces:", 0
MyDword dd 12345678
MyWord dw 12345
MyByte db 123
MyText db "This is a simple test", 0
num dd 123
text db "test test", 0

.code
; ---------- for syntax checks, use the area between <code> and <start> -------------

; mov [eax+ ebx], BYTE ptr [ecx + edx]         ; invalid instruction operands
; mov BYTE ptr [eax + ebx], [ecx + edx]
mov eax, [ecx + edx]                         ;MASM know the size (eax = 4bytes)
mov [ecx + edx], bx                          ;MASM know the size (bx  = 2bytes)
m2m [eax+ ebx], [ecx + edx]            ;OK as m2m! MASM knows the size for a push is DWORD
mov al, 22h                                  ;MASM know the size (al  = 1byte)
mov [edx + text], 22h                        ;MASM know the size (text = 1byte)??
mov eax, [num + ecx]                         ;MASM know the size (num  = 4bytes)??
; mov bl, [num + ecx]                          ;would not work, bl = 1byte/num = 4bytes??
mov bl, BYTE ptr [num + ecx]                 ;MASM know the size (BYTE ptr)??

; ---------- for syntax checks, use the area between <code> and <start> -------------

start: invoke MessageBox, NULL, addr MyText, addr AppName, MB_OK
invoke ExitProcess, 0

end start

n00b!

Cool, thanks :-)
Oh yeah, I forgot that memory to memory or 2 variables in 1 incstruction don't work.


Ok, I think the following are my last questions ._.

1.
But are the reasons on these instructions correct?

.data
  num dd 55

mov [edx + text], 22h                        ;MASM know the size (text = 1byte) ??
mov eax, [num + ecx]                         ;MASM know the size (num & eax  = 4bytes) ??

; mov bl, [num + ecx]                        ;would not work, bl = 1byte/num = 4bytes ??

mov bl, BYTE ptr [num + ecx]                 ;MASM know the size (bl = 1byte/num = 4bytes, but BYTE ptr) ??


2.
Is   "[num + ecx]"   equal to   "addr num + ecx"   or   "55 + ecx"?

jj2007

Quote from: n00b! on June 12, 2008, 07:10:25 PM
But are the reasons on these instructions correct?

.data
  num dd 55

mov [edx + text], 22h                        ;MASM know the size (text = 1byte) ?? YES INDEED, text is "db"
mov eax, [num + ecx]                         ;MASM know the size (num & eax  = 4bytes) ?? eax is DWORD

; mov bl, [num + ecx]                        ;would not work, bl = 1byte/num = 4bytes ??
Good questions, NO CLUE why Masm doesn't understand it... bl is clearly a BYTE

mov bl, BYTE ptr [num + ecx]                 ;MASM know the size (bl = 1byte/num = 4bytes, but BYTE ptr) ??


2.
Is   "[num + ecx]"   equal to   "addr num + ecx"   or   "55 + ecx"?
mov eax, [num + ecx]
means "move the 32 bit that you find at [address of num plus ecx] into eax"
The other ones will not assemble - test yourself ;-)