SlideShare une entreprise Scribd logo
1  sur  25
Computer Organization and
Assembly Language
Introduction
• Processorunderstands only machine language instructions which are strings
of 1sand0s.
• The low level assembly language is designed for aspecific family of
processorsthat represents various instructions in symbolic code and amore
understandable form.
What isAssembly
• An assembly language is alow-level programming language for acomputer,
or otherprogrammable device.
• Assembly language is converted into executable machine code by autility
program referred to asanassembler.
WhyAssembly?
• An understanding of assembly language provides knowledge of:
• Interface of programswith OS,processorand BIOS.
• Representationof data in memory and other external devices.
• How processor accessesandexecutes instruction.
• How instructionsaccessesandprocessdata
WhyAssembly?
• It requires lessmemory and execution time
• It allows hardware-specific complex jobs in an easier way
• It is most suitable for writing interrupt service routines and other memory
resident programs
Instruction
executions
• Fetching the instruction from memory
• Decoding or identifying the instruction
• Executing the instruction
• Byte – sequence of 8 bits:
16 35 4 07 2
MSB (Most Significant Bit) LSB (Least Significant Bit)
• Bit – basic information unit: (1/0)
• Word – a sequence of bits addressed as a single entity by the computer
byte byte 16 bit word
• Main Memory is an array of bytes,
addressed by 0 to 232-1=0xFFFFFFFF
232 bytes = 4∙210∙3 bytes = 4 G bytes
…
…
232-1
2K-1
1
0
address
space
physical
memory
Data Representation Basics
DataSize
• Theprocessor supports the following data sizes:
• Word: a2-byte dataitem
• Doubleword: a4-byte (32bit) data item
• Quadword: an8-byte (64 bit) data item
• Paragraph:a16-byte (128bit) area
Register file - CPU unit which contains (32 bit) registers.
general purpose registers
EAX, EBX, ECX, EDX
(Accumulator, Base, Counter, Data)
index registers
ESP, EBP, ESI, EDI
(Stack pointer - contains the address of last used
dword in the stack, Base pointer, Source index,
Destination Index)
flag register / status register
EFLAGS
Instruction Pointer / Program Counter EIP / EPC
- contains address (offset) of the next instruction that is going to be executed (at run time)
- changed by unconditional jump, conditional jump, procedure call, and return instructions
Registers
Note that the list of registers above is partial. The full list can be found here.
Register file
High byte Low byteExtended
16-bit register
General-purposeregisters
• Some general-purpose registers have specializeduses:
• EAX is automatically usedby multiplication and division instructions.It is often called
the extended accumulatorregister.
• TheCPUautomatically usesECX asaloop counter.
• ESP addresses data on the stack.It is rarely usedfor ordinary arithmetic or data
transfer.It is often calledthe extended stack pointer register.
• ESI and EDI are usedby high-speedmemory transfer instructions.They are sometimes
calledthe extended sourceindex and extended destination index registers.
• EBP is used by high-level languages to reference function parameters and local
variableson the stack.It should not be used for ordinary arithmetic or data transfer
except at anadvanced level of programming.It is often calledthe extended frame
pointer register.
SegmentRegisters
• In real-address mode, 16-bit segment registers indicate baseaddresses of
preassigned memory areas namedsegments.
• In protected mode, segment registers hold pointers to segment descriptor
tables.
Instruction
Pointer
• TheEIP,or instruction pointer, register contains the addressof the next
instruction tobe executed.
EFLAGSRegister
• TheEFLAGS(or just Flags)register consists of individual binary bits that
control the operation of the CPUor reflect the outcome of some CPU
operation
StatusFlags
• The Status flags reflect the outcomes of arithmetic and logical operations
performed by the CPU.They are the Overflow, Sign, Zero, Auxiliary Carry,
Parity, and Carryflags.
StatusFlags
• TheCarryflag (CF)is set whenthe result of anunsignedarithmetic operation is too large to
fit into the destination.
• TheOverflow flag (OF)is set when the result of asignedarithmetic operation is too large or
too small to fit into the destination.
• TheSign flag (SF)is set when the result of anarithmetic or logical operation generates a
negative result.
• TheZero flag (ZF)is set when the result of anarithmetic or logical operation generates a
result ofzero.
• TheAuxiliaryCarryflag (AC)is set when anarithmetic operation causesacarryfrom bit 3to
bit 4 in an8-bit operand.
• The Parity flag (PF)is set if the least-significantbyte in the result containsaneven number
of 1bits. Otherwise, PFis clear. In general, it is used for error checking when there is a
possibility that data might be altered or corrupted.
Assembly Language Program
• consists of a series of processor instructions, meta-statements, comments, and
data
• translated by assembler into machine language instructions (binary code) that
can be loaded into memory and executed
Example:
assembly code:
MOV AL, 61h ; load AL with 97 decimal (61 hex)
binary code:
10110000 01100001
1011 a binary code (opcode) of instruction 'MOV'
0 specifies if data is byte (‘0’) or full size 16/32 bits (‘1’)
000 a binary identifier for a register 'AL'
01100001 a binary representation of 97 decimal
(97d = (int)(97/16)*10 + (97%16 converted to hex
digit) = 61h)
label: (pseudo) instruction operands ; comment
optional fields
either required or forbidden by an
instruction
Notes:
- backslash () : if a line ends with
backslash, the next line is considered
to be a part of the backslash-ended
Examples:
mov ax, 2 ; moves constant 2 to the register ax
buffer: resb 64 ; reserves 64 bytes
Basic Assembly Instruction Structure
• each instruction has its offset (address)
• we mark an instruction with a label to refer it in the code
• (non-local) labels have to be unique
• an instruction that follows a label can be at the same / next line
• colon is optional
…
buffer
RAM
64bytes
2048
mov buffer, 2 = mov 2048, 2 
mov [buffer], 2 = mov [2048], 2 
mov byte [buffer], 2= mov byte [2048], 2 
A typical instruction has 2 operands
- target operand (left)
- source operand (right)
3 kinds of operands exists
- immediate : value
- register : AX,EBP,DL etc.
- memory location : variable or pointer
Instruction Arguments
mov [var1],[var2]! Note that x86 processor does not
allow both operands be memory locations.
Examples:
mov ax, 2 mov [buffer], ax
source operandtarget operand
immediateregister
source operandtarget operand
registermemory location
mov reg8/mem8(16,32),reg8/imm8(16,32)
(copies content of register / immediate (source) to register / memory location (destination))
mov reg8(16,32),reg8/mem8(16,32)
(copies content of register / memory location (source) to register (destination))
MOV - Move Instruction – copies source to destination
Note that NASM doesn’t remember the types of variables you declare . It will
deliberately remember nothing about the symbol var except where it begins, and
so you must explicitly code mov word [var], 2.
operands have to be
of the same size
Examples:
mov eax, 0x2334AAFF mov [buffer], ax mov word [var], 2
imm32reg32
reg16mem16 imm16mem16
ADD - add integers
Example:
add AX, BX ;(AX gets a value of AX+BX)
ADC - add integers with carry
(value of Carry Flag)
Example:
adc AX, BX ;(AX gets a value of AX+BX+CF)
Basic Arithmetical Instruction
<instruction> reg8/mem8(16,32),reg8/imm8(16,32)
(source - register / immediate, destination- register / memory location)
<instruction> reg8(16,32),reg8/mem8(16,32)
(source - register / immediate, destination - register / memory location)
SUB - subtract integers
Example:
sub AX, BX ;(AX gets a value of AX-BX)
SBB - subtract with borrow
(value of Carry Flag)
Example:
sbb AX, BX ;(AX gets a value of AX-BX-CF)
Basic Arithmetical Instruction
<instruction> reg8/mem8(16,32)
(source / destination - register / memory location)
INC - increment integer
Example:
inc AX ;(AX gets a value of AX+1)
DEC - increment integer
Example:
dec byte [buffer] ;([buffer] gets a value of [buffer] -1)
Basic Logical Instructions
<instruction> reg8/mem8(16,32)
(source / destination - register / memory location)
NOT – one’s complement negation – inverts all the bits
Example:
mov al, 11111110b
not al ;(AL gets a value of 00000001b)
;(11111110b + 00000001b = 11111111b)
NEG – two’s complement negation – inverts all the bits, and adds 1
Example:
mov al, 11111110b
neg al ;(AL gets a value of not(11111110b)+1=00000001b+1=00000010b)
;(11111110b + 00000010b = 100000000b = 0)
Basic Logical Instructions
OR – bitwise or – bit at index i of the destination gets ‘1’ if bit at index i
of source or destination are ‘1’; otherwise ‘0’
Example:
mov al, 11111100 b
mov bl, 00000010b
or AL, BL ;(AL gets a value 11111110b)
<instruction> reg8/mem8(16,32),reg8/imm8(16,32)
(source - register / immediate, destination- register / memory location)
<instruction> reg8(16,32),reg8/mem8(16,32)
(source - register / immediate, destination - register / memory location)
AND– bitwise and – bit at index i of the destination gets ‘1’ if bits at index
i of both source and destination are ‘1’; otherwise ‘0’
Example:
or AL, BL ;(with same values of AL and BL as in previous example, AL gets a value 0)
cmp reg8/mem8(16,32),reg8/imm8(16,32)
(source - register / immediate, destination- register / memory location)
cmp reg8(16,32),reg8/mem8(16,32)
(source - register / immediate, destination - register / memory location)
CMP – Compare Instruction – compares integers
Examples:
mov al, 11111100b
mov bl, 00000010b
cmp al, bl ;(ZF (zero flag) gets a value 0)
CMP performs a ‘mental’ subtraction - affects the flags as if the subtraction had
taken place, but does not store the result of the subtraction.
mov al, 11111100b
mov bl, 11111100 b
cmp al, bl ;(ZF (zero flag) gets a value 1)
Ascii table

