?? - PowerPoint PPT Presentation

About This Presentation
Title:

??

Description:

Title: Author: Last modified by: Panagiotis Katsaros – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 52
Provided by: GOS56
Category:
Tags:

less

Transcript and Presenter's Notes

Title: ??


1
??µ? µeta???tt?st? backend
?e???? a????s?
S??ta?t??? a????s?
S?µas???????? a????s?
?a?a???? e?d??µes?? ??d??a
e?d??µes?? ??d??a?
?a?a???? ??d??a
?e?t?st?p???s? ??d??a
  • ? ?atas?e?? t?? p??t?? st?d??? epe?e??as?a?
    (front end) e??a? se µe???? ίa?µ?
    a?t?µat?p???µ???
  • G?a t? te???? st?d?? epe?e??as?a? (back end) de
    d?a??t??µe ?e???? a?t?µat?p???µ??e? te??????
    ?atas?e???, ??at? e?????? ? pa?a??µe??? ??d??a?
    e?a?t?ta? ap? ta ?a?a?t???st??? t?? µ??a??? st??
    ?p??a ?a e?te?e?ta? ?a? ?? d??at?t?te?
    ίe?t?st?p???se?? p?????????
  • ? d?µ??????a e?d??µes?? ??d??a ep??e??e?
    ?a????st??? t?? ap?d?s? t?? back end

2
???f?? e?d??µes?? a?apa??stas??
  • S??ta?t??? d??d?a
  • ?ate?????µe??? ??????? ???f??
  • G??f?? ???? e??????
  • ??d??a? µ??a??? st??ίa?
  • ??d??a? t???? d?e????se??
  • ?ί??d???? p??se???se?? p?? ???s?µ?p????? te??????
    ap? t?? d?? p??a?afe??µe?e? ???????e?e?
  • ??p???? µeta???tt?st?? ???s?µ?p????? ??d??a t????
    d?e????se?? ?a? ??a epa?a??pt????? ί??????,
    e?t???? if ?a? a?af???? se array ???s?µ?p?????
    s??ta?t??? d??d?a

????? ep?ped?
??af??? e?d??µes? a?apa??stas?
??aµµ??? e?d??µes? a?apa??stas?
?aµ??? ep?ped? (p?? ???t? st? µ??a??)
3
S??ta?t??? d??d?a
Statements
  • if (x lt y)
  • x 5y 5y/3
  • else
  • y 5
  • x xy

IfStmt
AssignStmt

x
AssignStmt
lt
AssignStmt
y
x
x
x
y

y
5

/
5
y
3

5
y
4
?ate?????µe??? ??????? ???f??
  • ?ta? ???eta? ???s? ?ate?????µe??? ??????? ???f??
    ??a t?? a?apa??stas? e?f??se??
  • G?a ???e ??f?as? ???s?µ?p??e?ta? ??a?
  • µ??? ??µί??

Statements
if (x lt y) x 5y 5y/3 else y 5 x
xy
IfStmt
AssignStmt
lt
AssignStmt
x

y
/

3
5
5
G??f?? ???? e??????
  • ?? ??µί?? e??? ???f?? ???? e?????? e??a? ίas???
    block
  • ?as??? block e??a? µ?a se??? e?t???? p?? p??ta ?
    e?t??es? t??? a????e? ap? t?? p??t? ?a? te?e???e?
    st?? te?e?ta?a ap? a?t??
  • ?a t??a se ??a ???f? ???? e?????? a?apa??st??? t?
    ??? e??????

if (x lt y) x 5y 5y/3 else y 5 x
xy
B0
if (x lt y) goto B1 else goto B2
B1
B2
x 5y 5y/3
y 5
B3
  • ???e ίas??? block pe???aµί??e? µ?a se??? e?t????
  • ?e? ep?t??peta? d?af??? ap? t? µ?s? e??? block
  • ?ta? ???eta? e?????s? t?? e?t??es?? e??? block
    t?te
  • ? e?t??es? ?????????eta? p??ta st?? te?e?ta?a
    e?t??? t??

x xy
6
???a?? st??ίa?
??e? t?? t?µ? t?? ??s?? x st?? ????f? t?? st??ίa?
load x load y iflt L1 goto L2 L1
push 5 load y multiply push 5
load y multiply push 3 divide
add store x goto L3 L2 push 5 store
y L3 load x load y add store x
afa??e? d?? st???e?a ap? t?? ????f? ?a? ta
s??????e?
if (x lt y) x 5y 5y/3 else y 5 x
xy
afa??e? d?? st???e?a ap? t?? ????f?, ta
p???ap?as???e? ?a? t?p??ete? t? ap?t??esµa st??
????f?
  • JVM ??a µ??a?? st??ίa?
  • ?e??? fa??eta? s?µί?????? ??d??a? ??a t?? JVM,
    p??
  • µetat??peta? se bytecode µe t?? ?at??????
    s?µί?/st?
  • ? JVM d?e?µ??e?t?? e?te?e? t?? bytecode se
  • d?af??et???? µ??a???
  • ? JVM d?a??te? µ?a st??ίa p?? ???s?µ?p??e?ta?
    st??
  • ap?t?µ?s? e?f??se??
  • ? JVM ???s?µ?p??e? 65535 t?p???? µetaί??t??
  • ?? t?p???? µetaί??t?? ?e?t??????? ??
    ?ata????t??
  • ???e t?p??? µetaί??t? st?? JVM s?µί????eta? µe
  • ??a? a???µ? µeta?? 0 ?a? 65535 (st? pa??de??µa
  • ap?d?d??ta? st?? x ?a? y µ??ad???? a???µ??)

ap????e?e? t?? t?µ? t?? ????f?? t?? st??ίa? st?
??s? x
7
??d??a? t???? d?e????se?? ?
  • ???e e?t??? µp??e? ?a ??e? t? p??? t?e??
    te?est????
  • ??????s? t?µ??
  • x y
  • x y op z op d?ad???? a???µ?t???? ? ???????
    te?est??
  • x op y op µ??ad?a??? te?est?? (-, ???
    ?.a.)
  • ??a???d?s?
  • goto L e?t??es? t?? e?t???? µe t?? et???ta L
  • ?p? s?????? d?a???d?s?
  • if x relop y goto L relop lt, , lt, gt, , !
  • a? ? s?????? e??a? a????? t?te e?te?e?ta? ?
    e?t??? µe t?? et???ta L
  • a? ? s?????? de? e??a? a????? t?te s??e???eta? ?
    e?t??es? µe t?? ep?µe?? e?t???

8
??d??a? t???? d?e????se?? ??
?? µetaί??t?? a?apa??st??ta? ap? t? ??s? t???
st?? p??a?a s?µί????
if (x lt y) x 5y 5y/3 else y 5 x
xy
if x lt y goto L1 goto L2 L1 t1 5 y t2
5 y t3 t2 / 3 x t1 t2 goto L3 L2 y
5 L3 x x y
?? p??s?????? µetaί??t?? a?t?st?????? se
es?te?????? ??µί??? t?? s??ta?t???? d??d???
?? e?t???? t?? ??d??a t???? d?e????se?? µp?????
?a a?apa?asta???? se p??a?a ap? tet??de?
p????, pa??µet??? 1, pa??µet??? 2, ap?t??esµa
se p??a?a ap? t???de? p????, pa??µet??? 1,
pa??µet??? 2 (???e t???da ?e??e?ta? ?t?
a?t?st???e? se µ?a p??s????? µetaί??t? µe
p??sίas? st?? t?µ? t?? µ?s? a?af???? st?? a???µ?
t?? e?t????)
9
?a?a???? ??d??a t???? d?e????se??
?d??t?te? E.place ??s? ?p?? ί??s?eta? ? t?µ?
??a t?? ??f?as? E E.code se??? e?t???? p??
pa?????ta? ??a t?? E ??ad??as?e? newtemp()
ep?st??fe? ???e f??? µ?a ??a p??s?????
µetaί??t? gen() d?µ?????e? ??d??a (?a?e?ta? µe
t?? ?at?????e? pa?aµ?t????) lookup(id.name)
ep?st??fe? t? ??s? t?? id st?? p??a?a s?µί????
?a?a????? S?µas????????? ?a???e? S ? id
E id.place ? lookup(id.name) S.code ? E.code
gen(id.place E.place) E ? E1
E2 E.place ? newtemp() E.code ? E1.code
E2.code gen(E.place E1.place
E2.place) E ? E1 E2 E.place ?
newtemp() E.code ? E1.code E2.code
gen(E.place E1.place E2.place) E ? ( E1
) E.code ? E1.code E.place ? E1.place E ? ?
E1 E.place ? newtemp() E.code ? E1.code
gen(E.place uminus E1.place) E ? id
E.place ? lookup(id.name) E.code ?
(?e?? s?µί???se???)
10
?a?a???? ??d??a ??a µ??a?? st??ίa?
?d??t?te? E.code se??? e?t???? p?? pa?????ta?
??a t?? E (de ??e???eta? ?d??t?ta ??s?? ??a t??
??f?as?, af?? t? ap?t??esµa t?? ??f?as??
ap????e?eta? st? st??ίa) ??ad??as?e? newtemp()
ep?st??fe? ???e f??? µ?a ??a p??s?????
µetaί??t? gen() d?µ?????e? ??d??a (?a?e?ta? µe
t?? ?at?????e? pa?aµ?t????) lookup(id.name)
ep?st??fe? t? ??s? t?? id st?? p??a?a s?µί????
?a?a????? S?µas????????? ?a???e? S ? id
E id.place ? lookup(id.name) S.code ? E.code
gen(store id.place) E ? E1 E2 E.code ?
E1.code E2.code gen(add) (??
pa??µet??? t?? e?t???? add ί??s???ta? st?? ????f?
t?? st??ίa?) E ? E1 E2 E.code ? E1.code
E2.code gen(multiply) E ? ( E1 ) E.code ?
E1.code E ? ? E1 E.code ? E1.code gen(
negate) E ? id E.code ? gen(load id.place)
11
?a?a???? ??d??a ??a ??????? e?f??se??
  • ??? p??se???se??
  • ????µ?t??? a?apa??stas?
  • S??epa??µe?? a?apa??stas?
  • ????µ?t??? a?apa??stas?
  • ???s?µ?p????µe 1 ??a t? true ?a? 0 ??a t? false
  • Se ??d??a t???? d?e????se?? ap????e?eta? t?
    ap?t??esµa se p??s????? µetaί??t?
  • Se ??d??a µ??a??? st??ίa? t? ap?t??esµa
    ap????e?eta? st? st??ίa
  • S??epa??µe?? a?apa??stas?
  • G?a ??????? e?f??se?? p?? ???s?µ?p?????ta? se
    ??e??? ???? (p.?. e?t???? if, while ??p.) ?a? de
    ???s?µ?p?????ta? ??a t?? ?p?????sµ? e???
    ap?te??sµat??,
  • d?µ???????µe ??d??a p?? ap?? d?a??ad??e? st??
    ?at?????? e?t??? a?????a µe t? ap?t??esµa

12
??????? e?f??se?? a???µ?t??? a?apa??stas?
?d??t?te? E.place ??s? ?p?? ί??s?eta? ? t?µ?
??a t?? ??f?as? E E.code se??? e?t???? p??
pa?????ta? ??a t?? E id.place ??s? t?? id
?a?. µetaί??t? nextstat ep?st??fe? t? ??s? t??
??a? e?t???? p?? ?a d?µ???????e? (???e ???s?
st? gen() a????e? t? nextstat ?at? 1)
?a?a????? S?µas????????? ?a???e? E ? id1 relop
id2 E.place ? newtemp() E.code ? gen(if
id1.place relop.op id2.place goto
nextstat3) gen(E.place 0)
gen(goto nextstat2) gen(E.place
1) E ? E1 and E2 E.place ?
newtemp() E.code ? E1.code E2.code
gen(E.place E1.place and
E2.place)
13
??????? e?f??se?? s??epa??µe?? a?apa??stas?
?d??t?te? E.code se??? e?t???? p?? pa?????ta?
??a t?? E E.false et???ta d?a???d?s?? a? ? E
e??a? false E.true et???ta d?a???d?s?? a? ? E
e??a? true (E.code e??a? s????s?µ? e?? ??
E.true ?a? E.false e??a? ???????µ?s?µe?) id.plac
e ??s? t?? id
?a?a????? S?µas????????? ?a???e? E ? id1 relop
id2 E.code ? gen(if id1.place relop.op
id2.place goto E.true) gen(goto
E.false) E ? E1 and E2 E1.true ?
newlabel() E1.false ? E. false E2.true ?
E. true E2.false ? E. false E.code ?
E1.code gen(E1.true ) E2.code
?p???sd?p?te te?est?? s?s??t?s?? , lt, gt !
?a s???e???µ??a s?µe?a t?? ??d??a s?µp???????ta?
µe t?? ?at?????e? et???te? ?ta? a?t?? ??????
d?a??s?µe?
? d?µ???????e?sa et???ta t?p??ete?ta? st? ??s?
t?? E1.true st?? ??d??a t?? E1
14
?a??de??µa ??????? e?f??se??
????µ?t??? a?apa??stas?
100 if x lt y goto 103 101 t1 0 102 goto
104 103 t1 1 104 if a b goto 107 105 t2
0 106 goto 108 107 t2 1 108 t3 t1 and t2
T?se?? e?t???? t???? d?e????se?? ?a? ??? et???te?
?????? ??f?as? e?s?d?? x lt y and a b
S??epa??µe?? a?apa??stas?
if x lt y goto L1 goto LFalse L1 if a b goto
LTrue goto LFalse ... LTrue LFalse
?? et???te? a?t?? pa?????ta? se µeta?e??ste??
f?s? ?a? t?p??et???ta? st? s?st? ??s? t??
??d??a
15
??t???? e?????? ????
  • If-then-else
  • ??a???d?s? a?????a µe t? ap?t??esµa
  • ??????? ??f?as??
  • ?????? (loops)
  • ?p?t?µ?s? s??????? p??? ap? t? loop
  • (a? ??e???eta?)
  • ?p?t?µ?s? s??????? µet? ap? t? loop
  • ??a???d?s? st?? a???, a? ?s??e? ? s??????
  • While, for, do ?a? until ???p?????ta? ??a ?ts?

