0% found this document useful (0 votes)
26 views

KTMT HN - Ch05.assembly Basics

The document discusses the basic concepts of assembly language. It explains that assembly language was designed to make programming easier for humans by using mnemonics instead of machine language's 1s and 0s. An assembler translates assembly language instructions into machine code. Assembly language allows programmers to be aware of how programs interface with hardware and access memory/devices. While requiring less memory and execution time than high-level languages, assembly language allows more control over hardware.

Uploaded by

Nguyên
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

KTMT HN - Ch05.assembly Basics

The document discusses the basic concepts of assembly language. It explains that assembly language was designed to make programming easier for humans by using mnemonics instead of machine language's 1s and 0s. An assembler translates assembly language instructions into machine code. Assembly language allows programmers to be aware of how programs interface with hardware and access memory/devices. While requiring less memory and execution time than high-level languages, assembly language allows more control over hardware.

Uploaded by

Nguyên
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Computer Architecture & Assembly Language

Chapter 5

THE BASIC CONCEPTS OF


ASSEMBLY LANGUAGE

Thái Hùng Văn


thvan@fit.hcmus.edu.vn
• Each personal computer has a microprocessor that manages the
computer's arithmetical, logical, and control activities.
• Each family of processors has its own set of instructions for handling
various operations. They are called 'machine language instructions'
(MLIs).
• A processor understands only MLIs, which are series of 1's and 0's.
ML is too obscure and complex for programming. So, the assembly
language (AL) is designed to make programmer’s job easier.
• In AL, an instruction is an easy-to-remember form called a
mnemonic.
• Assembler: Translates AL instructions into ML

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.

• Other advantages of using assembly language are −


It requires less memory and execution time;
It allows hardware-specific complex jobs in an easier way;
It is suitable for time-critical jobs;
It is most suitable for writing interrupt service routines and other memory
resident programs.
3
• The main internal hardware of a PC consists of processor, memory,
and registers. Registers are processor components that hold data and
address. To execute a program, the system copies it from the external
device into the internal memory. The processor executes the program
instructions.
• The fundamental unit of computer storage is a bit; it could be ON (1)
or OFF (0). A group of nine related bits makes a byte, out of which
eight bits are used for data and the last one is used for parity.
According to the rule of parity, the number of bits that are ON (1) in
each byte should always be odd.
• So, the parity bit is used to make the number of bits in a byte odd. If
the parity is even, the system assumes that there had been a parity
error (though rare), which might have been caused due to hardware
fault or electrical disturbance.

4
• Bit (Binary digit) – basic information unit: (1/0)
• Byte – sequence of 8 bits:
7 6 5 4 3 2 1 0

MSB (Most Significant Bit) LSB (Least Significant Bit)

• Word – a sequence of bits addressed as a single entity by the computer


high low 16 bit word
byte byte
232-1
… physical
memory
• Main Memory is an array of bytes, 2K-1
addressed by 0 to 232-1=0xFFFFFFFF address …
(or to 264-1 in IA64) space
1
232 bytes = 4∙210∙3 bytes = 4 GBs 0
• general purpose registers
EAX, EBX, ECX, EDX
(Accumulator, Base, Counter, Data)
IA32 Registers
• index registers
ESP, EBP, ESI, EDI
(Stack pointer - contains the address of last used
dword in the stack, Base pointer, Source index,
Destination Index)

• segment registers
CS, DS, ES, SS, FS, GS

• flag register / status register


EFLAGS

• Instruction Pointer / Program Counter EIP / EPC


- contains address (offset) of the next instruction that is going to be executed (at run time)
- changed by unconditional jump, conditional jump, procedure call, and return instructions

6
7
• Assembly Program consist of statement, one per line; translated by
Assembler into MLIs that can be loaded into memory and executed.

• Each statement is either an instruction, which the assembler


translate into machine code, or assembler directive, which instructs
the assembler to perform some spesific task, such as allocating
memory space for a variable or creating a procedure.

• Both instructions and directives have up to four fields:

name operation operand(s) comment


(At least one blank or tab character must separate the fields)

8
• An example of an instruction is
START: MOV CX,5 ; initialize counter

The name field consists of the label START:


The operation is MOV, the operands are CX and 5
And the comment is ; initialize counter

• An example of an assembler directive is


MAIN PROC

 MAIN is the name, and the operation field contains PROC


 This particular directive creates a procedure called MAIN

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.

A Keyword, or reserved word, always have some


predefined meaning to the assembler.
It may be an instruction (MOV, ADD), or an assembler
directive (PROC, TITLE, END)

10
name operation operand(s) comment

• Operation field is a predefined or reserved word


mnemonic - symbolic operation code.
The assembler translates a symbolic opcode into a machine
language opcode.
Opcode symbols often discribe the operation’s function; for
example, MOV, ADD, SUB
assemler directive - pseudo-operation code.
In an assembler directive, the operation field contains a
pseudo-operation code (pseudo-op)
Pseudo-op are not translated into machine code; for
example the PROC pseudo-op is used to create a procedure

11
name operation operand(s) comment

• An operand field specifies the data that are to be acted on


by the operation.
• An instruction may have zero, one, or two operands. For
example:
 NOP No operands; does nothing

 INC AX one operand; adds 1 to the


contents of AX

 ADD WORD1,2 two operands; adds 2 to WORD1

12
name operation operand(s) comment

• The comment field is used by the programmer to say something


about what the statement does.

• A semicolon marks the beginning of this field, and the assembler


ignores anything typed after semicolon.

• Comments are optional, but because assembly language is low


level, it is almost impossible to understand an assembly language
program without comments.

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

Program Object file2 Executable file


Assembler Linker
.asm .obj .exe

Object file3
.obj 20
Ascii table

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy