Assembly Language

20
University of Diyala College of Engineering Communication Department Assembly Language

Transcript of Assembly Language

Page 1: Assembly Language

University of Diyala College of EngineeringCommunication Department

Assembly Language

Page 2: Assembly Language
Page 3: Assembly Language

Example of machine-languageHere’s what a program-fragment looks like:

10100001 10111100 10010011 0000010000001000 00000011 00000101 11000000 10010011 00000100 00001000 1010001111000000 10010100 00000100 00001000

It means: z = x + y;

Page 4: Assembly Language

Machine language Native to a processor: executed directly by hardware

Instructions consist of binary code: 1s and 0s

Assembly language A programming language that uses symbolic names to represent

operations, registers and memory locations.

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

Page 5: Assembly Language
Page 6: Assembly Language

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

GNU assembler distributed by the free software foundation

Page 7: Assembly Language

In assembly language, mnemonics are used to specify an opcode that represents a complete and operational machine language instruction. This is later translated by the assembler to generate the object code. For example, the mnemonic MOV is used in assembly language for copying and moving data between registers and memory locations.

mnemonics

Page 8: Assembly 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.

Page 9: Assembly Language

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.

Page 10: Assembly Language

Assembly Language Instructions Built from two pieces

Add R1, R3, 3

OpcodeWhat to do

with the data(ALU

operation)

OperandsWhere to get data

and put the results

Page 11: Assembly Language

Types of Opcodes Arithmetic, logical

◦ add, sub, mult◦ and, or◦ Cmp

Memory load/store◦ ld, st

Control transfer◦ jmp◦ bne

Complex◦ movs

Page 12: Assembly Language

Each operand taken from a particular addressing mode:

Examples:Register add r1, r2, r3Immediate add r1, r2, 10Indirect mov r1, (r2)Offset mov r1, 10(r3)PC Relative beq 100

Reflect processor data pathways

Operands

Page 13: Assembly Language
Page 14: Assembly Language
Page 15: Assembly Language

ASCII, American Standard Code for Information Interchange, is a scheme used for assigning numeric values to punctuation marks, spaces, numbers and other characters. ASCII uses 7 bits to represent characters. The values 000 0000 through 111 1111 or 00 through 7F are used giving ASCII the ability to represent 128 different characters. An extended version of ASCII assigns characters from 80 through FF.

ASCII

Page 16: Assembly Language

Accessibility to system hardware

Assembly Language is useful for implementing system software

Also useful for small embedded system applications

Space and Time efficiency

Understanding sources of program inefficiency

Tuning program performance

Writing compact code

Writing assembly programs gives the computer designer the needed deep understanding of the instruction set and how to design one

To be able to write compilers for HLLs, we need to be expert with the machine language. Assembly programming provides this experience

Page 17: Assembly Language

Advantages of Assembly Language

1. Shows how program interfaces with the processor, operating system, and BIOS.

2. Shows how data is represented and stored in memory and on external devices.

3. Clarifies how processor accesses and executes instructions and how instructions access and process data.

4. Clarifies how a program accesses external devices.

Page 18: Assembly Language

1. Assembly Language is used when speed and reliability are the overriding factor like small footprint real-time operating systems. 2. By using assembly language, programmers can maximize on speed to a level. It is easy to write than machine code programs. 3. It allows the programmer access to registers or instructions that are not usually provided by a High-level language. 4. The main Application of Assembly Language is for direct hardware manipulation i.e. device drivers.5. Assembly language also directly correlates which machine instructions; the only way to get closer to the machine is to write in binary or hex code.

What is the application of assembly Language?

Page 19: Assembly Language
Page 20: Assembly Language