ASC Partial 7 Dec
ASC Partial 7 Dec
Vancea
Week 1
- executive unit → EU
- ALU → device
- BIU → bus interface unit
- C-BUS in ALU
D- BUS
- a [7] = * •""Docteți în plus la a
at 7)
↳ accesează valoarea
as starting address
- bit
octet
Week2
- registers → definition: storage capacities, very small in terms of size 18, 16,32,64 bits),
but very fast as accessed speed, used for temporary store of operands with which the processor
currently works ↳ data, commands codes, addresses
EAXAM A
high
low
E:&:
ES:
AX
- FIFO-qu&ne
- help-something unorganised
top ofstack
- SS → stack segment i
e
ESP last el
EBP first el
base of stack
!! • - why 3 are focused on working with a stack and not with queue and heap?
Laduăm în ianuarie
PA
ESP
MP
EBP >
înregistrarea execuțiilor
t h e g e n er a l r e g i s te r s w il l b e c o n s id e r e d to d o w h a t the r e g i s t er d o es
W eek 3
- E U → e x e c u t iv e u n it
- al w a y s a lo o p in s tr u c t io n u s e s E C X fo r t h e n r . o f r e p e t it io n
- s ta c k s t . r ef l ec t s w h at h a ppe n s a t r u n t im e
- t h e r u n t im e s t a ck → t h e s tr u c t u r e t h a t s ta y s b e h in e d e v e r y h t p l a n g .
- in r e g is t e r s y o u ca n a c c e ss t h e l o w er p a r t L A X , B X .. . ) , b ut y ou ca n n o t a cc e s s t h e h i g h e r p a r t
- w o r k i n g w it h b y tes f or E A X , E B X , E C X ,E D X
„ A N D L O R , X O R , N O T - b it by b i t o p e r a t io n s
- A L U → p r o v id e s a r i t h m e t ic a n d l ogic o p e r a t ion s
C a r i t t m e t ic a n d → b i t - s h i f t in g o p e r a to r s → s hif t in g t h e l o c a tio n o f a b it to t h e m a r e b y a p a r t ic u l a r n u m b er
l o g i c u n it ) → w il l s e t a c c o r d in g l y t h e v alu e s f r o m t he E F L A G S r e g is ter
s o f t w a r e v i s i o n :
t h e s iz e o f t h e w o r d s it l o r r e g is te r s in s i d e th e pr o c e s s o r
- h a r d w a r e v is io n :
t h e s iz e o f t h e c o m m u n ic a t io n c h a n ne l s , b u s e s
u s u a l l y th e b u s e s b ig g e r th a n th e s iz e s o f th e p r o ce s s o r
- in th e l a n g u a g e w o r d d i f f e r e n t
E A G S
- o n l y 9 b it s u s e d o u t o f t h e 3 2
- w h a t e v e r y f l a g is d o in g a n d is g o o d f o r ?
- fla g → in d ic a t o r o n 1 b ie t
1 0 0 1 0 0 11 +
0 1 1 1 0 0 11
1 0 0 0 0 011 0
C F 1
d e s tin a t io n v a lu e o f the c a lcu l ator
L P O ( l a s t p r e f o r m e d o p e ra tio n )
P E - A p e t a b l ă t ot ( t h e co r r ect m a th e m a tica l is o n 9 b its )
S E E
- C E - t r a n s p o rt f l a g if in the L P O w e h a v e o v e r f l o w ( U N S IG N E D )
- c i o b ă n ește f l a g
- P F - p a r it y f la g > t h e l e a s t s ig n i f i ca t b y t e t o h av e a n o d d n u m b er o f cifr e 1
- A F - a u x il i a r y f l a g → tran s p o r t v a l u e f r o m b it 3 to b it u o f t he L P O
b o u n d a r y b e tw e e n t h e n ib b l e o f t h e b y te
↳ h a l f a b y te = s e m i o t e t
- compressed base 2 → base 16
6=262-256
- a binary digits → e hexa digit
unsigned signed
1001 0011 + = 934 + 147T -109 +
0 111 0011
00 00 0110
734 115 115
1 06 4 262 6
OF = O
- zero positive number E- 128, 1273 [0,25-5]
- ZF → zero flag trebuie să știm la bit, word came la signed sau unsigned
- SF -sign flag
DE:O ⇒ passing of the arrays made in asscending order I from small addresses to
big addresses
= 1 ⇒ passing of the arrays made in dessendingorder , inverse
- O F - o v er f l o w f lag ( S IG N E D )
- t he r es u l t c a n o r c a n n o t f it t he s p ace g iv en f o r th e o p e r a tio n
in s i d e co m p u t er → r epr e s e n t a t io n î n b a s e 2
o f t he v alu e in m y m i n d in b a se 10
b a s e 2 → b a s e 16 → b a s e 10
L e a s ie r th is u sa y )
- A r ep r e s en ta t io n in b a s e 2 h a s a l w a y s 2 p o s s i b l e in t e r p r etio n s i n b a se 10
↳ n u a r e in t e r p r e t ă r i c a l cu l ato r u l , d o a r r ep r e z e n t ăr i ↳ î n t o t d e a u n a 2
in te r p r e tă r i, c â teo d a t ă
- m e t o d a in t e g r ă r i i î n in t e r v a l e l e d e r e p r e z e n t a r e a d m is i b i l e a ces te a c o in c i d
- b o t h in ter p r e t a t io n th e c o m p g o e s s i m u l t a n eo u s l y S a u d e s e m n e a z ă o p r o s t i
2 situation in which OF = 1.
+ 1- .. .. +
0 1
1- - . 1 O _. _
2 Categories of flags:
Weekn:
- Mathematically, the 2's comlement REPRESENTATION of a NEGATIVE number is the value 2"-V,
where ✓ is the absolute value of the represented number
- Moto: With the 2's complement," We interpret representations and represent interpretations"
base 2 base 10
4 t h m e th o d : S u m a v a l -a b s a l e celo r 2 v a l c o m p l em e n t a r e in b a z a 10 e s te c a r d in a l u l m u l ț im i i
v a l . r ep r ez e n t a te p e a ce a d im e n s i u n e .
- E x a m p l es : W h ich is t h e s ig n e d in te r p r e t a t io n o f > i) 10 0 1 0 0 1 1 a ) 0 1 10 1 10 1 ×
b - 1 0 9
Ii) 9 3 4 c) 6 8 h ×
d ) + 1 4 7
I i 14 7 e ) - 1 4 7
n u a r e in t e r p r et a r e , î i d e ja o in t e r p r e t a r e ! ! !
14 7 a n d - 10 9 co m p lem e n t ar y B U T
N O T - 14 7 a n d 10 9
n o t r epr es e n ta b le o n O N E B Y T E
T h e ↳ s it u a t i o n s p os s ib le :
O X .. . . → s a m e s a n d u
14 .. . . → a l w a y s d if f e r en t
c o n f i g u r aț ia b in a r ă
a l u i - 10 9
- 1 4 7 → 1 .. . . .
0 1 0 0 1 0 0 11 → 14 7
1 0 1 1 0 1 1 0 1
- 14 7 1
↳ in t h e u n s ig n e d C b w
↳ in a s s a m b l y • w it h a d a u g ă b it - u l d e s e m n
T ip u r i d e î n tr e b ă r i p t e x a m e n s c r is și 7 d e c i
e -
W e e k 5 : A d d r ess r e g is t e r s a n d a ddre s s co m p u t a t ion
A D R - a d d r es s co m p uta t io n
÷i : :
C S - co d e seg m e nt → al w a ys
D S - d at a seg m en t
S S - s ta ck s eg m e n t → a lw a y s
E S - e x tr a s e g m en t → a n oth er d ata s e g m e n t ( u s u a lly her e t h e d es tin a tio n a r r a y )
T Ă - F S - ] 3 2 b its p r o g r a m m in g
6 5 -
E IP -
- d e d ic a te d to w o r k w ith a d d r es s es
- w o r k in g w it h a d d r es s e s / p o i n ter s in m o st h ig h l e v el pr ogr a m m in g l an gu a g es
O 1
- in d e x s tarts f r o m
o f a s eg m e n t 1. t h e f o c u s
23 t h e m a x im u m len g th
- p h i s ica l s e g m e n t ( c e v e d e m i n o l l y d e b u g )
- l o g i c a l s e g m e n t / s ectio n
- s e g m e n t → b a s ic a d d r e s s ( b a z ă )
✓ l im it ( s iz e o f )
t ype ( C s ,D s , S S , E S )
- a d d r e s s s p e c i f ic a ti o n → p a ir o f 2 n u m b e r s ( o f f s e t a n d s eg m e n t s el ect o r )
↳ s t il l 1 6 b it s n u m b er o n 3 2 b it s pr o gr am m in g
s e g m e n t : o ff s e t
↳ to t a ll y c o n tr o l o f it 3 2 b it s
lo b it s o n n o b p r o g . t h e s ta r ti n g a d d r e s s o f th e s e g m e n t
o n 3 26 pr a g s e g m e n t s e lec t o r ( is s u e d b y t he
o p e r a tin g s y s tem )
5 3 5 29 5 0 : 0 7 0 6 0 5 0 4 0 3 0 2 0 10 0
o n 16 b it s C S , D S s h o w e d th e s tar t in g a d d . o f th e s eg m e n t
s e g m e n t b a s ic
L i m it
s e l ect o r a d d r es s
8
5 17 8 2
17
i
27 3 2
•
17 15 2 c
t h e lim i t
th e o f f s e t
I
in t o B IU ←
↳ n e v er m a n ip u l a te d d ir e c t l y b y th e pr o g r a m m e r
c l ea r in w h ic h se g m e n t y o u w o r k i n
( d a ta ,c a d e , e t c )
o ffs et → a n e a r a d d r ess
•
→ n o t u s e d f o r a p r a c t ic a l p o i n t o f v ie w
f l at m e m o r y m o d e l : w e w o r k o n l y w it h o f f s e t s
t h e o nly m a n d a to r y o n e !
ly
e x e c u te d
→ s e v ed e l a in s t r u c ț i u n i î n s tâ n g a s u s th e o f fs e t / a d d r e s s
E IP / e x te n d e d in s t r u c t i o n p o in t e r )
C S E IP
1) u s u a l l y t h e s a m e !
D o n ly t h e o f f s e t
im p l i c i t for s o m e v a r i a b l es
W a y s in w h ic h w e ca n s p e cif y t h e o p er a n d s
- 3 w a y s in w h i c h w e ca n ex p r ess a n cep p e r a n d :
% r e g is te r m o d e : m o v e a x 11 7
I i) im m e d i a te m o d e : m o v ea x , 17 D m ea n s f r om m em ory !
Iii) m e m o r y a d d r es s in g m o d e : m o v e a x , [ a c t]
[ a t 7 ]
ju s t 9 + 7↳ th e s t a r t in g ad dres s
↳ th e v alu e
d ef er e n cin g o per a tor !
17 15 2 a d r es a
m o v e a x , e b x
" d u ,2 W
m ov e a x , [ e b x ]
E A X EB X
1 ,2 14 ,8 g o i n g f o r b ,w
( in d ir e c t io n )
Fo h 56 4 3 24 2 3 h
o f f s e t - a d r e s s = [ b a s e ] + [ in d e x * s c a le ] + [ c o n s t an t ] a h /3 2 4 56 4 Fo h
↳ o n e o f t h e a 8 ls o g e ,n "" at â t E i g is te r s EA X 17 1 5 2
în 16 b its
[ B X /B P ] + [ S I /D I ] + [ c o n s t a n t ]
O N L Y A D D IT I O N P O S S IB L E
o n l y t h is is a n
o p ț io n a l it a te a
n ot a d dr es s e s
a d d r es s
in d i r e c t a d d r e s s in g
the offsets are not changed!
A variable is a language element which contents it is variable , the address of it is constant!!!
(variabil)
D the address of v
At least one
Week 6:
[constant]
mov eax,[v3
Pointer arithmetic
Iii) subtracting 2 pointers (the number of bytes between them / the size of the area between them)
ex: q-p → SCALAR!
Tested
- every symbol is replaced with the offset
(constant)
address
i. „contents
^
LHS RHS
L-value R-value L-values, R-values
addresses, L-values
În, Fese
> R-value
(aer? 1:c) -xeyez not good
fla,7) = 79
I
✓ [73 = 79
alt]-* (art) = * (7- + a) Ea]
mov eax, a
mov ebx, 7 Ea]
Examples:
1-D pointer constant
mov eax, a + 2 ✓
↳ pointer arithmatic
W e ek 7 :
A s se m b l y L a n g u a g e B a s ic s
•
A m a s s e m b l er w o r k s w it h :
1) la b le s
2) in s t r u c t i o n s
3 ) d ir ec t iv es
„ l o c a t i o n c o u n t er
la b l e e x : j u m p n a m e
D j u st a n o ffset a n a d d r e s s
n a m e : ← h er e th e n a m e is d e fin e d
a ls o t h e n a m e o f a v a r i a b le / d a t a l a b le )
• d i r e c t iv e s : s e g m e n t d a t a , d b , d d , . .. .
o
a s s e m b l er → t r a n s l a tio n d a t a
→ ch e c k t h e c o r r e c t i on o f t h e c o d e
→ g e n e r a t i n o b j f il es
→ g e n e r a ti n g b y te s
• in s t r u c t i o n s → t o the p r o c e s s o r
• l o c a tio n c o u n t e r
↳ n o t s p e c i f ic to y our p r og r a m , b u t w it h e v er y s e g m e n t
( e x 2 o n e fo r d a ta s eg
on e for co d e s e g
• [ ] → s p e c i f ic f o r N A S M
☑ sta ț i a , o d a t a
• $ → t y p e p o in te r → o n l y in N A S M in T A S M : $ - d ata a n o ffset
.
→ t he s ta r tin g a d d r e ss of a d irect iv e S E C T I O N
in N A S M : d a ta → s -a . o f a F A R
$ → t h e b e g in n in g o f th e s e g m e n t if n o t S E C T I O N S a d d res s
e v er y o n e it ' s o p tio n a l , e v e r y o n e c a n m is s
P op tio n a l •
o n ly in N A S M
•| ↳ in t h e en d e v er y o ff s e t h a s to b e co m e a F A R A D D R E S S
in t h e p r o c e s s o f g en er a ti n g b y te s , a n y n a m e w ill b e î n lo cu i t w i th t h e a d d r es s b y t h e
a s s e m b l er
e x e p t io n : t o t h e o f f s e t s p e c i f i c a t io n s for m u la
( + , * )
V op er a t or s
d e s cr i p t or s u b 3 2 b it s
lo a d e r → the s e g m e n t p a r t p u t
b e f o r e r u n t im e in l o a d in g t i n e
→ s c a le in d e x b a s e d
N U E S !! !
o
" Ț
↳ fo r this :
s o u Tre e s t r i n g d e s tin a tio n s tr i n g
i m p l i c t it l y
T h e a s s e m b le r w il l p r e f ix a n y o ff s e t w it h o n e o f t h i s
3 s e g m e n t r eg is te r s
E x a m p le s :
1 . F in d len g th
S e g m e n t d a ta :
a d b 17 ,- 2 , o f f h , 1× 9 2 1 1 . . . . .
Î i : -.
eg a e u Ș i a
d o n 't a c t u a l ly n e e d l a u , y o u c a n d ef i n e it a s a v a r ia b l e
r ă m â n e î n t a b e l a d e co n s ta n te , c a v a r ia b il ă î n s e g m e n tu l d e d ate
↓ a d d r es s
S eg m e n t d a ta :
a d b 17 ,- 2 , o f f h , 1× 9 2 1 1 . . . . .
Î i : "
l g a d o $ - a → n o w l ga a v a r i a b le c a n b e m o d ifi e d
ca d e d a ta :
m o v [ l g a ] , s o m e th in g
Segment data:
a db 17,-2, offh , 1×9211.....
Îi:"
ega du $-$ $ → it works because a the first element
if bdw 15h
then.. ⇒ It would give the
number of bytes
from start until the current element
Segment data:
a db 17,-2, offh , 1×9211.....
Îi:"
- .
Segment data:
a db 17,-2, offh , 1×9211.....
db......
dw....
c dd...
lgadw c-a
Segment data:
a db 17,-2, offh , 1×9211.....
Îi:"
lga du ega-a!
already is generating the bytes, alocă 2byte forlga then you can use lga
on the spot
Î N C Ă UN S L ID E !
pr e ț in e
•
NO T
m o v e a x , a + 2 ✓
m o v e a x , [ a ta ] ✓
m o v e b x , e b x ← 2 ✗
a d d e b x " , 2 " o p er a tor
↳ in s t r u c t io n s
e v a l u at p e s u b it s
N U LA
E X A M E N CA S Ă
Ș TIU E V A L U A R E A
DA R T R E B E S Ă Ș T II C E F A C
P l ea s e p r o v i d e m in i m u m 2 0 w a y s to in i t i aliz e ◦ o f a r e g i s ter
V O R a x ,a x
m ov a x , o
a n d a x o
W e e k 8 : c o n t in u in g w it h o p er a tor s
y pe o p e r a t or s :
data segment:
example: i. • d?.... EXPLICIT OPERANDS AND IMPLICIT OPERANDS
ad? ex: old DF and o
bd?...... 2 operands
code segment:
push o puts the offset of ✓ at the top of the stack
L am offset on 32 bits
Lobey of. spes. formula
L cannot determine at assembly time
2 operands destination (the stack)
the offset poitier * pe constant
GOOD
push 15 i push DWORD 15 (in olly even)
↳ inconsistency ⇒ the assembler puts it on 32 bits
word,dword
pop [v] SYNTAX ERROR
dword,word
pop ↓ [eax]
↳ memory address operand
S. E.
POP '5- ☐ constant of immediate type
↳notevalue!!
dword
pop" [15]
byte, word, dword
word,doar, „te TYPE EXPRESION not TYPE MEMORCI ⇒ GOOD even if o is an immediate
value
din [o] SE.
II
imul [v2] SE.
but this is good
an R-value!
mov [a3, [b] SE.!!! NOT BOTH EXPLICIT OPERANDS FROM MEMORY
maxim unul explicit
S Y N T A X E R R O R = A S S E M B LY E R R O R ( o n 7- d e a )
D IR E C T I V E S N O T O N TH E EX A M
TIMES 32 add EAX, EDX jas effect EAX-EAX + 3IEDX
→ EQU → it is a constant
→ it ism'tin memory
[128, 255] 1 / /
• ..