Assignment no 1 assembly language
Assignment no 1 assembly language
Chapter no 1
1.1: “Section review”
1. How do assemblers and linkers work together?
Ans: Assemblers and Linkers: The assembler converts assembly language code into machine
code (object files). The linker then combines these object files into a single executable, resolving
references and adjusting memory addresses. Together, they transform human-readable code into
a runnable program.
2. How will studying assembly language enhance your understanding of operating systems?
Ans: Studying Assembly Language and Operating Systems: Studying assembly language helps
you understand how the operating system interacts with hardware at a low level, including
memory management, system calls, and device drivers. It provides insight into how higher-level
abstractions in operating systems are built upon machine-level instructions.
3. What is meant by a one-to-many relationship when comparing a high-level language to
machine language?
Ans: One-to-many relationship: A high-level language instruction can correspond to multiple
machine language instructions, meaning one high-level operation may require several machine-
level steps.
4. Explain the concept of portability as it applies to programming languages?
Ans: Portability: Portability refers to a program’s ability to run on different hardware or
operating systems without modification.
5. Is the assembly language for x86 processors the same as those for computer systems such
as the Vax or Motorola 68x00?
Ans: Assembly Language Differences: No, assembly language differs between processor
architectures like x86, VAX, and Motorola 68x00, as each has its own instruction set.
6. Give an example of an embedded systems application.
Ans: Embedded Systems Application: Example: A microcontroller controlling the temperature
in a thermostat.
7. What is a device driver?
Ans: Device Driver: A software component that allows the operating system to communicate
with hardware devices.
8. Do you suppose type checking on pointer variables is stronger (stricter) in assembly
language, or in C and C++?
Ans: Type Checking: Type checking is stricter in C and C++ because they have defined data
types and stricter rules for pointers compared to assembly.
9. Name two types of applications that would be better suited to assembly language than a
high-level language?
Ans: Applications for Assembly Language: Low-level system software (e.g., operating
systems), performance-critical routines (e.g., graphics rendering)
10. Why would a high-level language not be an ideal tool for writing a program that
directly accesses a printer port?
Ans: High-Level Language Limitation: High-level languages are abstracted from hardware,
making direct hardware manipulation (like accessing a printer port) more complex.
11. Why is assembly language not usually used when writing large application programs?
Ans: Why Not for Large Apps: Assembly language is too low-level, making development slow,
error-prone, and hard to maintain for large applications.
12. Challenge: Translate the following C++ expression to assembly language, using the
example presented earlier in this chapter as a guide: X (Y * 4) +3.
Ans: C++ to Assembly: The expression X + (Y * 4) + 3 would involve multiplying Y by 4,
adding the result to X, and subtracting 3 in assembly using corresponding machine instructions
for multiplication, addition, and subtraction.
Chapter no 2
2.1: “Section review”
1. The central processor unit (CPU) contains registers and what other basic elements?
Ans: Other basic elements in the CPU: The Arithmetic Logic Unit (ALU) and the Control Unit
(CU).
2. The central processor unit is connected to the rest of the computer system using what
three buses?
Ans: Three buses connecting CPU to the rest of the system: Data bus, Address bus, and
Control bus.
3. Why does memory access take more machine cycles than register access?
Ans: Memory access takes more machine cycles than register access: Because memory is
slower than registers, and it involves retrieving data from a larger storage space.
4. What are the three basic steps in the instruction execution cycle?
Ans: Three basic steps in the instruction execution cycle: Fetch, Decode, and Execute.
5. Which two additional steps are required in the instruction execution cycle when a
memory operand is used?
Ans: Two additional steps when a memory operand is used: Memory read (to fetch data from
memory) and Memory write (to store data into memory).
Chapter no 3
3.1: “Section review”
1. Using the value –35, write it as an integer literal in decimal, hexadecimal, octal, and
binary formats that are consistent with MASM syntax.
Ans: Value -35 as integer literals in different formats (MASM syntax):
Decimal: -35
Hexadecimal: -23h
Octal: -43o
Binary: -100011b
2. (Yes/No): Is A5h a valid hexadecimal literal?
Ans: Yes. A5h is a valid hexadecimal literal, where h signifies hexadecimal.
3. (Yes/No): Does the multiplication operator (*) have a higher precedence than the division
operator (/) in integer expressions?
Ans: No. In MASM, both multiplication (*) and division (/) have the same precedence, and they
are evaluated from left to right.
4. Create a single integer expression that uses all the operators from Section 3.1.2.
Calculate the value of the expression.
Ans: An example of an integer expression using all operators (addition +, subtraction -,
multiplication *, division /, and modulus %):
(6 + 2 * 3 - 4) / 2 + 5 % 2
Calculation:
Multiplication first: 2 * 3 = 6
Then: 6 + 6 - 4 = 8
Division: 8 / 2 = 4
Modulus: 5 % 2 = 1
Final result: 4 + 1 = 5
5. Write the real number -6.2 × 10⁴ as a real number literal using MASM syntax.
Ans: -6.2e4
6. (Yes/No): Must string literals be enclosed in single quotes?
Ans: No. In MASM, string literals are enclosed in double quotes ("), not single quotes.
7. Reserved words can be instruction mnemonics, attributes, operators, predefined
symbols, and __________.
Ans: Directives.
8. What is the maximum length of an identifier?
Ans: The maximum length of an identifier in MASM is 31 characters.