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

Assembly Language Programming

Assembly language is a low-level programming language that is closer to machine language. It uses mnemonic codes to represent binary machine instructions. An assembler is used to translate assembly language code into binary machine code. Assembly language provides better readability than machine language and allows direct access to hardware for tasks such as systems programming.

Uploaded by

Solomon SB
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Assembly Language Programming

Assembly language is a low-level programming language that is closer to machine language. It uses mnemonic codes to represent binary machine instructions. An assembler is used to translate assembly language code into binary machine code. Assembly language provides better readability than machine language and allows direct access to hardware for tasks such as systems programming.

Uploaded by

Solomon SB
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Assembly language programming

Basic concept
A Hierarchy of Languages
Assembly and Machine Language
• Machine language
– Native to a processor: executed directly by hardware
– Instructions consist of binary code: 1s and 0s
• Assembly language
– Slightly higher-level language
– Readability of instructions is better than machine language
– One-to-one correspondence with machine language instructions
• Assemblers translate assembly to machine code
• Compilers translate high-level programs to machine code
– Either directly, or
– Indirectly via an assembler
Compiler and Assembler
Instructions and Machine Language
• Each command of a program is called an
instruction (it instructs the computer what to
do).
• Computers only deal with binary data, hence
the instructions must be in binary format (0s
and 1s) .
• The set of all instructions (in binary form)
makes up the computer's machine language.
This is also referred to as the instruction set.
Instruction Fields
• Machine language instructions usually are made up of
several fields. Each field specifies different information
for the computer. The major two fields are:
• Opcode field which stands for operation code and it
specifies the particular operation that is to be
performed.
– Each operation has its unique opcode.
• Operands fields which specify where to get the source
and destination operands for the operation specified by
the opcode.
– The source/destination of operands can be a constant, the
memory or one of the general-purpose registers.
Assembly vs. Machine Code
Instruction Address Machine Code Assembly Instruction
0005 B8 0001 MOV AX, 1
0008 B8 0002 MOV AX, 2
000B B8 0003 MOV AX, 3
000E B8 0004 MOV AX, 4
0011 BB 0001 MOV BX, 1
0014 B9 0001 MOV CX, 1
0017 BA 0001 MOV DX, 1
001A 8B C3 MOV AX, BX
001C 8B C1 MOV AX, CX
001E 8B C2 MOV AX, DX
0020 83 C0 01 ADD AX, 1
0023 83 C0 02 ADD AX, 2
0026 03 C3 ADD AX, BX
0028 03 C1 ADD AX, CX
002A 03 06 0000 ADD AX, i
002E 83 E8 01 SUB AX, 1
0031 2B C3 SUB AX, BX
0033 05 1234 ADD AX, 1234h
Translating Languages
English: D is assigned the sum of A times B plus 10.

High-Level Language: D = A * B + 10

A statement in a high-level language is translated typically


into several machine-level instructions

Intel Assembly Language: Intel Machine Language:


mov eax, A A1 00404000
mul B F7 25 00404004
add eax, 10 83 C0 0A
mov D, eax A3 00404008
Advantages of High-Level Languages
• Program development is faster
– High-level statements: fewer instructions to code
• Program maintenance is easier
• Programs are portable
– Contain few machine-dependent details
• Can be used with little or no modifications on different
machines
– Compiler translates to the target machine language
– However, Assembly language programs are not
portable
Virtual Machine Concept
• An effective way to explain how a computer’s hardware
and software are related is called the virtual machine
concept.
• A computer can usually execute programs written in its
native machine language. Each instruction in this
language is simple enough to be executed using a
relatively small number of electronic circuits. For
simplicity, we will call this language L0.
• Programmers would have a difficult time writing
programs in L0 because it is enormously detailed and
consists purely of numbers. If a new language, L1 , could
be constructed that was easier to use, programs could
be written in L1. There are two ways to achieve this:
Interpretation:
• As the L1 program is running, each of its
instructions could be decoded and executed by a
program written in language L0. The L1 program
begins running immediately, but each instruction
has to be decoded before it can execute.
Translation:
• The entire L1 program could be converted into an
L0 program by an L0 program specifically designed
for this purpose. Then the resulting L0 program
could be executed directly on the computer
hardware.
Virtual Machines
• Rather than using only languages, it is easier to
think in terms of a hypothetical computer, or
virtual machine , at each level. we can define a
virtual machine as a software program that
emulates the functions of some other physical or
virtual computer.
• The virtual machine VM1 , can execute commands
written in language L1. The virtual machine VM0
can execute commands written in language L0.
• Each virtual machine can be constructed of either
hardware or software.
Why Learn Assembly Language?
• Two main reasons:
– Accessibility to system hardware
– To use space and time efficiently
 Some application of assembly languages are:
 Real time system. E.g Traffic control system
 Embedded system. Where there is no compiler. E.g Micro
chips.
 Operating system. Specially kernel part of operating
system. Where direct access of hard ware is necessary.
Assembler
• Software tools are needed for editing, assembling, linking,
and debugging assembly language programs
• An assembler is a program that converts source-code
programs written in assembly language into object files in
machine language
• Popular assemblers have emerged over the years for the
Intel family of processors. These include …
– TASM (Turbo Assembler from Borland)
– NASM (Netwide Assembler for both Windows and Linux), and
– MASM (Macro Assembler from Microsoft)
Linker and Link Libraries
• You need a linker program to produce
executable files
• It combines your program's object file created
by the assembler with other object files and
link libraries, and produces a single executable
program
• LINK32.EXE is the linker program provided with
the MASM distribution for linking 32-bit
programs
Assemble and Link Process
Source Object
File Assembler File

Source Object Executable


File Assembler File Linker
File

Source Object Link


File Assembler File Libraries

A project may consist of multiple source files


Assembler translates each source file separately into an object file
Linker links all object files together with link libraries
Microprocessor
• A microprocessor incorporates most or all of the functions of a
central processing unit (CPU) on a single integrated circuit (IC). [1]
• The first microprocessors emerged in the early 1970s and were
used for electronic calculators, using BCD arithmetics on 4-bit
words.
• Other embedded uses of 4 and 8-bit microprocessors, such as
terminals, printers, various kinds of automation etc, followed
rather quickly.
• Affordable 8-bit microprocessors with 16-bit addressing also led
to the first general purpose microcomputers in the mid-1970s.
ARCHITECTURES
• 8-bit designs
• 16-bit designs
• 32-bit designs
• 64-bit designs in personal computers
• Multicore designs
• RISC
• Special-purpose designs
– microcontrollers, digital signal processors (DSP) and
graphics processing units (GPU).
Binary operation
• AND
• XOR
• OR
• NOT
• Shift

You might also like