0% found this document useful (0 votes)
13 views6 pages

Assmbly language

Assembly language is a low-level programming language that uses mnemonic codes to represent machine instructions, making it more human-readable than machine code. It is specific to CPU architectures and requires an assembler to translate it into machine code. The document also covers various types of instructions (data movement, arithmetic, logical, control flow) and the process of converting assembly code to machine code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Assmbly language

Assembly language is a low-level programming language that uses mnemonic codes to represent machine instructions, making it more human-readable than machine code. It is specific to CPU architectures and requires an assembler to translate it into machine code. The document also covers various types of instructions (data movement, arithmetic, logical, control flow) and the process of converting assembly code to machine code.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Assembly Language

Assembly language is a low-level programming language that uses


mnemonic codes to represent machine instructions. These mnemonics
are human-readable abbreviations for the corresponding machine code
operations. For example, instead of writing the binary code for "add
two numbers," an assembly language programmer might write "ADD".

 Characteristics:
o Human-Readable: Assembly language is much easier to read
and write than machine code because it uses
understandable mnemonics like MOV, ADD, or JMP.
o Processor-Specific: Like machine code, assembly language is
specific to a particular CPU architecture. Each architecture
has its own set of mnemonics.
o Requires Assembly: Assembly language is translated into
machine code by an assembler, a special program that
converts assembly instructions into their binary
counterparts.

Data Movement Instructions:

 MOV: Moves data from one location to another.


o Example: MOV AX, BX (Moves the value in register BX to
register AX)
 PUSH: Pushes a value onto the stack.
o Example: PUSH EAX (Pushes the value in register EAX onto
the stack)
 POP: Pops a value off the stack and stores it in a register or
memory location.
o Example: POP EBX (Pops the top value from the stack and
stores it in register EBX)
 XCHG: Exchanges the values of two registers or memory locations.
o Example: XCHG AX, BX (Exchanges the values in registers AX
and BX)

Arithmetic Instructions:

 ADD: Adds two values and stores the result.


o Example: ADD AX, BX (Adds the values in registers AX and BX
and stores the result in AX)
 SUB: Subtracts one value from another and stores the result.
o Example: SUB AX, BX (Subtracts the value in register BX from
the value in register AX and stores the result in AX)
 MUL: Multiplies two values and stores the result.
o Example: MUL BX (Multiplies the value in register AX by the
value in register BX and stores the result in AX and DX)
 DIV: Divides one value by another and stores the quotient and
remainder.
o Example: DIV BX (Divides the value in AX by the value in BX
and stores the quotient in AX and the remainder in DX)

Logical Instructions:

 AND: Performs a bitwise AND operation on two values.


o Example: AND AX, 00001111B (Performs a bitwise AND
operation between the value in AX and the binary constant
00001111)
 OR: Performs a bitwise OR operation on two values.
o Example: OR AX, 00001111B (Performs a bitwise OR
operation between the value in AX and the binary constant
00001111)
 XOR: Performs a bitwise XOR operation on two values.
o Example: XOR AX, 00001111B (Performs a bitwise XOR
operation between the value in AX and the binary constant
00001111)
 NOT: Performs a bitwise NOT operation on a value.
o Example: NOT AX (Inverts all bits in register AX)

Control Flow Instructions:

 JMP: Jumps to a specified location in the program.


o Example: JMP label (Jumps to the label named "label")
 JZ: Jumps to a specified location if the zero flag is set.
o Example: JZ label (Jumps to the label named "label" if the
zero flag is set)
 JNZ: Jumps to a specified location if the zero flag is not set.
o Example: JNZ label (Jumps to the label named "label" if the
zero flag is not set)
 CALL: Calls a subroutine.
o Example: CALL procedure_name (Calls the subroutine
named "procedure_name")
 RET: Returns from a subroutine.
o Example: RET (Returns from the current subroutine)

 Example of Assembly Code:

csharp
Sample code:
MOV AL, 61h ; Move hexadecimal value 61 (97 in decimal) into
the AL register

This assembly instruction translates directly into machine code for


the CPU to execute.

Relationship Between Machine Code and Assembly Language

 Direct Correspondence: Every assembly instruction corresponds


directly to a machine code instruction. The assembler converts
the assembly instructions into machine code, so there is typically
a one-to-one mapping.
o For instance, the assembly instruction MOV AL, 61h might
be translated into the binary machine code 10110000
01100001.
 Mnemonics: Assembly language uses mnemonic codes for
instructions that are more intuitive to humans than raw binary
numbers.
o Example:
 Machine Code: 10110000 01100001
 Assembly Code: MOV AL, 61h
o Both represent the same operation but in different forms.
 Labels and Symbols: Assembly language allows the use of
symbolic names (labels) for memory addresses and variables,
making the code more understandable and maintainable. These
labels are replaced by actual memory addresses when the
assembler generates machine code.
o Example:

makefile
Sample code:
START: MOV AX, 0

In machine code, the label START would be replaced with an


actual memory address.

Assembler: The Bridge Between Assembly and Machine Code

 Definition: An assembler is a program that translates assembly


language into machine code. The assembler takes assembly code
as input and outputs the equivalent binary machine code.
 Assembly Process:
1. Parsing: The assembler reads the assembly code line by line.
2. Instruction Translation: Each mnemonic (like MOV, ADD) is
translated into its corresponding machine code.
3. Symbol Resolution: Labels and variables are replaced with
actual memory addresses.
4. Output: The assembler produces the machine code (binary)
as an output file, often with a .bin or .exe extension.
 Two Types of Assembly:

o One-Pass Assembler: Processes the assembly code in a


single pass, converting it to machine code as it reads.
o Two-Pass Assembler: First pass reads and records the
locations of labels, and the second pass translates the
instructions, using the recorded information.

Translating Assembly to Machine Code

Let’s walk through a simple example of how assembly code is translated


into machine code.

 Assembly Code:

sql
Sample code:
MOV AL, 61h ; Move hexadecimal value 61 into register AL
ADD AL, 1 ; Add 1 to the value in AL

 Step 1: Translate the first instruction MOV AL, 61h:


o MOV is represented by the opcode 10110000 in machine
code.
o The value 61h is 01100001 in binary.
o Together, the machine code is 10110000 01100001.
 Step 2: Translate the second instruction ADD AL, 1:
o ADD is represented by the opcode 00000100 in machine
code.
o The value 1 is 00000001 in binary.
o Together, the machine code is 00000100 00000001.
 Final Machine Code Sequence:

sql
Sample code:
10110000 01100001 ; MOV AL, 61h
00000100 00000001 ; ADD AL, 1

Higher-Level Concepts

 Assembly Language Macros: Some assembly languages support


macros, which allow programmers to define reusable sequences
of instructions, which are expanded by the assembler into
multiple machine code instructions.
 Optimization: Although assembly is low-level, understanding how
instructions map to machine code can help optimize software
performance. For instance, some instructions may be faster to
execute than others, even though they perform the same logical
operation.

Assembly vs. Machine Code in Modern Programming

 Abstraction in Higher-Level Languages: Most programmers work


with high-level languages like C, C++, Python, or Java, which are
much easier to read and write. The compiler converts this code
into assembly or machine code.
 Performance-Critical Software: In performance-critical software,
programmers sometimes use assembly language to optimize
specific portions of code. Embedded systems and systems
software (like operating systems) are typical areas where this
happens.

You might also like