chapter3instructionsetandassemblylanguageprogramming

Download Report

Transcript chapter3instructionsetandassemblylanguageprogramming

RTA: (06 : 06)
CHAPTER 3
INSTRUCTION SET AND ASSEMBLY
LANGUAGE PROGRAMMING
CLO 3: construct a simple program in assembly language
to perform a given task
Summary : This topic introduces the instruction set, data format,
addressing modes, status flag and assembly language programming.
3.1 UNDERSTANDING
INSTRUCTION SET AND
ASSEMBLY LANGUAGE
3.1.1 Define instruction set,machine
and assembly language
INSTRUCTION SET
• An instruction set is a list of commands ready to be executed directly by CPU.
• We can simply say that the functions of instruction set is to instruct all CPU's with
a set of instruction that can
– tells the CPU where to find data
– when to read the data
– what to do with the data
Now we will see some of the type of instruction set.
• Data transfer instruction
• Arithmetic instruction
• Logical instruction and bit manipulation
• Program control instruction
• Processing control instruction
• Shift and rotate instruction
Machine Language
• A machine language sometimes referred to
as machine code or object code.
• Machine language is a collection
of binary digits or bits that the computer
reads and interprets.
• Machine language is the only language a
computer is capable of understanding.
• Machine language consists of 0s and 1s.
Assembly Language
• Is a low-level programming
language for computers,microprocessors,
microcontrollers and other programmable devices.
• Assembly language is just one level higher than
machine language.
– Assembly language consists of simple codes.
– Each statement in an assembly language corresponds
directly to a machine code understood by the
microprocessor.
• The software used to convert an assembly program
into machines codes is called an assembler.
high Level
Programming
Low
Level
Programming
3.1.2 Describe features and architectures
of various type of microprocessor
MOTOROLA 6800
• The Motorola 68000 is a 32-bit CISC microprocessor.
• 24 bit address bus
• 16 bit data bus.
INTEL 8086
• 8086 has 16-bit ALU; this means 16-bit
numbers are directly processed by 8086.
• It has 16-bit data bus, so it can read data or
write data to memory or I/O ports either 16
bits or 8 bits at a time.
• It has 20 address lines, so it can address up to
220 i.e. 1048576 = 1Mbytes of memory (words
i.e. 16 bit numbers are stored in consecutive
memory locations).
3.1.3 Describe the Addressing
Modes
• Many instructions, such as MOV, operates on
two operands.
– MOV
dest, source
• Addressing mode indicates where the operands
are located.
• There are various addressing modes in x86.
– Register, immediate, direct, register indirect, baseplus-index, register relative, base relative-plus-index,
 Register is a storage element inside a
microprocessor.
ADDRESSING MODES
1. Register Addressing
• Instruction gets its source data from a register.
• Data resulting from the operation is stored in
another register.
• Data length depends on register being used.
– 8-bit registers: AH, AL, BH, BL, CH, CL, DH, DL.
– 16-bit registers: AX, BX, CX, DX, SP, BP, SI, DI.
– 32-bit registers: EAX, EBX, ECX, EDX, ESP, EBP, EDI,
ESI.
– 64-bit registers: RAX, RBX, RCX, RDX, RSP, RBP, RDI,
RSI, and R8 through R15.
1.Register Addressing
• Examples:
– MOV AX, BX ;Copy the 16-bit content of BX to
AX
– MOV AL, BL ;Copy the 8-bit content of BL to AL
– MOV SI, DI ;Copy DI into SI
– MOV DS, AX ;Copy AX into DS
• Note that the instruction must use registers of
the same size.
– Cannot mix between 8-bit and 16-bit registers.
– Will result in an error when assembled.
2. Immediate Addressing
• The source data is coded directly into the
instruction.
– The term immediate means that the data
immediately follows the hexadecimal opcode in the
memory.
• Immediate data are constant data such as
a number, a character, or an arithmetic
expression.
• Examples:
–
–
–
–
MOV AX, 100
MOV BX, 189CH
MOV AH, 10110110B
MOV AL, (2 + 3)/5
3. Direct Addressing
• The operand is stored in a memory location, usually in
data segment.
• The instruction takes the offset address.
– This offset address must be put in a bracket [ ].
• Example:
– MOV [1234H], AL
– The actual memory location is obtained by combining
the offset address with the segment address in the
segment register DS (unless specified otherwise)
– If we want to use another segment register such as ES,
you can use the syntax ES:[1234H]
– Assuming DS = 1000H, then this instruction will move
the content of AL into the memory location 1234H.
4. Register Indirect Addressing
• Similar to direct data addressing, except
that the offset address is specified using
an index or base register.
– Base registers = BP, BX. Index registers = DI, SI.
– In 80386 and above, any register (EAX, EBX, ECX, EDX, EBP, EDI,
ESI) can store the offset address.
– The registers must be specified using a bracket [ ].
– DS is used as the default segment register for BX, DI and SI.
• Example:
– MOV AX, [BX]
– Assuming DS = 1000H and BX = 1234H, this instruction will
move the content memory location 11234H and 11235H into
AX.
5. Base-plus-index Addressing
• Similar to register indirect addressing, except
that the offset address is obtained by adding a
base register (BP, BX) and an index register (DI,
SI).
• Example:
– MOV [BX+SI], BP
– Assuming DS = 1000H, BX = 0300H and SI = 0200H,
this instruction will move the content of register BP
to memory location 10500H.
6. Register Relative Addressing
• Similar to register indirect addressing,
except that the offset address is obtained
by adding an index or base register with a
displacement.
• Example 1:
– MOV AX, [DI+100H]
– Assuming DS = 1000H and DI = 0300H, this instruction will
move the content from memory location 10400H into AX.
• Example 2:
– MOV ARRAY[SI], BL
– Assuming DS = 1000H, ARRAY = 5000H and SI = 500H, this
instruction will move the content in register BL to memory
location 15500H.
7. Base Relative-plus-index
Addressing
• Combines the base-plus-index addressing
and relative addressing.
• Examples:
– MOV AH, [BX+DI+20H]
– MOV FILE[BX+DI], AX
– MOV LIST[BP+SI+4], AL
3.2 APPLY ASSEMBLY LANGUAGE
3.2.1 Write simple program in
assembly language
Example of assembly languange:
MOV
MOV
MOV
MOV
MOV
MOV
HLT
CL, 55H
DL, CL
AH, DL
AL, AH
BH, CL
CH, BH
; move 55H into register CL
; copy the contents of CL into DL (now DL=CL=55H)
; copy the contents of DL into AH (now AH=CL=55H)
; copy the contents of AH into AL (now AL=AH=55H)
; copy the contents of CL into BH (now BH=CL=55H)
; copy the contents of BH into CH (now CH=BH=55H)
3.2.2 Tool in analyzing and debugging
assembly language program
• Emulator 8086k –analyze for INTEL 8086
• Easy68k- analyze for MOTOROLA 6800