Assembly Language
Assembly Language
Assembly Language
Since most compilers convert source code directly to machine code, software
developers often create programs without using assembly language. However, in some
cases, assembly code can be used to fine-tune a program. For example, a programmer
may write a specific process in assembly language to make sure it functions as
efficiently as possible.
The following assembly language can be used to add the numbers 3 and 4:
This list of DOS commands is very useful when repairing Windows after a system
crash when Windows doesn’t load and the only option you have is a Dos command
prompt. Use the “help” command to find the usage and details of any particular
command e.g. C:\>help copy
CHDIR – Displays the name of or changes the current directory.
COMP – Compares two groups of files to find information that does not match.
DELTREE – Deletes a directory including all files and subdirectories that are in it.
ECHO – Displays messages or turns on or off the display of commands in a batch file.
EDIT – Starts the MS-DOS editor, a text editor used to create and edit ASCII text files.
FIND – Finds and reports the location of a specific string of text characters in one or
more files.
FOR – Performs repeated execution of commands (for both batch processing and
interactive processing).
MOVE – Moves one or more files to the location you specify. Can also be used to
rename directories.
PATH – Sets or displays directories that will be searched for programs not in the
current directory.
Assembler
An assembler is a program that converts assembly language into machine code. It takes
the basic commands and operations from assembly code and converts them
into binary code that can be recognized by a specific type of processor.
Assemblers are similar to compilers in that they produce executable code. However,
assemblers are more simplistic since they only convert low-level code (assembly
language) to machine code. Since each assembly language is designed for a specific
processor, assembling a program is performed using a simple one-to-one mapping from
assembly code to machine code. Compilers, on the other hand, must convert generic
high-level source code into machine code for a specific processor.
Most programs are written in high-level programming languages and are compiled
directly to machine code using a compiler. However, in some cases, assembly code may
be used to customize functions and ensure they perform in a specific way.
Therefore, IDEs often include assemblers so they can build programs from both high
and low-level languages.
Preprocessor Directives
Preprocessor directives are lines included in a program that begin with the
character #, which make them different from a typical source code text. They are
invoked by the compiler to process some programs before compilation. Preprocessor
directives change the text of the source code and the result is a new source code without
these directives.
Although preprocessing in C# is conceptually similar to that in C/C++, it is different
in two aspects. First, preprocessing in C# does not involve a separate step for
preprocessor execution before compilation. It is processed as a part of the lexical
analysis phase. Second, it cannot be used to create macros. In addition, the new
directives #region and #unregion have been added in C# along with the exclusion of
some directives used earlier (#include is a notable directive whose use is replaced with
"using" to include assemblies).
Java does not support preprocessor directives.
A preprocessor directive is usually placed in the top of the source code in a separate
line beginning with the character "#", followed by directive name and an optional white
space before and after it. Because a comment on the same line of declaration of the
preprocessor directive has to be used and cannot scroll through the following line,
delimited comments cannot be used. A preprocessor directive statement must not end
with a semicolon (;). Preprocessor directives can be defined in source code or in the
common line as argument during compilation.
#if, #elif, #else, and #endif: To skip part of source code based on conditions.
Conditional sections may be nested with directives forming complete sets.
#line: To control line numbers generated for errors and warning. This is
mostly used by meta-programming tools to generate C# source code from
some text input. It is generally used to modify the line numbers and source
file names reported by the compiler in its output.
#error and #warning : To generate errors and warnings, respectively.
#error is used to stop compilation, while #warning is used to continue
compilation with messages in the console.
#region and #endregion :To explicitly mark sections of source code. These
allow expansion and collapse inside Visual Studio for better readability and
reference.
Instruct
Meaning Notes Opcode
ion
Instruct
Meaning Notes Opcode
ion
0x10…0x15,
destination := destination +
ADC Add with carry 0x80/2…0x
source + carry_flag
83/2
0x00…0x05,
(1) r/m += r/imm; (2) r +=
ADD Add 0x80/0…0x
m/imm;
83/0
0x20…0x25,
(1) r/m &= r/imm; (2) r &=
AND Logical AND 0x80/4…0x
m/imm;
83/4
0x9A, 0xE8,
push eip; eip points to the
CALL Call procedure 0xFF/2,
instruction directly after the call
0xFF/3
Instruct
Meaning Notes Opcode
ion
0x38…0x3D,
CMP Compare operands 0x80/7…0x
83/7
Compare bytes in
CMPSB 0xA6
memory
Convert word to
CWD 0x99
doubleword
0x48…0x4F,
DEC Decrement by 1 0xFE/1,
0xFF/1
Used
ESC 0xD8..0xDF
with floating-point unit
Original 8086/8088 instruction set
Instruct
Meaning Notes Opcode
ion
0x69, 0x6B
(both since
80186),
(1) DX:AX = AX * r/m; (2) AX = 0xF6/5,
IMUL Signed multiply
AL * r/m 0xF7/5,
0x0FAF
(since
80386)
0x40…0x47,
INC Increment by 1 0xFE/0,
0xFF/0
Call to interrupt if
INTO 0xCE
overflow
Instruct
Meaning Notes Opcode
ion
0xE9…0xEB
JMP Jump , 0xFF/4,
0xFF/5
Instruct
Meaning Notes Opcode
ion
if (DF==0)
*(byte*)DI-- = *(byte*)SI--;
if (DF==0)
*(word*)DI-- = *(word*)SI--;
Instruct
Meaning Notes Opcode
ion
0x08…0x0D
(1) r/m |= r/imm; (2) r |= m/im ,
OR Logical OR
m; 0x80…0x83
/1
0x07,
r/m = *SP++; POP CS (opcode 0x0F(8086/
0x0F) works only on 8086/8088. 8088 only),
POP Pop data from stack
Later CPUs use 0x0F as a prefix 0x17, 0x1F,
for newer instructions. 0x58…0x5F,
0x8F/0
Pop FLAGS
POPF FLAGS = *SP++; 0x9D
register from stack
0x06, 0x0E,
0x16, 0x1E,
0x50…0x57,
PUSH Push data onto stack *--SP = r/m; 0x68, 0x6A
(both since
80186),
0xFF/6
Instruct
Meaning Notes Opcode
ion
0xC0…0xC1
/2 (since
RCL Rotate left (with carry) 80186),
0xD0…0xD3
/2
0xC0…0xC1
/3 (since
Rotate right (with
RCR 80186),
carry)
0xD0…0xD3
/3
Repeat
(REP, REPE, REPNE, REPNZ,
REPxx MOVS/STOS/CMPS/L 0xF2, 0xF3
REPZ)
ODS/SCAS
Instruct
Meaning Notes Opcode
ion
/0 (since
80186),
0xD0…0xD3
/0
0xC0…0xC1
/1 (since
ROR Rotate right 80186),
0xD0…0xD3
/1
0xC0…0xC1
/4 (since
Shift Arithmetically left
SAL (1) r/m <<= 1; (2) r/m <<= CL; 80186),
(signed shift left)
0xD0…0xD3
/4
0xC0…0xC1
/7 (since
Shift Arithmetically (1) (signed) r/m >>=
SAR 80186),
right (signed shift right) 1; (2) (signed) r/m >>= CL;
0xD0…0xD3
/7
Instruct
Meaning Notes Opcode
ion
instruction
0xC0…0xC1
/4 (since
Shift left (unsigned shift
SHL 80186),
left)
0xD0…0xD3
/4
0xC0…0xC1
/5 (since
Shift right (unsigned
SHR 80186),
shift right)
0xD0…0xD3
/5
Instruct
Meaning Notes Opcode
ion
0x28…0x2D,
(1) r/m -= r/imm; (2) r -=
SUB Subtraction 0x80…0x83
m/imm;
/5
0x84, 0x84,
0xA8, 0xA9,
TEST Logical compare (AND) (1) r/m & r/imm; (2) r & m/imm;
0xF6/0,
0xF7/0
Table look-up
XLAT behaves like MOV AL, [BX+AL] 0xD7
translation
0x30…0x35,
(1) r/m ^= r/imm; (2) r ^=
XOR Exclusive OR 0x80…0x83
m/imm;
/6