180 likes | 195 Views
Introduction to Assembly Language. Overview. What is Assembly Language? Why is AL important to learn? Machine instructions AL Instructions Intel 8086 Architecture Hands on Activity. What is Assembly Language (AL)?.
E N D
Overview • What is Assembly Language? • Why is AL important to learn? • Machine instructions • AL Instructions • Intel 8086 Architecture • Hands on Activity
What is Assembly Language (AL)? • To learn how a computer and its software really work, you need to view them at machine level. • Assembly language is a specific set of instructions for a particular computer system. • AL teaches you about the way the computer’s hardware and OS work together and how application programs communicate with the OS. • It is a programming language with a one-to-one correspondence between its statement and a computer’s main machine language.
Cont… • Each computer or family of computers uses a different set of machine instructions and a different assembly language (the computer’s design influences the instructions it can execute). • An assembler – a program that converts or translates source-code programs into machine language, which may in turn be executed by the computer (runs under the disk operating systems MS-DOS or PC-DOS).
Why is AL important to learn? • Provides opportunity to know more about the operations of the PC • Enable control of the PC – access to specific hardware features • Quicker, smaller and have larger capacities compared to other HL languages
Machine Instructions • A machine instruction is a binary code that has a special meaning for a computer’s CPU – it tells the computer to perform a task. • Each machine instruction is precisely defined when the CPU is constructed, and it is specified to that type of CPU. For example: • 00000100 Add a number to the AL register. • 10100011 Move the AX register to another register
Registers are high-speed storage locations inside the CPU which are used by nearly every instructions • They are identified by 2-letter names, such as AH, AL, AX and so on. • We refer to machine instructions using hexadecimal numbers because they take up less writing space.
Assembly Language Instructions • Mnemonic – a short alphabetic code that literally “assists the memory” in remembering CPU instruction • It may be an instruction or a directive • E.g. an instruction MOV (move) • E.g. a directive DB (definite byte, used to create memory variables) • An instruction may contain zero, one or two operands.
Intel 8086 Architecture • There are 14 internal registers in Intel 8086 • All of them are represented in 16-bit mode or equivalent to 4 digits in hexadecimal • They are grouped into several categories • For general-purpose registers, each of these is a combination of two 8-bit registers which are separately accessible as AL, BL, CL, DL (the "low'' bytes) and AH, BH, CH, and DH (the "high'' bytes) • For example, if AX contains the 16-bit number 1234h, then AL contains 34h and AH contains 12h
Registers Instruction Pointer PC / IP General-purpose registers Special-purpose registers segment registers Status register FLAGS AX = AH + AL, BX = BH + BL , CX = CH + CL, DX = DH + DL SP, BP, SI, DI CS, DS, ES, SS Figure 1: 14 Registers in Intel 8086
General Purpose Registers • There are 4 general-purpose registers, each of them is designed to play a particular role in common use: • AX – Accumulator Register • Used for operations involving i/o and most arithmetic such as MUL and DIV, require that one of the operands be in the accumulator • As a place to store data • BX – Base Register • The only general-purpose register which may be used for indirect addressing, MOV [BX], AX • As a place to store data • CX – Count Register • It may contain a value to control the number of times a loop is repeated or a value to shift/rotate bits left or right • As a place to store data • DX – Data Register • Used together with AX for the word-size MUL and DIV operations • As a place to store data
Special Purpose Registers • There are 4 special-purpose registers: • Stack Pointer Register (SP) • Holds add of top of stack • Base Pointer Register (BP) • Holds add of ref point in the stack • Source Index Register (SI) • Holds memory add of source • Destination Index Register (DI) • Holds memory add of destination
Segment registers • There 4 segment register: • Code Segment Register (CS) • Holds selector for code segment • Data Segment Register (DS) • Holds selector for data segment • Extra Segment Register (ES) • Holds selector for extra segment • Stack Segment Register (SS) • Holds selector for stack segment
Status Register • The status register, FLAGS, is a collection of 1-bit values, which reflect the current state of the processor and the results of recent operations • 9 of the 16 bits are used in the 8086. In this lesson you will only learn 6 flags: • Carry flag • Parity flag • Sign flag • Zero flag • Overflow flag • Auxiliary Flag
Instruction Pointer • The instruction pointer (sometimes called Program Counter - PC), IP, gives the address of the next instruction to be executed, relative to the code segment .
Example: 0100 MOV AX, 0123 Move value 0123H to AX 0103 ADD AX, 0025 Add value 0025H to AX 0106 MOV BX, AX Move contents of AX to BX 0108 ADD BX, AX Add contents of AX to BX 010A MOV CX, BX Move contents of BX to CX 010C SUB CX, AX Subtract contents of AX from CX 010E SUB AX, AX Subtract AX from AX (clear AX) 0110 JMP 100 Go back to the start