Introduction to Assembly Language Overview What is Assembly

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)? • 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 – 10100011 Add a number to the AL register. 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 1234 h, then AL contains 34 h and AH contains 12 h

Registers Instruction Pointer General-purpose registers Special-purpose registers segment registers 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 PC / IP Status register FLAGS

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

Symbol Set Clear Carry Flag CF CY NC Parity Flag PF PE PO Zero Flag ZF ZR NZ Sign Flag SF NG PL Overflow Flag OF OV NV Auxiliary Flag AF AC NA

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.

Debug commands Command Purpose r Display the contents of all registers Alter the contents of a register u List the instructions contained in the given address and following in assembly language form D Display the contents of memory in hexadecimal format and as ASCII character starting with the address given e Enter values into memory, beginning at a specific location t Trace the execution of an instruction a Choose an address to write a program q Quit the debug session

Example: 0100 0103 0106 0108 010 A 010 C MOV AX, 0123 ADD AX, 0025 MOV BX, AX ADD BX, AX MOV CX, BX SUB CX, AX 010 E SUB AX, AX 0110 JMP 100 Move value 0123 H to AX Add value 0025 H to AX Move contents of AX to BX Add contents of AX to BX Move contents of BX to CX Subtract contents of AX from CX Subtract AX from AX (clear AX) Go back to the start
- Slides: 18