Académique Documents
Professionnel Documents
Culture Documents
Introduction
Machine Language Programming
One way to write a program is to assign a fixed binary
pattern for each instruction and represent the program by
sequencing these binary patterns.
Such a program is called a Machine language program
or an object program
Eg:
0011
0000
0000
0000
1000
0011
0110
0000
0110
1110
0101
0110
0110
0000
1010
0100
0000
0110
Eg:
LOAD A, 5
LOAD B, 10
ADD A, B
LOAD (100), A
HALT
;
;
;
;
Features of ALP
Advantages:1.
Eg
LABEL OPCODE OPERAND COMMENTS
EU(Execution Unit)
BIU fetches instructions, reads data from
memory and I/O ports and writes data to
memory I/O ports. It handles all transfers of
data and addresses on the buses for the
Execution Unit(EU).
Execution Unit(EU) executes instructions
that have already been fetched by the BIU;
tells BIU where to fetch instructions or data
from, decodes and executes instructions.
Register Structure
Flag Register
All Registers
Segment Registers
CS,SS, DS,ES
00500
Code Segment
0050
CS
0070
DS
Stack Segment
0090
SS
Extra Segment
0099
ES
006FF
00700
Data Segment
007FF
Unused Area
00900
0098F
00990
00A00
The four segment registers (CS, DS, ES, and SS) are
used to "point" at location 0 (the base address) of
each segment.
This is a little "tricky" because the segment registers
are only 16 bits wide, but the memory address is 20
bits wide.
The BIU takes care of this problem by appending four
0's to the low-order bits of the segment register.
In effect, this multiplies the segment register contents
by 16.
Address Formation
Addressing Modes
The way in which an operand is specified is
called the Addressing Mode.
The 8086 processor supports:
Register AM
Immediate
Direct
Indirect mode through Base registers
Indirect mode through Index registers
Indirect mode through Sum of Base and
Index Registers
b classified as shown:
Data Transfer Instructions
Arithmetic Instructions
Bit Manipulation Instructions
String Instructions
Program Execution Transfer Instructions.
Processor Control Instructions.
1.Data-transfer Instructions
A. General purpose byte or word instructions
2.Arithmetic Instructions
A. Addition Instructions
B. Subtraction Instructions
C. Multiplication instructions
D. Division Instructions
B. Shift Instructions
C. Rotate Instructions
4. String Instructions
B. Conditional transfer
D. Interrupt instructions
STC: set CF to 1
CLC: clear CF to 0.
CMC: complement CF
STD: set Direction Flag DF to 1(decrement
string pointers)
CLD: clear DF to 0.
STI: set Interrupt enable flag to 1(enable
INTR interrupt).
CLI: clear interrupt enable flag to 0 (disbale
INTR interrupt)
C. No operation instructions
Segment unit
Segment
Register
Page unit
TLB
Page translator
Data Unit
Segment
translators
Protection
Test Unit
decoder
Instruction
queue
Decode unit
Prefetch
queue
prefetcher
Prefetch unit
biu
Internal Architecture
Includes 6 functional units that operate in parallel
1. Bus interface unit:
Interfaces between the 80386 with memory and I/O.
Based on internal requests for fetching instructions and
transferring data from the code prefetch unit, the
80386 generates the address, data, and control signals
for the current bus cycles.
4. Execution unit:
Processes the instructions from the instruction queue.
It contains a control unit, a data unit and a protection
test unit.
Control unit contains microcode and parallel hardware
for fast multiply, divide and EA calculation.
Data unit includes an ALU, 8 general-purpose
registers, and a 64-bit barrel shifter for performing
multiple bit shifts in one clock. It carries out data
operations requested by the control unit
Protection test unit checks for segmentation
violations under the control of the microcode
5.Segmentation unit:
Translates logical addresses into linear addresses at
the request of the execution unit
6.Paging unit.
Translated linear address is sent to the paging unit.
Upon enabling of the paging mechanism, the 80386
translates these linear addresses into physical
addresses.
80386 registers
General registers:
Segment registers:
Index and pointers:
Indicator:
General registers
Segment registers
Segment registers hold the segment address of
various items.
They are only available in 16 bit values. Some of
them are critical for the good execution of the
program:
CS: Holds the Code segment in which your
program runs. Changing its value might make the
computer hang.
DS: Holds the Data segment that your program
accesses. Changing its value might give erroneous
data.
ES, FS, GS: These are extra segment registers
available for far pointer addressing like video
memory.
SS: Holds the Stack segment your program uses.
Sometimes has the same value as DS. Changing its
value can give unpredictable results, mostly data
related.
2.
MACROS
separate procedure
Use Macro
Mainly 3 parts:
MACRO header (MACRO)
Text or Body
Pseudoinstructions marking the end of
the instruction (e.g.:- ENDM)
e.g.:-Without Macros
MOV
MOV
MOV
MOV
EAX, P
EBX, Q
Q, EAX
P, EBX
MOV
MOV
MOV
MOV
EAX, P
EBX, Q
Q, EAX
P, EBX
With Macros
SWAP MACRO
MOV EAX, P
MOV EBX, Q
MOV Q, EAX
MOV P, EBX
ENDM
SWAP
SWAP
EAX, P
EBX, Q
Q, EAX
P, EBX
MOV
MOV
MOV
MOV
EAX, P
EBX, Q
Q, EAX
P, EBX
With Macros
CHANGE MACRO P1, P2
MOV EAX, P1
MOV EBX, P2
MOV P2, EAX
MOV P1, EBX
ENDM
CHANGE P, Q
CHANGE R, S