EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

There are two types of addressing schemes:
CSCI 4717/5717 Computer Architecture
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
CS2422 Assembly Language & System Programming November 2, 2006.
Interrupt Processing Haibo Wang ECE Department
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Introduction to Interrupts
8051 ASSEMBLY LANGUAGE PROGRAMMING
ICS312 Set 11 Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
The 8051 Microcontroller and Embedded Systems
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
EEL 3801C EEL 3801 Part II System Architecture. EEL 3801C Components Video Display Terminal – self explanatory Keyboard – self-explanatory Disk Drives.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Functions/Methods in Assembly
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
JUMP, LOOP, AND CALL INSTRUCTIONS
MODULE 5 INTEL TODAY WE ARE GOING TO DISCUSS ABOUT, FEATURES OF 8086 LOGICAL PIN DIAGRAM INTERNAL ARCHITECTURE REGISTERS AND FLAGS OPERATING MODES.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Internal Programming Architecture or Model
Block diagram of a computer system Basic components of a computer system using block diagrams: Cpu Memory Input and output unit Evolution of microprocessor.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
I NTEL 8086 M icroprocessor بسم الله الرحمن الرحيم 1.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Instruction set Architecture
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Computer Organization & Assembly Language Chapter 3
Computer Organization And Assembly Language
Instruksi Set Prosesor 8088
Introduction of microprocessor
Microprocessor and Assembly Language
Machine control instruction
Microcomputer Programming
Microprocessor and Assembly Language
Chapter 3 Addressing Modes
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
Interrupts.
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
8051 ASSEMBLY LANGUAGE PROGRAMMING
Computer Organization and Assembly Language
Microprocessor and Assembly Language
Presentation transcript:

EEL 3801 Part IV The Assembler

OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of the segment. The destination operand must be a 16-bit register. When a register holds an address (offset) rather than the value therein, it is a pointer to that variable.

SEG Operator Returns the segment part of a label’s address. The segment from which the offset is being displaced. Not the offset.

Example Used when the base segment register must be initialized to a new segment. Assume array is in a segment other than what DS points to: push ds;Save contents of DS mov ax,seg array ; set DS to seg mov ds,ax ; of array mov bx,offset array ; set offset.; compute whatever pop ds; restore original DS

PTR Operator Specifies the size of an operand. Can override an operand’s default size –BYTE PTR (8-bit) –WORD PTR (16-bit) –DWORD PTR (32-bit) –QWORD PTR (64-bit) –TBYTE PTR (80-bit)

LABEL Directive Another way to override a variable’s default type. Does not allocate more memory Just redefines an existing variable.

Transfer of Control Instructions CPU executes instructions sequentially, in the exact order presented. Occasionally, we want a slightly different order of execution, –so must tell assembler so that it knows what is the next instruction to load and decode prior to execution.

Transfer of Control Instructions (cont.) Two types: –Conditional transfers –Unconditional transfers.

Unconditional Transfers Program branches to new location all the time, unconditionally. New value loaded into the instruction pointer.

Conditional Transfer Branching only if certain conditions are true. CPU interprets true/false condition based on content of CX and Flags registers. Some examples of these instructions:

JMP Instruction Tells CPU to begin execution at another location. New location to be identified by label Label translated by assembler into new address. If jump is to label in current segment, label’s offset loaded into the IP register. If jump is to another segment, segment address additionally loaded into CS.

JMP Instruction (cont.) Syntax is: JMP SHORT/NEAR PTR/FAR PTR destination where SHORT => destination within –128 to 127 bytes NEAR PTR => destination in same segment (default) FAR PTR => destination in another segment destination => a label or 32 bit segment-offset address.

JMP Instruction (cont.) Can move to just about anywhere, to same procedure, to another procedure, to another segment, to RAM or ROM or completely out of the current program. Loop based on JMP will never end.

LOOP Instruction Repeats a block of instructions a specific number of times. Uses CX as a counter, and decrements it every iteration. The number of cycles must be loaded into CX prior to the loop taking place. Format is: LOOP destination

LOOP Instruction (cont.) Destination must be from –128 to 127 bytes away from the current location. Destination typically behind loop instruction. When it gets to LOOP, assembler decrements CX by 1. If not zero, transfers control to destination.

Example #1 mov cx,12*80 next: mov ah,2;DOS function display char mov dl,’A’ int 21h; Call DOS function on ah loop next

Example #2 sum_an_array: mov ax,0 mov di,offset intarray mov cx,4 ; array size read_int: add ax,[di]; add integer to accum add di,2 loop read_int intarray dw 200h, 100h, 300h, 600h

Procedures It is generally infeasible to write a program consisting of long sequence of instructions. True in assembly or high level language. More likely, blocks of code that do something logically related complex mathematical calculation, setting up or retrieving a data structure, printing something reading a file.

Procedures (cont) By grouping and interacting these blocks of code, a program is much easier to write, debug and document. Moreover, the blocks of code may be reusable either in the same program, or in other programs. These blocks of code are called procedures, or subroutines.

Procedures (cont) Procedures or subroutines represent a branching of the program control when a call to a subroutine is reached in the program execution. The assembler must return to the instruction after the one that called the subroutine.

Procedures (cont) The subroutine can be called through the instruction CALL followed by the name of the subroutine. CALL saves address of next instruction to stack, depending on whether near or far call. This is different from the JMP instruction: –JMP does not require a return to the original address from where it was called.

Procedures (cont) Subroutines that return a value. They are typically equated to a label that takes on the value resulting from the function execution. Procedures do not normally return a value. PROC and ENDP are the bookends that mark the beginning and end of a procedure.

Procedures (cont) These directives must include the name of the procedure, which precedes the directive itself. Procedures must include the RET (return) instruction to pop old value of address from run-time stack. Procedures must not be overlapped. See example on page 107 of text book.

Near and Far Procedures The difference between them is how the assembler remembers where to return to.

Near Call Calling procedure and called procedure are in the same segment of the program. Assembler generates machine code for a near call. Before branching to the subroutine, the CALL instruction preserves the current content of the IP register (the instruction pointer) onto the run-time stack.

Near Call (cont) Remember that the IP points to the next instruction to be executed. It then copies the address of the first instruction of the called subroutine into the IP register. Thus, the CPU follows that sequence of instructions that begins at that address.

Near Call (cont.) At the end of the subroutine, the RET instruction pops the old value of IP into it again from the stack. Execution then resumes right from where the call was made.

Far Call This happens when the calling and called subroutines are in different segments of the code. The assembler then does a far call. Now the CALL instruction preserves both the contents of the IP and the CS register onto the stack. Uses a RETF instruction instead of RET.

Nested Calls Calls can be nested. The CALL instruction keeps the addresses in the run-time stack on a last-in-first-out basis, so there is no problem. The RET instructions are called in reverse order. See example on page 113, Figure 5.7.

Interrupts There are reasons why the CPU needs to be interrupted from its activity. Two types of interrupts: –Hardware interrupts –Software interrupts

Hardware Interrupts Are signals from other parts of the system (hardware) that something needs immediate attention from the CPU. These signals are generated by the Interrupt Controller, a chip called the 8529IC. They allow for important events occurring in the background to be “noticed” by the CPU and immediately acted upon.

Hardware Interrupts - Examples Examples of hardware interrupts are inputs that would be lost if not read and processed quickly. Sources of such interrupts are: –the keyboard, –external memory (disk) drives, –system clock.

The Interrupt Flag Occasionally, however, some processes are highly time-sensitive and do not tolerate any interrupts. The programmer can allow for this by turning off the ability to interrupt the CPU. This is done through the interrupt flag, IF.

The Interrupt Flag (cont.) When the IF is set, interrupts are enabled (normal value); When clear, interrupts are disabled. Instruction CLI clears the interrupt flag (disallows interrupts), Instruction STI sets the interrupt flag (re- enables interrupts).

Software Interrupts These are not really interrupts at all, but rather calls to outside routines such as BIOS or DOS functions. The INT instruction is used to introduce such “interrupts”. format as follows: INT number

The INT Instruction Calls a routine type identified by a number. The number can range between 0 and FFh. The routine type can be one of several, and each type will have its own range of possible functions. The number indicated as an operand of the INT instruction then is referred to the Interrupt Vector Table (IVT).

The INT Instruction (cont.) INT maps all the interrupt numbers to operating system subroutine type. IVT located in the lowest 1KB of memory. Each entry is a 32-bit segment-offset address, which points to the location where the Operating System subroutine resides. Executes the routine at that address.

The INT Instruction (cont.) The various interrupt types are: INT 10h: Video services (cursor position, graphics, scroll) INT 16h: Keyboard services (read keyboard and check status) INT 17h: Printer services (initialize, print, return printer status). INT 1Ah: Time of Day (no. of ticks since machine turned on)

The INT Instruction (cont.) INT 1Ch: User Timer Interrupt (executed 18.2 times per sec.) INT 21h: DOS services (DOS routines for file handling, memory management, I/O, - DOS function calls) The instruction IRET (interrupt return) tells the processor to resume execution at the next instruction of the calling program.

DOS Function Calls Called by INT 21h interrupt serv. routine Before the function type executes, it looks in register AH to determine the function number that identifies the subroutine itself (NOT the type of interrupt). Listed in page 116, figure 5.9.

DOS Function Calls These numbers are the ones that must be represented in register AH, as that is where the processor looks to see what the function number is. These are described in detail in the book. Please read over.

BIOS Level Video Control Instructions The BIOS level video control instructions are also listed in detail in the book. Please read them over.