SlideShare a Scribd company logo
ARHITEKTURA
 RAČUNARA


              1
16-bitni registri opšte namene
   AX – akumulator za aritmetečke i logičke
    operacije. Neke instrukcije imaju kraće
    kodiranje u slučaju njegovog korišćenja, a
    takođe mogu biti i brže.
   BX – base registar za čuvanje adresa.
   CX – brojač
   DX – registar za aritmetičke i I/O operacije
   Postoje AH, AL, BH, BL, CH, CL, DH, DL.


                                               2
16-bitni registri opšte namene
   SI – source index za indeksiranje
    nizova i pristup memoriji.
   DI – destination index za
    indeksiranje nizova i pristup
    memoriji.
   BP – base pointer sličan BX registru,
    ali za pristup argumentima i lokalnim
    promenljivim funkcija.
   SP – stack pointer pokazivač na stek.
                                        3
Segmentni registri
   Segment je količina memorije koja se može
    adresirati pomoću jednog registra.
   CS – code segment sadrži adresu segmenta koda.
   DS – data segmet sadrži adresu segmenta
    podataka.
   ES – extra segment dodatni segmentni registar.
   SS – stack segment sadrži adresu segmenta koji
    sadrži stek.
   U ove segmente je moguće smeštati i podatke, ali
    to ne treba raditi!


                                                   4
Specijalni registri
   IP – instruction pointer sadrži adresu instrukcije
    koja se trenutno izvršava.
   FLAGS registar se sastoji od sledećih bitova
    •   XXXXODITSZXAXPXC
    •   X – ne koristi se
    •   O – Overflow
    •   D – Direction
    •   I – Interrupt
    •   T – Trace
    •   S – Sign
    •   Z – Zero
    •   A – Auxilary carry
    •   P – Parity
    •   C - Carry
                                                         5
6
Segmentacija
   Pošto je 8086 imao 16-bitne registre, bilo je
    moguće adresirati najviše 65536 bajtova. Ovo je
    veličina jednog segmenta. Da bi se ovo
    prevazišlo, koriste se tzv. segmentni registri koji
    određuju koji se segment koristi.
   Adrese se navode u obliku segment:offset. Npr.
    1000:1F00. Ove adrese se nazivaju logičkim.
   Fizička adresa se, u slučaju da računar radi u real
    modu, dobija tako što se segment množi sa 16 i
    dodaje se offset. Npr. 10000h+1F00h=11F00h
   Očigledno, različite logičke adrese mogu
    odgovarati istoj fizičkoj adresi.
   U slučaju protected moda postupak je
    komplikovaniji.
                                                      7
8
Načini adresiranja memorije za
                  8086
   Validni načini adresiranja memorije se mogu
    dobiti tako što se iz svake kolone donje tabele
    izabere najviše jedan element, pri čemu je
    ukupno potrebno izabrati bar jedan i formira se
    izraz [E1+E2+E3]. Npr.

    mov ax, [50h+bp+si]




                          [BX]    [SI]
              DISP        [BP]    [DI]
                                                      9
Načini adresiranja za 8086
   Prvi registar koji se pojavljuje u
    uglastim zagradama određuje
    podrazumevani segmentni registar.
    On se može navesti i eksplicitno.
   Za BX, SI i DI podrazumeva se DS, a
    za BP - SS.
   Registri se adresiraju navođenjem
    imena.
                                      10
11
12
Adresiranje memorije za 80386
   Adresa se formira kao
    [base+index*scale+disp]
    Npr. mov ax, [bx+si*2+30]




                                13
NETWIDE
ASSEMBLER



            14
NASM
   Pokretanje:
    • nasm –f <format> <filename> [-o <output>]
    • <format> predstavlja jedan od formata u
      kojima se generiše izlaz. Najvažniji su bin i
      obj.
    • <filename> predstavlja ulazni fajl sa kodom.
    • <output> predstavlja naziv izlaznog fajla.
   Naravno, postoje i druge opcije.


                                                      15
NASM
   Izgled komandne linije
    • oznaka: instrukcija operandi    ; komentar
   Bilo koji deo može nedostajati.
   Prisustvo operanada je uslovljeno prirodom instrukcije.
   Ako na kraju linije stoji , sledeća linija se smatra
    nastavkom tekuće.
   Oznake ne moraju imati : na kraju.
   Validna imena oznaka su sastavljena od slova, brojeva, _,
    $, #, @, ~, . i ?. Identifikatori mogu počinjati slovom, ., _
    ili ?.
   Ako ime počinje znakom $, niska se ne tumači kao
    rezervisana reč, već kao identifikator. Npr. $ax.
   Ako se znak $ javi sam, označava trenutnu poziciju
    prilikom asembliranja.


                                                                    16
NASM
   U slučaju bin formata postoje tri
    istaknute sekcije:
    • .text za kod,
    • .data za inicijalizovane podatke i
    • .bss za neinicijalizovane podatke.




                                           17
Pseudo instrukcije – d*
   DB, DW, DD, DQ, DT
    •   db 0x55 – bajt 0x55
    •   db 0x55, 0x56, 0x57 – tri uzastopna bajta
    •   db ‘a’, 0x55 – bajtovi 0x61 i 0x55
    •   db ‘hello’, 13, 10, ‘$’
    •   dw 0x1234 – 0x34, 0x12
    •   dw ‘a’ – 0x61, 0x00
    •   dw ‘ab’ – 0x61, 0x62
    •   dw ‘abc’ – 0x61, 0x62, 0x63, 0x00
    •   dd 0x12345678 – 0x78, 0x56, 0x34, 0x12
    •   dd 1.234567e20
    •   dq 1.234567e20
    •   dt 1.234567e20
   dq i dt ne prihvataju numeričke konstante ili niske za
    operande (?).

                                                             18
Pseudo instrukcije – RES*
   RESB, RESW, RESD, RESQ i REST
    rezervišu memoriju za
    neinicijalizovane podatke. Predviđeno
    je da se koristi u bss sekciji. Npr.
    • buffer:   resb    64




                                        19
Pseudo instrukcije – EQU
   EQU služi da definiše konstantu. Npr.
    • msglen   equ 12




                                        20
Pseudo instrukcije - TIMES
   Čini da instrukcija bude asemblirana
    više puta. Npr.
    • zerobuff: times 64 db 0
    • buffer: db ‘hello, world’
              times 64-($-buffer) db ‘ ’
    • times 100 movsb
    • times 100 resb 1 ili resb 100


                                           21
Promenljive
   Promenljive u punom smislu nisu
    podržane. Sve što se pamti uz simbol
    prilikom deklaraciji je početna adresa
    u memoriji. Dužina se mora
    naknadno zadati u instrukciji. Npr.
    • var dw 5
    • mov word [var], 2
    • mov bx, var

                                         22
Pristup memoriji
   Za sva pristupanja memoriji moraju
    biti koripšćene uglaste zagrade.
    • var    dw 5
    • mov   ax, [var]
    • mov   ax, [var+1]
    • mov   ax, [ds:var+bx]
    • mov   ax, [bp+di+8]
    • mov   ax, [byte bx+6]

                                         23
Numeričke konstante
   mov   ax,   100   ; dekadna
   mov   ax,   0a2h ; hex
   mov   ax,   $0a2 ; hex
   mov   ax,   0xa2 ; hex
   mov   ax,   777q ; oktalna
   mov   ax,   777o ; oktalna
   mov   ax,   10010011b ; binarna

                                      24
Karakterske konstante
   Do 4 karaktera ograničena
    jednostrukim ili dvostrukim
    navodnicima. Npr. ‘abcd’ se prevodi
    kao 0x64636261. S obzirom da se
    radi o little-endian arhitekturi,
    zapisuje se kao 0x61626364 što je i
    željeno.


                                          25
Stringovi
   Izgledaju kao karakterske konstante,
    samo što su duže. Dozvoljene su
    samo u nekim pseudo instrukcijama.
   db ‘hello’ ; string
   db ‘h’,’e’,’l’,’l’,’o’ ; karakterska
    konstanta
   dd ‘ninechars’
   dd ‘nine’, ‘char’, ‘s’
   db ‘ninechars’,0,0,0
                                       26
Realne konstante
   podrzane su realne konstante u pokretnom
    zarezu
   mogu se koristiti samo kao operandi
    instrukcija dd, dq i dt

dd 1.2
dq 1.e10
dq 1.e+10
dq 1.e−10
dt 3.141592653589793238462

                                           27
SEG i WRT
   SEG operator vraća adresu podrazumevanog
    segmenta za neki simbol. Npr sledeći kod smešta
    pokazivač na promenljivu simbol u ES:BX
    •   mov   ax, seg simbol
    •   mov   es, ax
    •   mov   bx, simbol
   Ukoliko želimo da izračunamo adresu neke
    promenljive u odnosu na neki segment koji nije
    podrazumevani koristimo WRT operator. Npr.
    • mov ax, adresa_segmenta
    • mov es, ax
    • mov bx, simbol wrt adresa_segmenta

                                                     28
Kritični izrazi
   Kritični izrazi su izrazi čija vrednost mora
    biti poznata u prvom prolazu asembliranja.
   Argumenti pseudo instrukcija TIMES, RES*
    i ЕQU su kritični izrazi.
   Primer:
             times (label-$) db 0
    label:   db ‘tekst’

             times (label-$+1) db 0
    label:   db ‘tekst’


                                               29
mov ax,symbol1
symbol1 equ symbol2
symbol2:

mov eax,[ebx+offset]
offset equ 10




                       30
Lokalne oznake
   Lokalnim se smatraju oznake koje počinju
    tačkom. Vezuju se za prvu prethodnu oznaku.
    Npr.
    label1 ; neki kod
    .lokalna ; neki kod
    label2 ; neki kod
    .lokalna ; neki kod
   Prilikom korišćenja oznake .lokalna nema
    konflikta imena jer se prva interno vodi kao
    label1.lokalna, a druga kao label2.lokalna, a
    mogu se i tako referencirati. Npr.
    • jmp label1.lokalna

                                                    31
Direktive
   BITS određuje da li će se kod izvršavati na 16-bitnom ili
    32-bitnom procesoru. Npr.
    • BITS 16
   SECTION (ili SEGMENT) definiše sekcije. Npr. .text, .data
    i .bss.
   EXTERN deklariše simbole iz drugih fajlova sa kojima
    eventualno vršimo povezivanje.
   GLOBAL čini simbole vidljivim izvan fajla prilikom
    povezivanja.
   CPU određuje skup instrukcija koje se koriste. Npr.
    •   CPU   8086
    •   CPU   186
    •   CPU   PENTIUM
    •   CPU   IA64



                                                                32
Izlazni formati
   bin – čist mašinski kod.
   Podrazumeva se BITS 16
   Koristi se za pisanje kernela, bootloadera,
    malih programa za DOS, drajvera...
   ORG direktiva određuje adresu na kojoj se
    očekuje da počne izvršavanje programa.
    Npr.
    • ORG 0x100 ; očekivano kod .com programa


                                                33
Izlazni formati
   obj – Microsoft-ov objektni format
   Izlazni kod se mora povezati pomoću
    linkera.
   Nema privilegovanih sekcija.
   Program uvek počinje od oznake
    ..start


                                      34
Prekidi
   Prekidi se dele na:
    • Hardverske
    • Softverske
    • Izuzetke
   BIOS obezbeđuje veći broj
    softverskih prekida koji nam
    omogućavaju da radimo sa ulazom i
    izlazom.
                                        35

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

1.cas

  • 2. 16-bitni registri opšte namene  AX – akumulator za aritmetečke i logičke operacije. Neke instrukcije imaju kraće kodiranje u slučaju njegovog korišćenja, a takođe mogu biti i brže.  BX – base registar za čuvanje adresa.  CX – brojač  DX – registar za aritmetičke i I/O operacije  Postoje AH, AL, BH, BL, CH, CL, DH, DL. 2
  • 3. 16-bitni registri opšte namene  SI – source index za indeksiranje nizova i pristup memoriji.  DI – destination index za indeksiranje nizova i pristup memoriji.  BP – base pointer sličan BX registru, ali za pristup argumentima i lokalnim promenljivim funkcija.  SP – stack pointer pokazivač na stek. 3
  • 4. Segmentni registri  Segment je količina memorije koja se može adresirati pomoću jednog registra.  CS – code segment sadrži adresu segmenta koda.  DS – data segmet sadrži adresu segmenta podataka.  ES – extra segment dodatni segmentni registar.  SS – stack segment sadrži adresu segmenta koji sadrži stek.  U ove segmente je moguće smeštati i podatke, ali to ne treba raditi! 4
  • 5. Specijalni registri  IP – instruction pointer sadrži adresu instrukcije koja se trenutno izvršava.  FLAGS registar se sastoji od sledećih bitova • XXXXODITSZXAXPXC • X – ne koristi se • O – Overflow • D – Direction • I – Interrupt • T – Trace • S – Sign • Z – Zero • A – Auxilary carry • P – Parity • C - Carry 5
  • 6. 6
  • 7. Segmentacija  Pošto je 8086 imao 16-bitne registre, bilo je moguće adresirati najviše 65536 bajtova. Ovo je veličina jednog segmenta. Da bi se ovo prevazišlo, koriste se tzv. segmentni registri koji određuju koji se segment koristi.  Adrese se navode u obliku segment:offset. Npr. 1000:1F00. Ove adrese se nazivaju logičkim.  Fizička adresa se, u slučaju da računar radi u real modu, dobija tako što se segment množi sa 16 i dodaje se offset. Npr. 10000h+1F00h=11F00h  Očigledno, različite logičke adrese mogu odgovarati istoj fizičkoj adresi.  U slučaju protected moda postupak je komplikovaniji. 7
  • 8. 8
  • 9. Načini adresiranja memorije za 8086  Validni načini adresiranja memorije se mogu dobiti tako što se iz svake kolone donje tabele izabere najviše jedan element, pri čemu je ukupno potrebno izabrati bar jedan i formira se izraz [E1+E2+E3]. Npr. mov ax, [50h+bp+si] [BX] [SI] DISP [BP] [DI] 9
  • 10. Načini adresiranja za 8086  Prvi registar koji se pojavljuje u uglastim zagradama određuje podrazumevani segmentni registar. On se može navesti i eksplicitno.  Za BX, SI i DI podrazumeva se DS, a za BP - SS.  Registri se adresiraju navođenjem imena. 10
  • 11. 11
  • 12. 12
  • 13. Adresiranje memorije za 80386  Adresa se formira kao [base+index*scale+disp] Npr. mov ax, [bx+si*2+30] 13
  • 15. NASM  Pokretanje: • nasm –f <format> <filename> [-o <output>] • <format> predstavlja jedan od formata u kojima se generiše izlaz. Najvažniji su bin i obj. • <filename> predstavlja ulazni fajl sa kodom. • <output> predstavlja naziv izlaznog fajla.  Naravno, postoje i druge opcije. 15
  • 16. NASM  Izgled komandne linije • oznaka: instrukcija operandi ; komentar  Bilo koji deo može nedostajati.  Prisustvo operanada je uslovljeno prirodom instrukcije.  Ako na kraju linije stoji , sledeća linija se smatra nastavkom tekuće.  Oznake ne moraju imati : na kraju.  Validna imena oznaka su sastavljena od slova, brojeva, _, $, #, @, ~, . i ?. Identifikatori mogu počinjati slovom, ., _ ili ?.  Ako ime počinje znakom $, niska se ne tumači kao rezervisana reč, već kao identifikator. Npr. $ax.  Ako se znak $ javi sam, označava trenutnu poziciju prilikom asembliranja. 16
  • 17. NASM  U slučaju bin formata postoje tri istaknute sekcije: • .text za kod, • .data za inicijalizovane podatke i • .bss za neinicijalizovane podatke. 17
  • 18. Pseudo instrukcije – d*  DB, DW, DD, DQ, DT • db 0x55 – bajt 0x55 • db 0x55, 0x56, 0x57 – tri uzastopna bajta • db ‘a’, 0x55 – bajtovi 0x61 i 0x55 • db ‘hello’, 13, 10, ‘$’ • dw 0x1234 – 0x34, 0x12 • dw ‘a’ – 0x61, 0x00 • dw ‘ab’ – 0x61, 0x62 • dw ‘abc’ – 0x61, 0x62, 0x63, 0x00 • dd 0x12345678 – 0x78, 0x56, 0x34, 0x12 • dd 1.234567e20 • dq 1.234567e20 • dt 1.234567e20  dq i dt ne prihvataju numeričke konstante ili niske za operande (?). 18
  • 19. Pseudo instrukcije – RES*  RESB, RESW, RESD, RESQ i REST rezervišu memoriju za neinicijalizovane podatke. Predviđeno je da se koristi u bss sekciji. Npr. • buffer: resb 64 19
  • 20. Pseudo instrukcije – EQU  EQU služi da definiše konstantu. Npr. • msglen equ 12 20
  • 21. Pseudo instrukcije - TIMES  Čini da instrukcija bude asemblirana više puta. Npr. • zerobuff: times 64 db 0 • buffer: db ‘hello, world’ times 64-($-buffer) db ‘ ’ • times 100 movsb • times 100 resb 1 ili resb 100 21
  • 22. Promenljive  Promenljive u punom smislu nisu podržane. Sve što se pamti uz simbol prilikom deklaraciji je početna adresa u memoriji. Dužina se mora naknadno zadati u instrukciji. Npr. • var dw 5 • mov word [var], 2 • mov bx, var 22
  • 23. Pristup memoriji  Za sva pristupanja memoriji moraju biti koripšćene uglaste zagrade. • var dw 5 • mov ax, [var] • mov ax, [var+1] • mov ax, [ds:var+bx] • mov ax, [bp+di+8] • mov ax, [byte bx+6] 23
  • 24. Numeričke konstante  mov ax, 100 ; dekadna  mov ax, 0a2h ; hex  mov ax, $0a2 ; hex  mov ax, 0xa2 ; hex  mov ax, 777q ; oktalna  mov ax, 777o ; oktalna  mov ax, 10010011b ; binarna 24
  • 25. Karakterske konstante  Do 4 karaktera ograničena jednostrukim ili dvostrukim navodnicima. Npr. ‘abcd’ se prevodi kao 0x64636261. S obzirom da se radi o little-endian arhitekturi, zapisuje se kao 0x61626364 što je i željeno. 25
  • 26. Stringovi  Izgledaju kao karakterske konstante, samo što su duže. Dozvoljene su samo u nekim pseudo instrukcijama.  db ‘hello’ ; string  db ‘h’,’e’,’l’,’l’,’o’ ; karakterska konstanta  dd ‘ninechars’  dd ‘nine’, ‘char’, ‘s’  db ‘ninechars’,0,0,0 26
  • 27. Realne konstante  podrzane su realne konstante u pokretnom zarezu  mogu se koristiti samo kao operandi instrukcija dd, dq i dt dd 1.2 dq 1.e10 dq 1.e+10 dq 1.e−10 dt 3.141592653589793238462 27
  • 28. SEG i WRT  SEG operator vraća adresu podrazumevanog segmenta za neki simbol. Npr sledeći kod smešta pokazivač na promenljivu simbol u ES:BX • mov ax, seg simbol • mov es, ax • mov bx, simbol  Ukoliko želimo da izračunamo adresu neke promenljive u odnosu na neki segment koji nije podrazumevani koristimo WRT operator. Npr. • mov ax, adresa_segmenta • mov es, ax • mov bx, simbol wrt adresa_segmenta 28
  • 29. Kritični izrazi  Kritični izrazi su izrazi čija vrednost mora biti poznata u prvom prolazu asembliranja.  Argumenti pseudo instrukcija TIMES, RES* i ЕQU su kritični izrazi.  Primer: times (label-$) db 0 label: db ‘tekst’ times (label-$+1) db 0 label: db ‘tekst’ 29
  • 30. mov ax,symbol1 symbol1 equ symbol2 symbol2: mov eax,[ebx+offset] offset equ 10 30
  • 31. Lokalne oznake  Lokalnim se smatraju oznake koje počinju tačkom. Vezuju se za prvu prethodnu oznaku. Npr. label1 ; neki kod .lokalna ; neki kod label2 ; neki kod .lokalna ; neki kod  Prilikom korišćenja oznake .lokalna nema konflikta imena jer se prva interno vodi kao label1.lokalna, a druga kao label2.lokalna, a mogu se i tako referencirati. Npr. • jmp label1.lokalna 31
  • 32. Direktive  BITS određuje da li će se kod izvršavati na 16-bitnom ili 32-bitnom procesoru. Npr. • BITS 16  SECTION (ili SEGMENT) definiše sekcije. Npr. .text, .data i .bss.  EXTERN deklariše simbole iz drugih fajlova sa kojima eventualno vršimo povezivanje.  GLOBAL čini simbole vidljivim izvan fajla prilikom povezivanja.  CPU određuje skup instrukcija koje se koriste. Npr. • CPU 8086 • CPU 186 • CPU PENTIUM • CPU IA64 32
  • 33. Izlazni formati  bin – čist mašinski kod.  Podrazumeva se BITS 16  Koristi se za pisanje kernela, bootloadera, malih programa za DOS, drajvera...  ORG direktiva određuje adresu na kojoj se očekuje da počne izvršavanje programa. Npr. • ORG 0x100 ; očekivano kod .com programa 33
  • 34. Izlazni formati  obj – Microsoft-ov objektni format  Izlazni kod se mora povezati pomoću linkera.  Nema privilegovanih sekcija.  Program uvek počinje od oznake ..start 34
  • 35. Prekidi  Prekidi se dele na: • Hardverske • Softverske • Izuzetke  BIOS obezbeđuje veći broj softverskih prekida koji nam omogućavaju da radimo sa ulazom i izlazom. 35