lecture 1 intro,segments,registers]

34
ASSEMBLY LANGUANGE

Transcript of lecture 1 intro,segments,registers]

Page 1: lecture 1 intro,segments,registers]

ASSEMBLY LANGUANGE

Page 2: lecture 1 intro,segments,registers]

Introduction

In Writing a program in assembly language requires knowledge of the computer’s instruction set, the rules of its use, and the hardware on which it runs.

An assembly language program consists of one or more segments for defining data and for machine instructions and a segment named the stack that contains stored addresses.

Page 3: lecture 1 intro,segments,registers]

We will utilize ROM (Read-only Memory), the important feature of ROM in programming is its Basic Input/Output System (BIOS), RAM (Random Access Memory) , its importance is its availability as a “worksheet” for temporary storage and execution of programs, and Addressing Memory Locations, an assembly language programmer has to distinguish between the address of memory location and its contents.

Page 4: lecture 1 intro,segments,registers]

SEGMENTS

A segment is an area in memory that begins on a paragraph boundary.

Page 5: lecture 1 intro,segments,registers]

TYPES OF SEGMENTS

Code SegmentData SegmentStack SegmentSegment Boundaries

Page 6: lecture 1 intro,segments,registers]

Code Segment – the code segment contains the machine instructions that are to execute. Typically, the first executable instruction is at the start of this segment, and the operating system links to this location for program execution. The CS (code segment) register addresses this segment.

Page 7: lecture 1 intro,segments,registers]

Data Segment – The data segment contains a program’s defined data, constants, and work areas. The DS (data segment) register addresses this segment.

Page 8: lecture 1 intro,segments,registers]

Stack Segment – the stack contains any data addresses that you need to save temporarily for your own “called” subroutines to return to your main program. The SS (stack segment) register addresses this segment.

Page 9: lecture 1 intro,segments,registers]

Segment Boundaries

The segment registers contain the starting address of each segment. Extra segment registers are the ES.

Page 10: lecture 1 intro,segments,registers]

Segment Boundaries

Page 11: lecture 1 intro,segments,registers]

Segment Offsets

All memory locations are relative to the start of a segment. The distance in bytes is expressed as an offset (or displacement) from the start of a segment. For example: a two-byte (16-bit) offset can range from hex 0000 through hex FFFF or 0 through 65,535. Thus the first byte of the code segment is at offset 00, the second byte is at offset 01, and so forth, through to offset 65,535.

Page 12: lecture 1 intro,segments,registers]

REGISTERS

The processor’s registers are used to control instructions being executed, to handle addressing of memory, and to provide arithmetic capability. The registers are addressable by name. Bits are conventionally numbered from right to left.

Page 13: lecture 1 intro,segments,registers]

Segment Registers

A segment register is 16 bits long and provides for addressing an area of memory, known as the current segment.

Page 14: lecture 1 intro,segments,registers]

CS register

the code segment register contains the initial address of a program’s code segment. This address plus an offset value in the instruction pointer (IP) register indicates the address of an instruction to be fetched for execution.

Page 15: lecture 1 intro,segments,registers]

DS register

the data segment register contains the initial address of a program’s data segment. In simple terms, this address plus an offset value in an instruction causes a reference to a specific byte location in the data segment.

Page 16: lecture 1 intro,segments,registers]

SS register

the stack segment register permits implementation of a stack in memory, used for temporary storage of addresses and data. The SS register contains the starting address of the program’s stack segment. This address plus an offset value in the stack pointer (SP) register indicates the current word in the stack being addressed.

Page 17: lecture 1 intro,segments,registers]

ES register

Some string (character data) operations use the extra segment register to handle memory addressing. In his context, the ES register is associated with the DI register.

Page 18: lecture 1 intro,segments,registers]

Instruction Pointer Register (IP)

The 16-bit IP register contains the offset address of the instruction that is to execute next. The IP is associated with the CS register such that the IP indicates the current instruction within the currently executing code segment.

Page 19: lecture 1 intro,segments,registers]

POINTER REGISTER

The pointer registers, SP and BP, are associated with the SS register and permit the system to access data in the stack segment.

Page 20: lecture 1 intro,segments,registers]

SP register

The 16-bith stack pointer is associated with the SS register and provides an offset value that refers to the current word being processed in the stack.

Page 21: lecture 1 intro,segments,registers]

BP register

The 16-bit base pointer facilitates referencing parameters, which are data and addresses passed via the stack.

Page 22: lecture 1 intro,segments,registers]

General Purpose Registers

The AX, BX, CX and DX general-purpose registers are the workhorses. They are unique in that you can address them as one word or as a one-byte portion. The leftmost byte is the “high” portion and the rightmost byte is the “low” portion.

Page 23: lecture 1 intro,segments,registers]

For example, the CX register consists of a CH and a CL portion, and you can reference any of the three names.

Page 24: lecture 1 intro,segments,registers]

The following instructions move zeros to the CX, CH, and CL respectively:

MOV CX, 00

MOV CH, 00

MOV CL, 00

Page 25: lecture 1 intro,segments,registers]

AX register

The AX register, the primary accumulator, is used for operations involving input/output and most arithmetic.

Page 26: lecture 1 intro,segments,registers]

BX register

The BX is known as the base register since it is the only general-purpose register that can be used as an “index” to extend addressing.

Page 27: lecture 1 intro,segments,registers]

CX register

The CX is known as the count register. It may contain a value to control the number of times a loop is repeated or a value to shift bits left or right.

Page 28: lecture 1 intro,segments,registers]

DX register

The DX is known as the date register. Some input/output operations require its use, and multiply and divided operations that involve large values assume the DX and AX pair.

Page 29: lecture 1 intro,segments,registers]

INDEX REGISTER

The index registers are available for extended addressing and for use in addition and subtraction.

Page 30: lecture 1 intro,segments,registers]

SI register

The 16-bit source index register is required for some string (character) operation. In this context, the SI is associated with the DS register.

Page 31: lecture 1 intro,segments,registers]

DI register

The 16-bit destination index register is also required for some string operations. In this context, the DI is associated with the ES register.

Page 32: lecture 1 intro,segments,registers]

Flag Register

9 of the 16 bit of the flags register are common to all 8086-family processors to indicate the current status of the machine and the results of execution.

The FLAGS Register consists of 9 status bits. These bits are also called flags, because they can either be SET (1) or NOT SET (0). All these flags have a name and purpose.

Page 33: lecture 1 intro,segments,registers]

Flag Register

Page 34: lecture 1 intro,segments,registers]