KTMT HN - Ch05.assembly Basics
KTMT HN - Ch05.assembly Basics
Chapter 5
2
• Having an understanding of AL makes one aware of −
How programs interface with OS, processor, and BIOS;
How data is represented in memory and other external devices;
How the processor accesses and executes instruction;
How instructions access and process data;
How a program accesses external devices.
4
• Bit (Binary digit) – basic information unit: (1/0)
• Byte – sequence of 8 bits:
7 6 5 4 3 2 1 0
• segment registers
CS, DS, ES, SS, FS, GS
6
7
• Assembly Program consist of statement, one per line; translated by
Assembler into MLIs that can be loaded into memory and executed.
8
• An example of an instruction is
START: MOV CX,5 ; initialize counter
9
name operation operand(s) comment
• A Name field identifies a label, variable, or symbol. It may
contain any of the following characters :
A, B,.. , Z, a, b,.. , z, 0, 1,.. , 9, ?, _, @, $, .
• Names are case sensitive. (MOV or mov is same).
• The first character may not be a digit. The period ( . ) may
be used only as the first character.
10
name operation operand(s) comment
11
name operation operand(s) comment
12
name operation operand(s) comment
13
• AL instructions built from 2 pieces:
Opcode : What to do with the data
Operands : Where to get the data
Ex: In instruction 'add R1, R3, 3', opcode is 'add' and operand is 'R1, R3, 3'
assembly code: MOV AL, 61h ; load AL with 97d
binary code: 10110000 01100001
1011 a binary code (opcode) of instruction 'MOV'
0 specifies if data is byte (‘0’) or full size 16/32 bits (‘1’)
000 a binary identifier for a register 'AL'
01100001 a binary representation of 97d (=61h)
• Types of Opcodes:
Arithmetic, logical (add, sub, mult, and, or, cmp,..)
Memory load /store (ld, st)
Control transfer (jmp, bne)
Complex ( movs, ..)
14
• AL closely tied to processor architecture, so there are many AL.
• At least four main types:
CISC: Complex Instruction-Set Computer
RISC: Reduced Instruction-Set Computer
DSP: Digital Signal Processor
VLIW: Very Long Instruction Word
• When programing, we can use one of two forms:
Inline Assembly: some compilers allows AL instructions to be embedded
within a program, such as C, C++, Pascal, Ada,... We don't need any
Assembler to translate AL instructions.
Full Assembly: We must use an Assembler to translate AL instructions into
MLIs (binary code). TASM (Turbo Assembler) , MASM (Macro..), NASM
(Netwide..),.. - are assemblers for x86 architecture
15
• Developed when people wrote assembly language
• Complicated, often specialized instructions with many effects
• Examples from x86 architecture: String move, Procedure enter, leave
• Many, complicated addressing modes
• So complicated, often executed by a little program (microcode)
• Examples: Intel x86, 68000, PDP-11
16
• Response to growing use of compilers
• Easier-to-target, uniform instruction sets “Make the most common
operations as fast as possible”
• Load-store architecture:
Arithmetic only performed on registers
Memory load/store instructions for memory-register transfers
• Designed to be pipelined
• Examples: SPARC, MIPS, HP-PA, PowerPC
17
• Digital signal processors designed specifically for signal processing
algorithms
• Lots of regular arithmetic on vectors
• Often written by hand
• Irregular architectures to save power, area
• Substantial instruction-level parallelism
• Examples: TI 320, Motorola 56000, Analog Devices
• Digital Signal Processor Apps
Low-cost embedded systems : Modems, cellular telephones, disk drives,
printers
High-throughput applications : Halftoning, base stations, 3-D sonar,
tomography
PC based multimedia : Compression/decompression of audio, graphics,
video
18
• Response to growing desire for instruction-level parallelism
• Using more transistors cheaper than running them faster
• Many parallel ALUs
• Objective: keep them all busy all the time
• Heavily pipelined
• More regular instruction set
• Very difficult to program by hand
• Looks like parallel RISC instructions
• Examples: Itanium, TI 320C6000 56000, Analog Devices
19
• Many programs are too large to be developed by one person. This
means that programs are routinely developed by a teams.
• The Assembler converts a source module (file) into a object file.
• The Linker program is used so that modules can be linked together
into a complete program. It reads the object files that are created by
the assembler and links them together into a single execution file.
• An execution file is created with the file name extension EXE.
In DOS /Windows: If a file is short enough (less than 64K bytes long), it can
be converted from an execution file to a command file (.COM).
The command file is slightly different from an execution file in that the
program must be originated at location 0100H before it can execute.
Object file1
.obj
Object file3
.obj 20
Ascii table