Contenu connexe

Tendances

12109 microprocessor & programming
12109 microprocessor & programming12109 microprocessor & programming
12109 microprocessor & programmingGaurang Thakar
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic conceptsAbdul Khan
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Lecture 4 assembly language
Lecture 4   assembly languageLecture 4   assembly language
Lecture 4 assembly languagePradeep Kumar TS
 
Assembly language
Assembly languageAssembly language
Assembly languagegaurav jain
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Assembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersAssembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersSrinimf-Slides
 
Unit i se pai_dos function calls
Unit i se pai_dos function callsUnit i se pai_dos function calls
Unit i se pai_dos function callsKanchanPatil34
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programmingKartik Sharma
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Khaja Dileef
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applicationscommiebstrd
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computerMartial Kouadio
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 

Tendances (19)

12109 microprocessor & programming
12109 microprocessor & programming12109 microprocessor & programming
12109 microprocessor & programming
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
Alp 05
Alp 05Alp 05
Alp 05
 
Lec 01 basic concepts
Lec 01 basic conceptsLec 01 basic concepts
Lec 01 basic concepts
 
Intro to assembly language
Intro to assembly languageIntro to assembly language
Intro to assembly language
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Lecture 4 assembly language
Lecture 4   assembly languageLecture 4   assembly language
Lecture 4 assembly language
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Emu8086
Emu8086Emu8086
Emu8086
 
Assembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe ProgrammersAssembler Language Tutorial for Mainframe Programmers
Assembler Language Tutorial for Mainframe Programmers
 
Unit i se pai_dos function calls
Unit i se pai_dos function callsUnit i se pai_dos function calls
Unit i se pai_dos function calls
 
Mp lab manual
Mp lab manualMp lab manual
Mp lab manual
 
Unit 4 assembly language programming
Unit 4   assembly language programmingUnit 4   assembly language programming
Unit 4 assembly language programming
 
Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2Systemsoftwarenotes 100929171256-phpapp02 2
Systemsoftwarenotes 100929171256-phpapp02 2
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
Programming basic computer
Programming basic computerProgramming basic computer
Programming basic computer
 
Assembler
AssemblerAssembler
Assembler
 
Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 

Similaire à Coal (1)

Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacksJapneet Singh
 
Assembly programming
Assembly programmingAssembly programming
Assembly programmingOmar Sanchez
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsCysinfo Cyber Security Community
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationTalal Khaliq
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 
8086-microprocessor-architecture.ppt
8086-microprocessor-architecture.ppt8086-microprocessor-architecture.ppt
8086-microprocessor-architecture.pptMadhan7771
 
Register introduction
Register introductionRegister introduction
Register introductionmaamir farooq
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memoryNico Ludwig
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01destaw belay
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01Siva Raman
 

Similaire à Coal (1) (20)

It322 intro 1
It322 intro 1It322 intro 1
It322 intro 1
 
Buffer overflow attacks
Buffer overflow attacksBuffer overflow attacks
Buffer overflow attacks
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
Amp
AmpAmp
Amp
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basics
 
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral IntegrationA 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
A 32-Bit Parameterized Leon-3 Processor with Custom Peripheral Integration
 
Architecture of pentium family
Architecture of pentium familyArchitecture of pentium family
Architecture of pentium family
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 
Pentium processor
Pentium processorPentium processor
Pentium processor
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
8086-microprocessor-architecture.ppt
8086-microprocessor-architecture.ppt8086-microprocessor-architecture.ppt
8086-microprocessor-architecture.ppt
 
Register introduction
Register introductionRegister introduction
Register introduction
 
(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory(8) cpp stack automatic_memory_and_static_memory
(8) cpp stack automatic_memory_and_static_memory
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
 
SS-assemblers 1.pptx
SS-assemblers 1.pptxSS-assemblers 1.pptx
SS-assemblers 1.pptx
 
microprocessor
 microprocessor microprocessor
microprocessor
 
EC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptxEC8691-MPMC-PPT.pptx
EC8691-MPMC-PPT.pptx
 

Plus de talhashahid40

Plus de talhashahid40 (8)

Talha 11009 call_quiz_addressing_modes
Talha 11009 call_quiz_addressing_modesTalha 11009 call_quiz_addressing_modes
Talha 11009 call_quiz_addressing_modes
 
Only floating point lecture 7 (1)
Only floating point lecture 7 (1)Only floating point lecture 7 (1)
Only floating point lecture 7 (1)
 
Lecture 11
Lecture 11Lecture 11
Lecture 11
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Lecture 9 examples (1)
Lecture 9 examples (1)Lecture 9 examples (1)
Lecture 9 examples (1)
 
Lect 8 updated (1)
Lect 8 updated (1)Lect 8 updated (1)
Lect 8 updated (1)
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Chapter 3 caal (1)
Chapter 3 caal (1)Chapter 3 caal (1)
Chapter 3 caal (1)
 

Dernier

Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learninglevieagacer
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)Areesha Ahmad
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)Areesha Ahmad
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsSérgio Sacani
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Silpa
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryAlex Henderson
 
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICESAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICEayushi9330
 
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flypumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flyPRADYUMMAURYA1
 
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...dkNET
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLkantirani197
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.Nitya salvi
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptxAlMamun560346
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPirithiRaju
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑Damini Dixit
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxFarihaAbdulRasheed
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 

Dernier (20)

Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Alandi Call Me 7737669865 Budget Friendly No Advance Booking
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
Locating and isolating a gene, FISH, GISH, Chromosome walking and jumping, te...
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICESAMASTIPUR CALL GIRL 7857803690  LOW PRICE  ESCORT SERVICE
SAMASTIPUR CALL GIRL 7857803690 LOW PRICE ESCORT SERVICE
 
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit flypumpkin fruit fly, water melon fruit fly, cucumber fruit fly
pumpkin fruit fly, water melon fruit fly, cucumber fruit fly
 
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 

Coal (1)

  • 2. Introduction • Processorunderstands only machine language instructions which are strings of 1sand0s. • The low level assembly language is designed for aspecific family of processorsthat represents various instructions in symbolic code and amore understandable form.
  • 3. What isAssembly • An assembly language is alow-level programming language for acomputer, or otherprogrammable device. • Assembly language is converted into executable machine code by autility program referred to asanassembler.
  • 4. WhyAssembly? • An understanding of assembly language provides knowledge of: • Interface of programswith OS,processorand BIOS. • Representationof data in memory and other external devices. • How processor accessesandexecutes instruction. • How instructionsaccessesandprocessdata
  • 5. WhyAssembly? • It requires lessmemory and execution time • It allows hardware-specific complex jobs in an easier way • It is most suitable for writing interrupt service routines and other memory resident programs
  • 6. Instruction executions • Fetching the instruction from memory • Decoding or identifying the instruction • Executing the instruction
  • 7. • Byte – sequence of 8 bits: 16 35 4 07 2 MSB (Most Significant Bit) LSB (Least Significant Bit) • Bit – basic information unit: (1/0) • Word – a sequence of bits addressed as a single entity by the computer byte byte 16 bit word • Main Memory is an array of bytes, addressed by 0 to 232-1=0xFFFFFFFF 232 bytes = 4∙210∙3 bytes = 4 G bytes … … 232-1 2K-1 1 0 address space physical memory Data Representation Basics
  • 8. DataSize • Theprocessor supports the following data sizes: • Word: a2-byte dataitem • Doubleword: a4-byte (32bit) data item • Quadword: an8-byte (64 bit) data item • Paragraph:a16-byte (128bit) area
  • 9. Register file - CPU unit which contains (32 bit) registers. general purpose registers EAX, EBX, ECX, EDX (Accumulator, Base, Counter, Data) index registers ESP, EBP, ESI, EDI (Stack pointer - contains the address of last used dword in the stack, Base pointer, Source index, Destination Index) flag register / status register EFLAGS Instruction Pointer / Program Counter EIP / EPC - contains address (offset) of the next instruction that is going to be executed (at run time) - changed by unconditional jump, conditional jump, procedure call, and return instructions Registers Note that the list of registers above is partial. The full list can be found here. Register file High byte Low byteExtended 16-bit register
  • 10. General-purposeregisters • Some general-purpose registers have specializeduses: • EAX is automatically usedby multiplication and division instructions.It is often called the extended accumulatorregister. • TheCPUautomatically usesECX asaloop counter. • ESP addresses data on the stack.It is rarely usedfor ordinary arithmetic or data transfer.It is often calledthe extended stack pointer register. • ESI and EDI are usedby high-speedmemory transfer instructions.They are sometimes calledthe extended sourceindex and extended destination index registers. • EBP is used by high-level languages to reference function parameters and local variableson the stack.It should not be used for ordinary arithmetic or data transfer except at anadvanced level of programming.It is often calledthe extended frame pointer register.
  • 11. SegmentRegisters • In real-address mode, 16-bit segment registers indicate baseaddresses of preassigned memory areas namedsegments. • In protected mode, segment registers hold pointers to segment descriptor tables.
  • 12. Instruction Pointer • TheEIP,or instruction pointer, register contains the addressof the next instruction tobe executed.
  • 13. EFLAGSRegister • TheEFLAGS(or just Flags)register consists of individual binary bits that control the operation of the CPUor reflect the outcome of some CPU operation
  • 14. StatusFlags • The Status flags reflect the outcomes of arithmetic and logical operations performed by the CPU.They are the Overflow, Sign, Zero, Auxiliary Carry, Parity, and Carryflags.
  • 15. StatusFlags • TheCarryflag (CF)is set whenthe result of anunsignedarithmetic operation is too large to fit into the destination. • TheOverflow flag (OF)is set when the result of asignedarithmetic operation is too large or too small to fit into the destination. • TheSign flag (SF)is set when the result of anarithmetic or logical operation generates a negative result. • TheZero flag (ZF)is set when the result of anarithmetic or logical operation generates a result ofzero. • TheAuxiliaryCarryflag (AC)is set when anarithmetic operation causesacarryfrom bit 3to bit 4 in an8-bit operand. • The Parity flag (PF)is set if the least-significantbyte in the result containsaneven number of 1bits. Otherwise, PFis clear. In general, it is used for error checking when there is a possibility that data might be altered or corrupted.
  • 16. Assembly Language Program • consists of a series of processor instructions, meta-statements, comments, and data • translated by assembler into machine language instructions (binary code) that can be loaded into memory and executed Example: assembly code: MOV AL, 61h ; load AL with 97 decimal (61 hex) binary code: 10110000 01100001 1011 a binary code (opcode) of instruction 'MOV' 0 specifies if data is byte (‘0’) or full size 16/32 bits (‘1’) 000 a binary identifier for a register 'AL' 01100001 a binary representation of 97 decimal (97d = (int)(97/16)*10 + (97%16 converted to hex digit) = 61h)
  • 17. label: (pseudo) instruction operands ; comment optional fields either required or forbidden by an instruction Notes: - backslash () : if a line ends with backslash, the next line is considered to be a part of the backslash-ended Examples: mov ax, 2 ; moves constant 2 to the register ax buffer: resb 64 ; reserves 64 bytes Basic Assembly Instruction Structure • each instruction has its offset (address) • we mark an instruction with a label to refer it in the code • (non-local) labels have to be unique • an instruction that follows a label can be at the same / next line • colon is optional … buffer RAM 64bytes 2048 mov buffer, 2 = mov 2048, 2  mov [buffer], 2 = mov [2048], 2  mov byte [buffer], 2= mov byte [2048], 2 
  • 18. A typical instruction has 2 operands - target operand (left) - source operand (right) 3 kinds of operands exists - immediate : value - register : AX,EBP,DL etc. - memory location : variable or pointer Instruction Arguments mov [var1],[var2]! Note that x86 processor does not allow both operands be memory locations. Examples: mov ax, 2 mov [buffer], ax source operandtarget operand immediateregister source operandtarget operand registermemory location
  • 19. mov reg8/mem8(16,32),reg8/imm8(16,32) (copies content of register / immediate (source) to register / memory location (destination)) mov reg8(16,32),reg8/mem8(16,32) (copies content of register / memory location (source) to register (destination)) MOV - Move Instruction – copies source to destination Note that NASM doesn’t remember the types of variables you declare . It will deliberately remember nothing about the symbol var except where it begins, and so you must explicitly code mov word [var], 2. operands have to be of the same size Examples: mov eax, 0x2334AAFF mov [buffer], ax mov word [var], 2 imm32reg32 reg16mem16 imm16mem16
  • 20. ADD - add integers Example: add AX, BX ;(AX gets a value of AX+BX) ADC - add integers with carry (value of Carry Flag) Example: adc AX, BX ;(AX gets a value of AX+BX+CF) Basic Arithmetical Instruction <instruction> reg8/mem8(16,32),reg8/imm8(16,32) (source - register / immediate, destination- register / memory location) <instruction> reg8(16,32),reg8/mem8(16,32) (source - register / immediate, destination - register / memory location) SUB - subtract integers Example: sub AX, BX ;(AX gets a value of AX-BX) SBB - subtract with borrow (value of Carry Flag) Example: sbb AX, BX ;(AX gets a value of AX-BX-CF)
  • 21. Basic Arithmetical Instruction <instruction> reg8/mem8(16,32) (source / destination - register / memory location) INC - increment integer Example: inc AX ;(AX gets a value of AX+1) DEC - increment integer Example: dec byte [buffer] ;([buffer] gets a value of [buffer] -1)
  • 22. Basic Logical Instructions <instruction> reg8/mem8(16,32) (source / destination - register / memory location) NOT – one’s complement negation – inverts all the bits Example: mov al, 11111110b not al ;(AL gets a value of 00000001b) ;(11111110b + 00000001b = 11111111b) NEG – two’s complement negation – inverts all the bits, and adds 1 Example: mov al, 11111110b neg al ;(AL gets a value of not(11111110b)+1=00000001b+1=00000010b) ;(11111110b + 00000010b = 100000000b = 0)
  • 23. Basic Logical Instructions OR – bitwise or – bit at index i of the destination gets ‘1’ if bit at index i of source or destination are ‘1’; otherwise ‘0’ Example: mov al, 11111100 b mov bl, 00000010b or AL, BL ;(AL gets a value 11111110b) <instruction> reg8/mem8(16,32),reg8/imm8(16,32) (source - register / immediate, destination- register / memory location) <instruction> reg8(16,32),reg8/mem8(16,32) (source - register / immediate, destination - register / memory location) AND– bitwise and – bit at index i of the destination gets ‘1’ if bits at index i of both source and destination are ‘1’; otherwise ‘0’ Example: or AL, BL ;(with same values of AL and BL as in previous example, AL gets a value 0)
  • 24. cmp reg8/mem8(16,32),reg8/imm8(16,32) (source - register / immediate, destination- register / memory location) cmp reg8(16,32),reg8/mem8(16,32) (source - register / immediate, destination - register / memory location) CMP – Compare Instruction – compares integers Examples: mov al, 11111100b mov bl, 00000010b cmp al, bl ;(ZF (zero flag) gets a value 0) CMP performs a ‘mental’ subtraction - affects the flags as if the subtraction had taken place, but does not store the result of the subtraction. mov al, 11111100b mov bl, 11111100 b cmp al, bl ;(ZF (zero flag) gets a value 1)