• Tidak ada hasil yang ditemukan

Introduction to x86 Assembly

N/A
N/A
Protected

Academic year: 2025

Membagikan "Introduction to x86 Assembly"

Copied!
23
0
0

Teks penuh

(1)

Introduction to x86 Assembly

Lecture INT

x86 Interrupts

(2)

Remember: fetch-execute cycle

CPU

Instructions

Main Memory

Data Data Bus

Address Bus

(3)

Remember: fetch-execute cycle

CPU

Instructions

Main Memory

Data Data Bus

Address Bus

Instructions control CPU, or CPU controls instruction?

(4)

Remember: fetch-execute cycle

● How the OS can terminate/suspend your application?

● How multiple programs are run on a single CPU?

● How to handle events?

● How to get data from input devices while running?

● Alarm apps?

● real time system?

(5)

Remember: fetch-execute cycle

● How the OS can terminate/suspend your application?

● How multiple programs are run on a single CPU?

● How to handle events?

● How to get data from input devices while running?

● Alarm apps?

● real time system?

interrupts

(6)

Interrupt

(7)

Interrupt

(8)

Interrupt

A signal to Processor

Immediate attention

Interrupt handler (interrupt service routine)

(9)

Types of Interrupts

Hardware Interrupts

Software Interrupts

Exceptions

(10)

Hardware Interrupts

● A signal from hardware

● Input devices (keyboard, mouse, scanner, network interface, )

● Interrupt Request (IRQ)

● Asynchronous

(11)

Software Interrupts

int instruction

INT immed8

push EFLAGS

push (far) return address (CS + EIP)

(12)

Exceptions (traps)

● exceptional conditions in execution

○ divide by zero

○ access a protected memory area.

○ write on read-only memory area

(13)

Interrupt

● Hardware/Software Signals CPU

● CPU suspends current activity

● CPU saves its state (registers, flags, etc.)

● CPU calls an Interrupt Service Routine

● CPU retrieves its state

● CPU resumes previous activity

(14)

Real Mode: Interrupt Vector Table (IVT)

● 256 4-byte vectors, Address 0x0 to 0x3F of memory

● each vector CS+IP

● when interrupt happens:

FLAGS, CS and IP are pushed

(15)

Software Interrupts

(16)

Software Interrupts

(17)

Interrupt service routine (ISR)

AKA Interrupt handler

(18)

Software Interrupts

IRET (NASM)

Some other assemblers

IRET

IRETD

IRETQ

(19)

Protection ring

https://en.wikipedia.org/wiki/Protection_ring

(20)

The IPOL flag

https://en.wikipedia.org/wiki/Protection_ring

Carry Flag (CF)

Parity Flag (PF)

Auxiliary Carry Flag (AF)

Zero Flag (ZF)

Sign Flag (SF)

Trap Flag (TF)

Interrupt Flag (IF)

Direction Flag (DF)

Overflow Flag (OF)

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

IOPL (I/O Privilege level)

(21)

Software Interrupts

INT immed8

INT3

INT1

INT0 (32-bit mode only)

Most software interrupts cannot be called from user space

(22)

User-space programs

● User-space applications are run at privilege 0

● Cannot call most software interrupts

● Use OS API's instead

(23)

References

https://en.wikibooks.org/wiki/X86_Assembly

https://wiki.osdev.org/Interrupts

Referensi

Dokumen terkait

Therefore, to correctly read data, execute either the address set instruction or cursor shift instruction (only with DDRAM), then just before reading the desired data, execute the

—  In parallel fetch address used to access branch prediction arrays. •  F3 Instruction data are placed in

The fetch stage is said to be un- derutilized if the number of instructions that can be fetched per cycle from the instruction cache is less than the maximum fetch rate.. Our

A five stage pipelined RISC processor has stages as instruction fetch, decode, execute, memory, write back.. RISC has a simpler and faster instruction set

 Fetch instruction: The processor reads an instruction from memory  Interpret instruction: The instruction is decoded and required action take place  Fetch data: Execution of

Building a Datapath Major components required to execute each class of MIPS instructions • Instruction memory • Need a memory unit to store instructions of a program • Simple

Introduction to 8086 Assembly Lecture 5 Jump, Conditional Jump, Looping, Compare instructions... Example: rem.asm

Clock cycle & instruction timing See ● 8086 Instruction Timing http://www.oocities.org/mc_introtocomputers/ ○ http://www.oocities.org/mc_introtocomputers/Instruction_Timing.PDF ●