6 Asc
6 Asc
Segment data
a db 17, -2, 0ffh, ‘xyz’,…
db ….
db….
;lga dw $-$$ ; the same correct length, but ONLY IF a is the first element
allocated in the data segment !!!!
;lga EQU $-a ; ok ! but mov [lga],… will issue a syntax error !!! because lga is
NOT an allocated variable… so it doesn’t have a memory address to be deref.
If no section directive is explicitly used, the symbol $$ will be implicitly evaluated to the offset
of the beginning of the current segment.
“:” is mandatory when we define code labels (ex: “start:”) but must not be present when we
define a data label (ex: a variable definition “a db 17”)
Examples - implicit rules for prefixing an offset with the corresponding
segment register
Mov eax, [ebx+esp] ; ESP – base… EBX – index ;EAX dword ptr [SS:esp+ebx]…
Mov eax, [esp + ebx] ; ESP – base… EBX – index ;EAX …SS:…
Mov eax, [ebx+esp*2] ; syntax error BECAUSE ESP can be ONLY a base register !
Mov eax, [ebx+ebp*2] ; mov eax, DWORD PTR [DS:EBX+EBP*2]
Mov eax, [ebx*1+ebp*1] ; ;…SS… - the first found scaled element is taken as index
!! EBP - base
Mov eax, [ebp*1+ebx*1] ; …DS… - the first found scaled element is taken as index
!! EBX - base
Vs.
In the descriptions below x represents ONE BIT, 0 and 1 represent bit values and ~x represents
the complementary value of the value bit x. The descriptive sequences below exemplify the
mode of action of the AND, OR and XOR operations AT THE BIT LEVEL as the MECHANISM of
action, regardless of whether the respective operation is triggered at the source code level by
the respective OPERATOR or by the corresponding INSTRUCTION.
| - bitwise OR operator x OR 0 = x ; x OR x = x
OR – instruction x OR 1 = 1 ; x OR ~x = 1
In C - !0 = 1 (0 = false, anything different from 0 = TRUE, but a predefined function will set
TRUE =1)
~ 1’s Complement: mov al, ~0 => mov AL, 0ffh (bitwise operator !)
(because a 0 in asm is a binary ZERO represented on 8, 16, 32 or 64 bits the logical BITWISE
negation – 1’s complement - will issue a binary 8 of 1’s, 16 of 1’s, 32 of 1’s or 64 of 1’s… )
a d?....
b d?...
Mov eax, ![a] - because [a] is not something computable/determinable at assembly time, this
instruction will issue a syntax error ! – (expression syntax error)
Mov eax, [!a] - ! can only be applied to SCALAR values !! (a = pointer data type ≠ scalar !)
aa equ 2
mov ah, !aa ; AH=0