0% found this document useful (0 votes)
7 views4 pages

6 Asc

The document discusses assembly language concepts, including segment data, pointer arithmetic, and bitwise operations. It highlights syntax rules for defining labels and using offsets, as well as the differences between operators and instructions in bitwise operations. Additionally, it provides examples of how to manipulate bits and the implications of using logical negation and 1's complement in assembly language.

Uploaded by

sararoza123321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

6 Asc

The document discusses assembly language concepts, including segment data, pointer arithmetic, and bitwise operations. It highlights syntax rules for defining labels and using offsets, as well as the differences between operators and instructions in bitwise operations. Additionally, it provides examples of how to manipulate bits and the implications of using logical negation and 1's complement in assembly language.

Uploaded by

sararoza123321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Location Counter

Segment data
a db 17, -2, 0ffh, ‘xyz’,…
db ….
db….

;lga db $-a (mov [lga],….); ok //pointer arithmetic – subtracting 2 pointers =


scalar value (numerical constant) – lga = memory variable (mov [lga],…)

;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.

;lga dw $-data ; correct in TASM/MASM, INCORRECT in NASM on 32 bits


!!! syntax error – “Expression is not simple or relocatable”

;lga dw lga-a !!!! ok !

b EQU 27 ; b is NOT an offset !!!!


c dd 12345678h

;lga dw b-a ; syntax error !!!!! b is NOT an address !!!


;lga dw c-a ; ok !!!!
lga dw $-a-4 ; ok !!!
lg dw $-a ; length (a) + 4 !!!

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, [v] ; mov eax, DWORD PTR DS:[405000]

Mov eax, [ebx] ; mov eax, DWORD PTR DS:[ebx]


Mov eax, [ebp] ; mov eax, DWORD PTR SS:[ebp]

Mov eax, [ebp*2] ; mov eax, DWORD PTR SS:[ebp+ebp]


Mov eax, [ebp*3] ; mov eax, DWORD PTR SS:[ebp+ebp*2]
Mov eax, [ebp*4] ; mov eax, DWORD PTR DS:[ebp*4]

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+ebp] ; …DS…


Mov eax, [ebp+ebx] ; …SS…

Mov eax, [ebx*2+ebp] ; …SS…

Mov eax, [ebx*1+ebp] ;…SS…


Mov eax, [ebp*1+ebx] ; …DS…

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

Mov eax, [ebp*1+ebx*2]; …SS…


Bitwise operators and instructions

In computer programming, a bitwise operation operates on a bit string, a bit array or a


binary numeral at the level of its individual bits. It is a fast and simple action, basic to
the higher-level arithmetic operations and directly supported by the processor.

Pay attention to the difference between operators and instructions !!!

Mov ah, 01110111b << 3 ; AH :=10111000b

Vs.

Mov ah, 01110111b


Shl ah, 3

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 AND operator x AND 0 = 0 ; x AND x = x


AND – instruction x AND 1 = x ; x AND ~x = 0

Operation useful for FORCING the values of certain bits to 0 !!!!

| - bitwise OR operator x OR 0 = x ; x OR x = x
OR – instruction x OR 1 = 1 ; x OR ~x = 1

Operation useful for FORCING the values of certain bits to 1 !!!!

^ - bitwise EXCLUSIVE OR operator; x XOR 0 = x x XOR x = 0


XOR – instruction x XOR 1 = ~x x XOR ~x = 1

Operation useful for COMPLEMENTING the value of some bits !!!

XOR ax, ax ; AX=0 !!! = 00000000 0000000b


Operators ! and ~ usage

In C - !0 = 1 (0 = false, anything different from 0 = TRUE, but a predefined function will set
TRUE =1)

In ASM - !0 = same as in C, so ! - Logic Negation: !X = 0 when X ≠ 0, otherwise = 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 !)

Mov eax, !a - ! can only be applied to SCALAR values !!

Mov eax, !(a+7) - ! can only be applied to SCALAR values

Mov eax, !(b-a) – ok ! because a,b – pointers, but b-a = SCALAR !


Mov eax, ![a+7] - expression syntax error
Mov eax, !7 - EAX = 0
Mov eax, !0 – EAX = 1

Mov eax, ~7 ; 7 = 00000111b , so ~7 = 11111000b = f8h,


EAX=ff ff ff f8h

Mov eax, !ebx ; syntax error !

aa equ 2
mov ah, !aa ; AH=0

Mov AH, 17^(~17) ; AH = 11111111b = 0ffh = -1


Mov ax, value ^ ~value ax=11111111 11111111 = 0ffffh

value ^ ~value ax=0ffffh

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy