Assembly Language Programming (pdf, 3.hafta, 17.02.2016)

Transkript

Assembly Language Programming (pdf, 3.hafta, 17.02.2016)
Assembly Language
Programming
Assembly Programming
• Machine Language
• binary
• hexadecimal
• machine code or object code
• Assembly Language
• mnemonics
• assembler
• High-Level Language
• Pascal, Basic, C
• compiler
2
Assembly Language Programming
3
What Does It Mean to Disassemble
Code?
Preprocessing
& Compiling
Source Code
Assembly Code
Assembly
Executable Code
Object Code
Linking
DLLs
4
What Does It Mean to Disassemble
Code?
Preprocessing
& Compiling
Source Code
Assembly Code
Assembly
Executable Code
Object Code
Linking
DLLs
5
Assembly Language
•
Assembly language veya Assembler language
–
–
–
Bir bilgisayar veya diğer programlanabilen
cihazlara yönelik bir alt-seviye programlama
dilidir. (low-level programming language)
bu dilde genellikle mimarinin makine kod
emirleri ile arasında güçlü bir (genellikle bire-bir)
benzeşme vardır ( architecture’s machine code
instructions)
(Yüksek seviyeli programlama dillerinin tersine)
Her assembly dili, belirli bilgisayar mimarisine
özgüdür.
6
High-level programming language
•
High-level programming language
–
Genellikle çeşitli mimariler arasında taşınabilir
(portable)
–
Fakat yorumlamaya veya derlemeye ihtiyaç duyar
(interpreting or compiling)
7
Assembly Language
•
Assembly language aynı zamanda
– Assembly
– Assembler
– ASM
– Symbolic machine code
– Assembly program
olarak da anılır.
8
Assembly Language
•
Assembly dili, ‘assembler’ olarak anılan bir
utility program tarafından ‘executable
machine code’ a dönüştürülür.
•
Bu dönüşüm işlemi ‘assembly’ olarak anılır
–
assembling the source code
9
Assembly Language
•
•
•
Semboller (symbols) tanımlayarak ve
kullanarak donanımdaki bellek adreslerini
(memory adresses) temsil etmeye imkan tanır
‘mnemonic’ olarak anılan özel sembol
kullanılarak her bir alt-seviye makine emiri
veya operasyon belirtilmiş olur.
Tipik operasyonlar bir veya birden fazla
operand gerektirir.
10
Assembly Programming
•
Assembly dil emirleri 4 alandan oluşur
[label:]
mnemonic [operands] [;comment]
• Label
• mnemonic, operands
• MOV AX, 6764
• comment
• ; this is a sample program
11
Model Definition
MODEL directive
– memory modelinin boyutunu seçer
• MODEL MEDIUM
• Data must fit into 64KB
• Code can exceed 64KB
• MODEL COMPACT
• Data can exceed 64KB
• Code cannot exceed 64KB
• MODEL LARGE
• Data can exceed 64KB (but no single set of data should exceed 64KB)
• Code can exceed 64KB
• MODEL HUGE
• Data can exceed 64KB (data items i.e. arrays can exceed 64KB)
• Code can exceed 64KB
• MODEL TINY
• Data must fit into 64KB
• Code must fit into 64KB
• Used with COM files
12
Segments
• Segment definition:
The 80x86 CPU 4 tane segment registere sahiptir: CS,
DS, SS, ES
• Segments of a program:
.STACK
example:
.STACK
; stack segmentin başlangıcına işaret eder
64
.DATA
example:
.DATA1 DB
.CODE
; 64Byte’lık yığın bellek alanı rezerve eder
; data segmentin başlangıcına işaret eder
52H
; DB direktifi bayt boyutunda parçalar halinde
bellek ayırır
; Code segmentin başlangıcına işaret
eder.
13
Assemble, Link, and Run Program
STEP
INPUT
PROGRAM
OUTPUT
1.
Edit the program
keyboard
editor
myfile.asm
2.
Assemble the program myfile.asm
MASM or TASM
myfile.obj
myfile.lst
myfile.crf
3.
Link the program
LINK or TLINK
myfile.exe
myfile.map
myfile.obj
14
Assemble, Link, Run Files
STEP
.asm – source file
INPUT
PROGRAM
OUTPUT
.obj – machine language file
.lst – list file
- it lists all the Opcodes, Offset addresses, and errors that
MASM detected
.crf – cross-reference file
- an alphabetical list of all symbols and labels used in the
program as well as the program line numbers in which they
are referenced
.map – map file
- to see the location and number of bytes used when there
15
are many segments for code or data
Control Transfer Instructions
•
NEAR – Kontrol, aktif code segment içerisindeki bir bellek
lokasyonuna transfer edildiğinde
•
FAR – Kontrol, aktif code segment dışında bir yere transfer
edildiğinde
CS:IP – Bu register çifti her zaman sıradaki icra edilecek emirin
adresine işaret eder
• NEAR Jump: IP güncellenir, CS aynı kalır
(In a NEAR jump, IP is updated, CS remains the same)
• FAR Jump : hem CS hem de IP güncellenir
( In a FAR jump, both CS and IP are updated)
16
Control Transfer Instructions
•
•
Conditional Jumps
Short Jump
– Tüm koşullu dallanmalar kısa dallanmadır
– Hedefin adresi, IP’nin –128 ile +127 byte aralığında olmalıdır
– Koşullu dallanma 2-byte lık emirdir
• Bir byte’ı dallanma şartının opcode’udur
• 2.byte ise 00 ile FF arasında bir sayıdır
• 256 olası addres:
forward jump to +127
backward jump to –128
17
Data Types and Data Definition
•
Assembler data directives

ORG (origin) – to indicate the beginning of the offset address
 example:
ORG

0010H
DB (define byte) – allocation of memory in byte-sized chunks
 example:
DATA1
DATA2
DATA3
DATA4
DATA5
DATA6
DATA7
DB
DB
DB
DB
DB
DB
DB
25
10001001B
12H
‘2591’
?
‘Hello’
“O’ Hi”
;decimal
;binary
;hex
;ASCII numbers
;set aside a byte
;ASCII characters
;ASCII characters18
Data Types and Data Definition
•
Assembler data directives

DUP (duplicate) – to duplicate a given number of characters
 example:
DATA1 DB 0FFH, 0FFH, 0FFH, 0FFH
Can be replaced with:
DATA2 DB
4 DUP(0FFH)
;fill 4 bytes with FF
DATA3
DB
30 DUP(?)
;set aside 30 bytes
DATA4
DB
5 DUP (2 DUP (99))
;fill 10 bytes with 99
;fill 4 bytes with FF
19
Data Types and Data Definition
•
Assembler data directives

DW (define word) – allocate memory 2 bytes (one word) at a time
 example:
DATA1
DATA2
DATA3
DATA4
DATA5

DW
DW
DW
DW
DW
342
01010001001B
123FH
9,6,0CH, 0111B,’Hi’
8 DUP (?)
;decimal
;binary
;hex
;Data numbers
;set aside 8 words
EQU (equate) – define a constant without occupying a memory
location
 example:
COUNT
EQU
25
;COUNT can be used in many places in the program
20
EXE vs. COM
•
COM files
• Smaller in size (max of 64KB)
• Does not have header block
•
EXE files
• Unlimited size
• Do have header block (512 bytes of memory, contains
information such as size, address location in memory, stack
address)
21

Benzer belgeler

CV - EN / Bilkent University

CV - EN / Bilkent University Microwave & System Technologies Division:  Test  Engineering Department 

Detaylı

Assembly dili programların 2

Assembly dili programların 2 Programın ilk satırında yer alan .model tiny satırı, işlemci üreticisi tarafından önerilen Bellek Modellerinden com uzantılı dosyalar için kullanılan ve bellek parçalarının (kod, veri, yığın ve eks...

Detaylı

1.1 16 Port 230 Watt PoE Kenar Switch 1.1.1

1.1 16 Port 230 Watt PoE Kenar Switch 1.1.1 Cihazın anahtar kapasitesi minimum 40Gbps/non-blocking ve Mac adres tablosu büyüklüğü en az 8K olmalıdır. Cihazın Throughput kapasitesi 29.7Mbps@64Byte olmalıdır. Cihazın Jumbo frame’i 9216 bytes o...

Detaylı