Professional Documents
Culture Documents
Stored Program concept Main memory storing programs and data ALU calculating data Control unit interpreting instructions from memory and executing Input and output equipment operated by control unit
von Neumann
von Neumann
1000 x 40 bit words
Binary number 2 x 20 bit instructions
Moores Law
Increased density of components on chip Gordon Moore - cofounder of Intel Number of transistors on a chip will double every year Since 1970s development has slowed a little Number of transistors doubles every 18 months Cost of a chip has remained almost unchanged Higher packing density means shorter electrical paths, giving higher performance Smaller size gives increased flexibility Reduced power and cooling requirements Fewer interconnections increases reliability
Speeding it up
Pipelining On board cache On board L1 & L2 cache Branch prediction Data flow analysis Speculative execution
Segmentation
Compilers for the 8086 commonly supported two types of pointer, "near" and "far". Near pointers were 16-bit addresses implicitly associated with the program's code or data segment (and so made sense only in programs small enough to fit in one segment). Far pointers were 32-bit segment:offset pairs.
Segmentation
To avoid the need to specify "near" and "far" on every pointer and every function which took or returned a pointer, compilers also supported "memory models" which specified default pointer sizes. The "small", "compact", "medium", and "large" models covered every combination of near and far pointers for code and data. The "tiny" model was like "small" except that code and data shared one segment. The "huge" model was like "large" except that all pointers were huge instead of far by default. Precompiled libraries often came in several versions compiled for different memory models.
Index Register
Segment Register
32/16
32/16
32/16 32/16
Function Accumulator Register For arithmetic, logic and data transfer operation Base Register Also as address register Count Register Used for loop counter, shift and rotate bits Data Register Used in division and multiplication also I/O operation
13
14
15
Segment Register
Main memory management in 8086 use segment concept The following show the usage of segment in memory
Segment
Code (CS) Data (DS)
Usage
Space to store program that will be executed Space to store data that will be processed
Stack (SS)
Special space to store information needed by microprocessor to execute subroutine or interrupt service Function is the same as DS
Extra (ES)
17
20
Assembler
An assembler translates assembly language programs into machine codes It resolves symbolic names for memory locations and other entities.
Assembler
There are two types of assemblers based on how many passes through the source are needed to produce the executable program. One-pass assemblers go through the source code once and assumes that all symbols will be defined before any instruction that references them. Two-pass assemblers (and multi-pass assemblers) create a table with all unresolved symbols in the first pass, then use the 2nd pass to resolve these addresses. The advantage of the two-pass assembler is that symbols can be defined anywhere in the program source.
Assembler
As a result, the program can be defined in a more logical and meaningful way. This makes two-pass assembler programs easier to read and maintain.
Variable Declarations
Our compiler supports two types of variables: BYTE and WORD.
Syntax for a variable declaration: name DB value name DW value
Variable Declarations
Syntax for a variable declaration: name DB value
name DW value
DB - stays for Define Byte. DW - stays for Define Word. name - can be any letter or digit combination value - can be any numeric value in any supported numbering system (hexadecimal, binary, or decimal), or "?" symbol for variables that are not initialized.
Declare Variables
use DB to declare variables with small values 0 to 255. use DW to declare variables with larger values 0 to 65000. C++: int HT=47, WD=2415, SZ; ASM: HT DB 47 WD DW 2415 SZ DW ? unitialised value in ASM is denoted by ?
comments / remarks
C++: comments denoted by // anything after // will be ignored in ASM: comments denoted by ; anything after ; will be ignored C++ has multi-line comments enclosed by /* and */. In ASM, each comment line must be individually preceded by ;
Simple Assignments
The easiest expressions to convert to assembly language are the simple assignments. MOV instruction Simple assignments copy a single value into a variable
Eg:
This move immediate instruction copies the constant into the variable.
ORG
Program start address ORG 100H normally start at address 100H (hexadecimal)
RET
similar to C++ return statement.
Simple Assignments(MOV)
The easiest expressions to convert to assembly language are the simple assignments. Simple assignments copy a single value into a variable
Eg:
This move immediate instruction copies the constant into the variable.
It is possible to enter numbers in any system, hexadecimal numbers should have "h" suffix, binary "b" suffix, octal "o" suffix, decimal numbers require no suffix. mov AX, 46H ;hex mov BX, 1011B ;binary mov AH, 251o ;octal mov CH, 36 ;decimal
Assembler Directive/Pseudo-Ops
2 types of ASM statements program instruction
convert to machine code of the program, ADD, SUB, MUL, MOV, DIV, etc
Assignments (MOV)
This example assignment copies a variable into a variable
P := Q
The assignment above is somewhat complicated since the 80x86 doesnt provide a memoryto-memory mov instruction. Therefore, to copy one memory variable into another, you must move the data through a register.
Eg:
C++: ASM:
Addition (ADD)
Examples of common simple expressions:
X := Y + Z
ASM:
Arithmetic Expressions
Arithmetic expressions, in most high level languages, look similar to their algebraic equivalents:
X:=Y+Z;
In assembly language, youll need several statements to accomplish this same task, e.g.,
Arithmatic Expressions
A math expression takes the form: var := term1 op term2 Var is a variable, term1 and term2 are variables or constants, and op is some arithmetic operator(+,-,*, /, etc) ASM: op term1 term2 where op = ADD, SUB, MUL, IMUL, DIV, IDIV, etc
SUBTRACT (SUB)
X := Y - Z; ASM: mov ax, y sub ax, z mov x, ax
INCREMENT (INC)
X := X + 1; ASM: inc x
DECREMENT (DEC)
X := X - 1; ASM: dec x
Instruction Format
instruction has opcode + operand(s) ADD AX, 2 SUB BX, Y MOV Z, 1584 INC Y
opcode is ADD, SUB, MOV, INC operands are AX, BX, X, Y, 2, 1584
Arithmetic Expressions
Arithmetic expressions, in most high level languages, look similar to their algebraic equivalents:
X:=Y+Z;
In assembly language, youll need several statements to accomplish this same task, e.g.,
Complex Expressions
A complex function that is easy to convert to assembly language is one that involves three terms and two operators, for example: W := W - Y - Z;
Complex Expressions
Clearly the straight-forward assembly language conversion of this statement will require two sub instructions. However, even with an expression as simple as this one, the conversion is not trivial. There are actually two ways to convert this from the statement above into assembly language: mov ax, w sub ax, y sub ax, z mov w, ax
Opcode mnemonics
Instructions (statements) in assembly language are generally very simple, unlike those in high-level languages. Generally, an opcode is a symbolic name for a single executable machine language instruction, and there is at least one opcode mnemonic defined for each machine language instruction. Each instruction typically consists of an operation or opcode plus zero or more operands.
Linking
In traditional assembly language work, what actually happens is that the assembler writes an intermediate object code file with an .OBJ extension to disk. You can't run this .OBJ file, even though it generally contains all the machine instructions that your assembly language source code file specified. The .OBJ file needs to be processed by another translator program, the linker. The linker performs a number of operations on the .OBJ file, most of which would be meaningless to you at this point. The most obvious task the linker does is to weave several .OBJ files into a single .