16
??t???? e?????? ???? d?µ? ??d??a
S ? if E then S1 else S2
S ? while E do S1
st? E.true
S.begin
st? E.true
E.code
a? ? E e??a? true
E.code
st? E.false
st? E.false
a? ? E e??a? false
E.true
E.true
S1.code
S1.code
goto S.next
goto S.begin
E.false
E.false
?
S2.code
?
?
S.next
?
?
?
17
??t???? e?????? ???? pa?a???? ??d??a
?d??t?te? S.code se??? e?t???? p??
pa?????ta? ??a t?? S S.next et???ta ??a t??
e?t??? p?? ?a e?te?este? aµ?s?? µet? t?? S (?
S.next e??a? ???????µ?s?µ? ?d??t?ta)
?a?a????? S?µas????????? ?a???e? S ? if E then
S1 else S2 E.true ? newlabel() E.false ?
newlabel() S1.next ? S. next S2.next ?
S. next S.code ? E.code gen(E.true )
S1.code gen(goto S.next) gen(E.false
) S2.code S ? while E do S1 S.begin ?
newlabel() E.true ? newlabel() E.false ?
S. next S1.next ? S. begin S.code ?
gen(S.begin ) E.code gen(E.true )
S1.code gen(goto S.begin) S ? S1
S2 S1.next ? newlabel() S2.next ?
S.next S.code ? S1.code gen(S1.next )
S2.code
18
?a??de??µa e?t???? e?????? ????
L1 if a lt b goto L2 goto LNext L2 if c lt d
goto L3 goto L4 L3 t1 y z x t1 goto
L1 L4 t2 y z x t2 goto L1 LNext
...
?p?spasµa p??a??? ??d??a while (a lt b)
if (c lt d) x y z else
x y z
19
Backpatching
  • ?? E.true, E.false, S.next µp??e? ?a µ?? e??a?
    ef??t? ?a ?p?????s???? µe ??a p??asµa (e??a?
    ???????µ?s?µe? ?d??t?te?)
  • ?? backpatching e??a? µ?a te????? d?µ??????a?
    et??et?? E.true, E.false, S.next ?a? e?sa?????
    t??? st?? ?at?????e? ??se?? ??d??a µe ??a µ???
    p??asµa
  • ?as??? ?d?a
  • ??at????µe t?? ??ste? E.truelist, E.falselist,
    S.nextlist
  • E.truelist ? ??sta t?? e?t???? ?p?? p??pe? ?a
    s?µp?????e? ? et???ta ??a t? E.true ?ta? a?t?
    ???e? d?a??s?µ?
  • S.nextlist ? ??sta t?? e?t???? ?p?? p??pe? ?a
    s?µp?????e? ? et???ta ??a t? S.next ?ta? a?t?
    ???e? d?a??s?µ?
  • ?ta? ?????? d?a??s?µe? ?? t?µ?? t?? E.true,
    E.false, S.next t?te s?µp???????ta? ?? et???te?
    st?? e?t???? p?? a?af????ta? st?? ??ste?

20
?a?a???? ??d??a st? µeta???tt?st? t?? YAPL
  • St? µeta???tt?st? t?? ί?ί????
  • pa???eta? ??d??a? assembly
  • ape??e?a?, µe µetad?ateta?µ??? d??s??s? t??
    s??ta?t???? d??d??? ap? a??ste?? p??? ta de???
  • ?e ???s?µ?p??e?ta? ??d??a? t???? d?e????se?? ?
    ??p??a ???? µ??f? e?d??µes?? a?apa??stas?? e?t??
    t?? pa?a??µe??? s??ta?t???? d??t???

21
S????t?s? d?µ??????a? e?t????
void emit_code(char keno,char optr,char
opd1,char opd2,char opd3) char
kodikas81 if(keno 'y')
strcpy(kodikas," ")
strcat(kodikas,optr) else
strcpy(kodikas,optr) if(strlen(opd1) gt 0)
strcat(kodikas," ")
strcat(kodikas,opd1) if(strlen(opd2) gt 0)
strcat(kodikas,",")
strcat(kodikas,opd2) if(strlen(opd3) gt
0) strcat(kodikas,",")
strcat(kodikas,opd3)
strcat(kodikas,"\n")
fputs(kodikas,femitc)
22
S????t?s? d??s??s?? d??d???
  • void CodeGeneration(AstNode p, int lev, int
    lvalue, int leftChild)
  • switch (p-gtNodeType)
  • case astEmptyProgram break
  • case astProgram ProcessProgram(p,lev)break
  • case astEmptyDeclSeq break
  • case astDeclSeqProcessDeclSeq(p,lev,lvalue)
    break
  • case astDeclProcessDecl(p,lev,lvalue)break
  • ............................................
    .........
  • case astStmtSeq ProcessStmtSeq(p,lev,lvalue
    )break
  • case astIfElseStmtProcessIfElseStmt(p,lev,l
    value)break
  • case astIfStmtProcessIfStmt(p,lev,lvalue)b
    reak
  • case astExprStmt ProcessExprStmt(p,lev,lval
    ue)break
  • case astNullStmtProcessNullStmt()break
  • case astReadStmt ProcessReadStmt(p,lev)
    break
  • case astPrintStmt ProcessPrintStmt(p,lev)b
    reak
  • case astDecimConst ProcessDecimConst(p)
    break
  • ............................................
    .........
  • case astNotEq ProcessComp(p,lev,lvalue,leftChi
    ld)break

23
S????t?s? epe?e??as?a? ??µί?? PrintStmt
  • void ProcessPrintStmt(AstNode p, int lev)
  • symbol rhs
  • CodeGeneration(p-gtpAstNode0,lev1,FALSE,FALSE
    )
  • rhspop_vs()
  • switch( rhs-gtsclass )
  • case MEMORY
  • case CONSTANT
  • emit_code('y',"mov","ax",rhs-gtname,"")
  • emit_code('y',"push","ax","","")
  • break
  • case REGISTER
  • emit_code('y',"push",rhs-gtname,"","")
  • break
  • emit_code('y',"push","10","","")
  • emit_code('y',"call","_PrintInt","","")
  • emit_code('y',"add","sp","4","")

24
?a?a???? ??d??a ????te?t????? Pentium ?
?ata????t?? ded?µ????
de??t?? st??ίa? (????f?)
?ata????t?? d?e????se??
ί?s? ?p?????sµ?? d?e????se??
de??te? d?e????se?? se s??s? µe µ?a ί?s?
ί?se?? tµ?µ?t?? µ??µ??
25
?a?a???? ??d??a ????te?t????? Pentium ??
  • ?????G?S??S ????T??S?S ?????S (real mode)
  • t? pe??e??µe?? t?? ?ata????t? tµ?µat??
    µetat?p??eta? t?sse?a bit p??? ta a??ste?? (d??.
    p???ap?as???eta? ep? 16)
  • st?? t?µ? p?? p????pte? p??st??eta? ? ap????s?
  • e?t???? ap? t? tµ?µa p?? ?p?de????e? ? CS (code
    segment) se s??d?asµ? µe t?? IP (instruction
    pointer)
  • d?e????s? e?t???? CSIP
  • ?ata????s? ? a?????s? ded?µ???? ap? t? tµ?µa p??
    ?p?de????e? ? DS (data segment)
  • p???e?? st??ίa? t? tµ?µa t?? st??ίa?
    ?p?de????eta? ap? t?? SS (stack segment)

26
?a?a???? ??d??a ????te?t????? Pentium ??I
  • ?p??????? st?? e?????s? tµ?µ?t?? µ??µ??

27
?a?a???? ??d??a ????te?t????? Pentium ?V
  • o EFLAGS e??a? ?ata????t?? s?µa???
  • ?? e?t???? ???s?µ?p????? ded?µ??a ta ?p??a
    ί??s???ta? e?te
  • se ?ata????t?? ded?µ????
  • e?te st?? ?d?a t?? e?t???
  • e?te st? µ??µ?
  • ??????a µe t?? t?p? t?? e?t???? ta ded?µ??a
    µp??e? ?a e??a?
  • e??? byte
  • µ?a? ????? (word)
  • µ?a? d?p??? ????? (double)
  • ???????st? ??a ap? ta ded?µ??a p??pe? ?a
    ί??s?eta? se ?ata????t?

