Assembly Language Revision Notes
Assembly Language Revision Notes
1. TASM: TASM is a widely used assembler developed by Borland. It supports both 16-
bit and 32-bit assembly language programming for the x86 family of processors.
TASM is known for its ease of use, extensive documentation, and compatibility with a
wide range of operating systems. It has been used to develop a variety of software
applications, including device drivers, system utilities, and embedded systems.
.MODEL SMALL
.STACK 100h
.DATA
message DB 'Hello$'
.CODE
Explanation:
The .MODEL SMALL directive tells TASM to generate a small memory model
program.
The .STACK 100h directive reserves 256 bytes of memory for the stack.
The .DATA section declares the message variable as a string containing the
characters "Hello" and a null terminator ($).
The .CODE section is where the program code begins.
The MOV AH, 09h instruction loads the value 9 into the AH register. This value
represents the DOS function to print a string to the console.
The MOV DX, OFFSET message instruction loads the offset of the message
variable into the DX register. This register will point to the beginning of the string
to be printed.
The INT 21h instruction calls the DOS interrupt to print the string to the console.
The MOV AH, 4Ch instruction loads the value 4C into the AH register. This value
represents the DOS function to terminate the program.
The INT 21h instruction calls the DOS interrupt to terminate the program and
return control to the operating system.
The END directive marks the end of the program.
When the program is executed, it will print "Hello" to the console and then
terminate. The $ character at the end of the string is necessary to signal the end of
the string to the DOS interrupt that prints it.
.stack 100h
.data
.code
end
Explanation:
The .model small directive tells MASM to generate a small memory model
program.
The .stack 100h directive reserves 256 bytes of memory for the stack.
The .data section declares the message variable as a string containing the
characters "Hello" (0Ah is a line feed character for a new line) and a null
terminator ($).
The .code section is where the program code begins.
The mov ah, 09h instruction loads the value 9 into the ah register. This value
represents the DOS function to print a string to the console.
The lea dx, message instruction loads the offset of the message variable into the
dx register using the "load effective address" instruction.
The int 21h instruction calls the DOS interrupt to print the string to the console.
The mov ah, 4Ch instruction loads the value 4C into the ah register. This value
represents the DOS function to terminate the program.
The int 21h instruction calls the DOS interrupt to terminate the program and
return control to the operating system.
The end directive marks the end of the program.
When the program is executed, it will print "Hello" to the console and then
terminate. The $ character at the end of the string is necessary to signal the end of
the string to the DOS interrupt that prints it.
Both TASM and MASM provide a powerful set of tools for low-level software
development. They allow programmers to write code that directly interacts with the
hardware, making them ideal for developing device drivers and system utilities.
However, assembly language programming can be complex and time-consuming, and it
requires a deep understanding of the underlying hardware architecture. Therefore, these
assemblers are typically used by experienced programmers with a background in low-
level programming.
In conclusion, TASM and MASM are two popular assembly language assemblers used in
the development of low-level software for the x86 family of processors. They provide a
powerful set of tools for low-level programming but require a deep understanding of
the underlying hardware architecture. These assemblers continue to be used today by
experienced programmers in the development of device drivers, system utilities, and
other low-level software applications.
1. Syntax: TASM uses a different syntax than MASM. TASM uses an older syntax
that is based on the Intel syntax, while MASM uses a more modern syntax that is
based on the Microsoft syntax. This difference may affect the readability and
maintainability of the code.
2. Features: MASM has more features than TASM. For example, MASM supports
macros, which are reusable code segments that can be inserted into the program,
while TASM does not. MASM also supports more advanced data types, such as
structures and unions, which can make programming easier.
3. Compatibility: TASM is primarily used with Borland compilers, while MASM is
primarily used with Microsoft compilers. However, both assemblers can be used
with other compilers as well.
4. Performance: TASM is generally considered to be faster than MASM, but the
difference in performance is often negligible.
5. Support: MASM has better documentation and support from Microsoft, while
TASM has a smaller community of users and less support.
In conclusion, TASM and MASM are both popular assemblers for the x86
architecture. They provide a powerful set of tools for low-level programming and
have been used to develop a wide range of software applications. While TASM is
known for its ease of use and compatibility with a wide range of operating systems,
MASM is known for its powerful macro capabilities and ability to generate optimized
code.
1. CMP - Compare The CMP instruction is used to compare two values. It subtracts
the second operand from the first operand and sets the flags based on the result,
without actually changing the values of the operands. The syntax for CMP is:
Here, dest and src are the operands to be compared. If dest is less than src, the
Carry flag (CF) is set. If dest is equal to src, the Zero flag (ZF) is set. If dest is
greater than src, the Sign flag (SF) is set.
2. JE/JZ - Jump if Equal/Jump if Zero The JE/JZ instruction is used to jump to a
different location in the code if the Zero flag (ZF) is set. The syntax for JE/JZ is:
JE/JZ label
Here, label is the destination address of the jump. If the Zero flag (ZF) is set, the
jump is taken.
3. JNE/JNZ - Jump if Not Equal/Jump if Not Zero The JNE/JNZ instruction is used to
jump to a different location in the code if the Zero flag (ZF) is not set. The syntax
for JNE/JNZ is:
JNE/JNZ label
Here, label is the destination address of the jump. If the Zero flag (ZF) is not set,
the jump is taken.
4. JA/JNBE - Jump if Above/Jump if Not Below or Equal The JA/JNBE instruction is
used to jump to a different location in the code if the Carry flag (CF) and Zero
flag (ZF) are both clear. The syntax for JA/JNBE is:
JA/JNBE label
Here, label is the destination address of the jump. If the Carry flag (CF) and Zero
flag (ZF) are both clear, the jump is taken.
5. JB/JC/JNAE - Jump if Below/Jump if Carry/Jump if Not Above or Equal The
JB/JC/JNAE instruction is used to jump to a different location in the code if the
Carry flag (CF) is set. The syntax for JB/JC/JNAE is:
JB/JC/JNAE label
Here, label is the destination address of the jump. If the Carry flag (CF) is set, the
jump is taken.
6. JG/JNLE - Jump if Greater/Jump if Not Less or Equal The JG/JNLE instruction is
used to jump to a different location in the code if the Zero flag (ZF) is clear and
the Sign flag (SF) is equal to the Overflow flag (OF). The syntax for JG/JNLE is:
JG/JNLE label
Here, label is the destination address of the jump. If the Zero flag (ZF) is clear and
the Sign flag (SF) is equal to the Overflow flag (OF), the jump is taken.
1. Numeric I/O: Numeric I/O refers to the input and output of numerical data in
assembly language programs. The IN and OUT instructions are used to perform
input and output operations respectively. For example, the following code reads a
byte from port 0x60 and stores it in the AL register:
IN AL, 60h
Similarly, the following code outputs the value in the BL register to port 0x80 :
OUT 80h, BL
2. Macros: Macros are a way to define reusable code segments in assembly language.
They are similar to functions in high-level languages. Macros are defined using the
MACRO directive, and can take arguments. Here's an example of a simple macro that
adds two numbers:
ENDM
To use the macro, you would call it with two arguments:
MYMACRO 10, 20
MOV AX, 10
ADD AX, 20
3. Bit Operations: Bit operations are used to manipulate individual bits in a binary
number. Some common bit operations include AND, OR, XOR, NOT, SHIFT LEFT, and
SHIFT RIGHT. For example, the following code sets the 5th bit of the AL register to 1:
OR AL, 20h
This works by OR-ing the AL register with the value 0x20, which has a 1 in the 5th bit
position. Similarly, the following code clears the 3rd bit of the BL register:
This works by AND-ing the BL register with the bitwise NOT of the value 0x04, which
has a 0 in the 3rd bit position.
Overall, Numeric I/O, Macros, and Bit Operations are fundamental to low-level
programming and are used extensively in system-level programming and hardware
control.