28
?a?a???? ??d??a ??t???? assembly I
  • MOV p?????sµ??, afet???a
  • ? e?t??? MOV ?ata???e? st?? p?????sµ? a?t???af?
    t?? de?te??? te?est???. ?? ? p?????sµ?? e??a?
    ??a? ap? t??? ?ata????t?? tµ?µat?? (DS, ES, SS,
    FS, GS), t?te ? afet???a p??pe? ?a e??a? ??a? ap?
    t??? ?ata????t?? ded?µ????.
  • ADD p?????sµ??,afet???a
  • ? e?t??? ADD p??s??te? d?? a?e?a????. ?
    p?????sµ?? d????e? t?? p?????sµ? t??
    ap?te??sµat?? t?? p?????, d??ad? ?t? t? ?????sµa
    ?ata???e?ta? st?? ?ata????t? ? st? d?e????s?
    p?????sµ??.
  • SUB p?????sµ??,afet???a
  • ? e?t??? SUB afa??e? t? de?te?? te?est?? ap? t??
    p??t?. ? d?af??? ?ata???e?ta? st?? ?ata????t? ?
    st? µ??µ? p?????sµ??.
  • IMUL
  • ???s?µasµ???? p???ap?as?asµ?? se d??f??e? µ??f??
    µe ??a ? d?? ???sµata.

29
?a?a???? ??d??a ??t???? assembly I?
  • ? e?t??? IMUL e?te?e? p??s?µasµ???
    p???ap?as?asµ?. ??p??e? µ??f?? t?? e?t????
    ???s?µ?p????? ?µµesa te?est???? p?? ί??s???ta? se
    ?ata????t??.
  • IDIV
  • ? e?t??? IDIV e?te?e? p??s?µasµ??? d?a??es?. ?
    d?a??et??? p??pe? ?a ί??s?eta? se ??a? ap? t???
    ?ata????t?? AL, AX ?a? EAX a?????a µe t?? t?p?
    t??, e?? t? p????? ?a? t? ?p????p? ?ata??????ta?
    ?µµesa se s???e???µ????? ?ata????t??. ? d?a???t??
    d?deta? ?? r/m te?est???.

IMUL r/m8 IMUL r/m16 IMUL r/m32 AX?ALr/m byte DX AX?AXr/m word EDX EAX?EAXr/m dword
IMUL r16, r/m16 IMUL r32, r/m32 word register?word registerr/m word dword register?dword registerr/m dword
30
?a?a???? ??d??a ??t???? assembly I?I
IDIV AL, r/m8   IDIV AX, r/m16 IDIV EAX, r/m32 Signed divide AX (where AH must contain sign-extension of AL) by r/m byte. (Results ALQuo, AHRem) Signed divide DXAX (where DX must contain sign-extension of AX) by r/m word. (Results AXQuo, DXRem) Signed divide EDXEAX (where EDX must contain sign-extension of EAX) by r/m dword. (Results EAXQuo, EDXRem)
PUSH ???sµa ? e?t??? PUSH µe???e? t? de??t? t??
st??ίa? ?at? 2 ?ta? t? ???sµa e??a? 16 bit ? ?at?
4 ?ta? t? ???sµa e??a? 32 bit. ? e?t??? PUSH
t?p??ete? t? ???sµa st?? ????f? t?? st??ίa?, t??
?p??a de???e? ? de??t?? t?? st??ίa?.
31
?a?a???? ??d??a ??t???? assembly IV
  • POP ???sµa
  • ? e?t??? POP d?a???fe? ap? t? st??ίa t? ded?µ???
    p?? de???e? ? ?ata????t?? SP ? ESP, ?a? t?
    ap????e?e? st? ???sµa t?? e?t????, p?? µp??e? ?a
    e??a? ??s? µ??µ??, ?ata????t?? ? ?ata????t??
    tµ?µat??. ? ?ata????t?? SP a????eta? ?at? 2 ??a
    16 bit ded?µ??? ? ?at? 4 ??a 32 bit ded?µ???.

32
?a?a???? ??d??a ?a??de??µa
  • ?a?a???? ??d??a ??a ??f?as? e?????s?? t?µ??
  • xabcd-ef

33
?a?a???? ??d??a ?a??de??µa (s????e?a)
  • mov ax,_a
  • imul _b
  • push ax
  • mov ax,_c
  • imul _d
  • pop dx
  • add dx,ax
  • push dx
  • mov ax,_e
  • imul _f
  • pop dx
  • sub dx,ax
  • mov _x,dx

34
?a?a???? ??d??a ?a??de??µa ??
.model small .stack 100h
.586 The Data Segment .data _i sword ?
_j sword ? The Code Segment .code
extrn _print_intproc extrn
_read_intproc main proc mov ax,_at_data
mov ds,ax mov _i,2 mov
_j,-6 mov ax,_i imul _j
push ax call _print_int pop
cx Return to the Operating System mov
ax,4c00h int 21h main endp end
main
  • int i,j
  • i2
  • j-6
  • print(ij)

p??asµa pa?aµ?t??? µ?s? t?? st??ίa?
???s? ?p?p?????µµat??
35
?pe?????s? ??p?? ?ed?µ???? st? ???µ?
  • ??p?? ?ed?µ???? e??a? ??a s????? t?µ?? µe t??
    ep?t?ept?? p???e?? ep? t?? t?µ?? a?t??.
  • ?as???? t?p?? a???a???, p?a?µat????, ???????,
    ?a?a?t??e?
  • ??µ?µ???? t?p?? p??a?e?, e???af??, s?µί???se????
  • ??p?? p??sp??as?? (de??te?)
  • ?e????af? ??p?? ?????? ?p?p?d?? ?a?a?t???st???
    p?? d?a??????? t?? t?µ?? t?? t?p??, t?µ??,
    p???e??
  • ?e????af? ??p?? ?aµ???? ?p?p?d?? ape?????s?
    (d???s?) t?p?? st?? µ??µ?, e?t???? t?? ???ssa?
    t?? epe?e??ast? p?? ???p????? t?? p???e?? t??
    ?????? ep?p?d??

36
????a??? ?
  • ????a??? p??s?µasµ???? e??? byte ap? -128 ???
    127 ?a? µ? p??s?µasµ???? ap? 0 ??? 255
  • arithmos sbyte ? ????? a????? t?µ?
  • apotelesma byte ? ????? a????? t?µ?
  • µe byte d??????µe µ? p??s?µasµ??e? µetaί??t??
    ?a? µe sbyte d??????µe p??s?µasµ??e? µetaί??t??

37
????a??? ??
  • ????a??? d?? byte ap? -32768 ??? 32767 ?a? µ?
    p??s?µasµ???? ap? 0 ??? 65535
  • akeraios sword -3456 µe a????? t?µ?
  • etos word 1998 ep?s?? µe a????? t?µ?
  • ????a??? tess???? byte ap? -2147483648 ???
    2147483647 ?a? µ? p??s?µasµ???? ap? 0 ???
    4294967295
  • lakeraios sdword -543890 µe a????? t?µ?
  • poso dword ? ????? a????? t?µ?

38
????a??? ???
  • ????µ?t???? p???e?? ADD, ADC, INC, SUB, SBB,
    DEC, MUL, IMUL, DIV, IDIV
  • NEG ??a t?? e??es? t?? s?µp????µat???? e???
    a???µ??
  • CMP ??a t? s?????s? d?? a?e?a???

39
??a?µat???? ?
  • ?? p?a?µat???? a???µ?? ape????????ta? µe t? µ??f?
    t?? ????t?? ?p?d?ast????. ? s?µί???sµ?? a?t??
    ίas??eta? st? p??s?µ? S, t? ???sµa F, t?? e???t?
    E, ?a? a?apa??st? µ?a t?µ? V ?? e???
  • V(-1)S F 10E
  • ??a?µat???? ????µ?? ?p??? ????ίe?a?
  • ??a?µat???? ????µ?? ??p??? ????ίe?a?

40
??a?µat???? ??
  • arithmos real4 1.5
  • apotelesma real8 1.0e-25
  • apotelesma real10 -1.2594e10
  • ????µ?t???? p???e?? FADD, FSUB, FMUL, FDIV

41
??????? ??µ?? ?
  • ??a ?????? µetaί??t? µp??e? ?a d????e?
    ???s?µ?p????ta?
  • ??a bit ap? ??a byte t? ?p??? ???s?µ?p??e?ta? ??a
    t?? d???s? pe??ss?te??? ??????? µetaί??t??.
  • t? bit t?? p??s?µ??, a?????ta? t? ?p????p? byte.
  • ??a byte. ?ta? pe????e? t? 0 t?te pa??st??e? t??
    t?µ? FALSE, e?? ?p???sd?p?te ????? a???µ??
    pa??st??e? t? t?µ? TRUE.

42
??????? ??µ?? ??
  • ?? e?t???? ??????? p???e?? e??a? AND, OR, XOR,
    NOT, TEST.
  • ?? e?t???? a?t?? ep??e????? t?? s?µa?e? t??
    ?ata????t? EFLAGS. ??t? p?? µa? e?d?af??e? e??a?
    ? t??p?? µe t?? ?p??? ?? s?µa?e? Zero, Carry ?a?
    Sign pa???s?????? t? ap?t??esµa p?? pa???eta? ap?
    ??????? p???e??.

43
?a?a?t??e?
  • kefalaio byte 'G' µe a????? t?µ?

44
????d??stat?? ???a?e? ?
  • Pascal
  • Pinax arrayminindex..maxindex of element_type
  • C
  • element_type Pinaxn

45
????d??stat?? ???a?e? ??
  • G?a ?a desµe?te? ????? st? µ??µ? a??et?? ??a t??
    ap????e?s? ???? t?? st???e??? t?? p??a?a p??pe?
    ?a ???e? ? e??? d???s?
  • ???µa-p??a?a ίas????-t?p?? n dup (?)
  • xaraktires byte 128 dup (?) ???a?a? 128
    ?a?a?t???? ?????
  • a????? t?µ?.
  • longakeraioi sdword 24 dup (?) ???a?a? 24
    µe????? a?e?a??? ????? a????? t?µ?.
  • pragmatikoi real4 8 dup (1.0) ???a?a? 8
    p?a?µat????
  • a???µ?? µe a????? t?µ? ?s? µe 1.0.

46
????d??stat?? ???a?e? ???
  • ? d???s? p?????? t?? ?p???? ta st???e?a ?????
    d?af??et???? a?????? t?µ?? ???eta? ?? e???
  • ???µa-p??a?a ίas????-t?p??
    t?µ?1,t?µ?2,...,t?µ?k
  • sqrindex sword 1,4,9,16,25,36,49,64,81,100
  • ???sp??as? µ???d??stat?? p??a?a
  • d?e????s? i?? st???e??? d?e??(P1) (
    i-minindex)µ??e???_st???e???

47
????d??stat?? ???a?e? ?V
  • ??a ? d?e????s? t?? 4?? st???e??? t?? p??a?a P,
    p?? s?µί????eta? ?? P4, ί??s?eta? µe t?? t?p?
  • d?e????s? 4?? st???e??? P ( 4-1)2 P 6
  • mov bx,i bxi
  • sub bx,1 bxi-1
  • add bx,bx bx(i-1)2
  • mov ax,Pbx axpe??e??µe??(P(i-1)2)
  • ?
  • mov bx,i bxi
  • sub bx,1 bxi-1
  • shl bx,1 bx(i-1)2
  • mov ax,Pbx axpe??e??µe??(P(i-1)2)

48
????d??stat?? ???a?e? V
  • ? a??? t?? p??a?a ap????e?eta? st?? ?ata????t?
    ί?s?? bx ?a? ? de??t?? t?? st???e??? st??
    ?ata????t? si. ? ?p?????sµ?? t?? d?e????s??
    ???eta? ?? e???
  • lea bx,P bxaddress of P
  • mov si,i sii
  • sub si,1 sii-1
  • shl si,1 si(i-1)2
  • mov ax,bxsi axpe??e??µe??(P(i-1)2)
  • ? d?af??? fa??eta? st?? ?p?????sµ? t?? ??s??
    ????? st???e??? t?? ?d??? p??a?a, ?p?? ? µ????
    ?p?????sµ?? p?? ?a ???e? ?a e??a? a?t?? t?? ??s??
    t?? st???e???
  • mov si,i2 sii2
  • sub si,1 sii2-1
  • shl si,1 si(i2-1)2
  • mov ax,bxsi axpe??e??µe??(P(i2-1)2)

49
???a?e? ?????? ??ast?se?? ?
  • Pascal
  • Pinaxkarrayminindex1..maxindex1,...,minindex?..m
    axindex? of element_type
  • C
  • element_type Pinaxkn1n2...nk

50
???a?e? ?????? ??ast?se?? ??
  • ?at?ta?? µe p??t? t? ??aµµ?
  • ??s? d?e????s?_p??t??_st???e???
    ((de??t??_??aµµ?? 1)
  • p?????_st???e???_??aµµ?? (de??t??_st???? 1))
    µ??e???_st???e???

51
???a?e? ?????? ??ast?se?? ???
  • ?at?ta?? µe p??t? t? st???
  • ??s? d?e????s?_p??t??_st???e???
    ((de??t??_??aµµ?? 1)
  • (de??t??_st???? 1) p?????_st???e???_??aµµ??)
    µ??e???_st???e???
Write a Comment
User Comments (0)
About PowerShow.com