Assembly Language Assignment 1
Assembly Language Assignment 1
Assembly Language
Chapter 1
1.1.3 Section Review
1. How do assemblers and linkers work together?
Ans: An assembler translates assembly language code into object code (machine-readable). The
linker combines object files into an executable, resolving references between code segments and
libraries.
Ans: Studying assembly provides insight into low-level system operations, memory
management, and hardware interaction, which are essential for understanding OS functions like
process control and resource allocation.
Ans: A one-to-many relationship means a single high-level language statement can translate
into multiple machine code instructions.
Ans: Portability refers to a program's ability to run on different hardware or operating systems
with little or no modification, often achieved with high-level languages.
5. Is the assembly language for x86 processors the same as those for computer systems
such as the Vax or Motorola 68x00?
Ans: No, assembly language is architecture-specific, so the x86, VAX, and Motorola 68x00
processors each have different assembly languages based on their distinct instruction sets.
Ans: A device driver is software that allows the operating system to communicate and control
hardware devices like printers, keyboards, or graphics cards.
Ans: Type checking is stronger in C and C++. In assembly, there is no type checking, leaving
the programmer responsible for ensuring proper usage of pointers.
9. Name two types of applications that would be better suited to assembly language than a
high-level language.
Ans: Embedded systems with limited resources and performance-critical applications like
video games or real-time software.
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 languages abstract hardware details, which makes it difficult to perform precise,
low-level control required to access hardware ports directly.
11. Why is assembly language not usually used when writing large application programs?
12. Challenge: Translate the following C++ expression to assembly language, using the
example presented earlier in this chapter as a guide: X + (Y * 4)
Ans: A virtual machine is an abstraction layer between the hardware and software that allows
programs to run independently of the underlying physical machine. It provides a uniform
environment for executing software, regardless of the hardware.
2: Why do you suppose translated programs often execute more quickly than interpreted
ones?
Ans: Translated programs are compiled into machine code, which can be executed directly by
the hardware, making them faster. Interpreted programs require real-time translation, adding
overhead during execution.
Ans: True. The interpreter (written in language L0) decodes and executes the instructions of the
program written in language L1 at runtime.
4: Explain the importance of translation when dealing with languages at different virtual
machine levels.
Ans: Translation ensures that higher-level languages can be converted into machine code or
assembly language, which can be understood and executed by the hardware. It allows programs
to be portable across different systems.
5: At which level does assembly language appear in the virtual machine example shown in
this section?
Ans: Assembly language appears just above machine language in the virtual machine, acting as
a low-level, human-readable representation of machine instructions.
6: What software utility permits compiled Java programs to run on almost any computer?
Ans: The Java Virtual Machine (JVM) allows compiled Java programs to run on any computer
by abstracting the underlying hardware and providing a platform-independent environment.
7: Name the four virtual machine levels named in this section, from lowest to highest.
1. Machine language
2. Assembly language
3. High-level language
4. User-level/application-level
9: Machine language is used at which level of the virtual machine shown in Figure 1-1?
Ans: Machine language is used at the lowest level of the virtual machine, as it directly
corresponds to instructions executed by the processor.
10: Statements at the assembly language level of a virtual machine are translated into
statements at which other level?
Ans: Assembly language statements are translated into machine language for execution by the
hardware.
Ans: The least significant bit (LSB) is the bit in a binary number that represents the smallest
value. It is located at the far right of the binary number.
2. What is the decimal representation of each of the following unsigned binary integers?
c. 11110000 = 240
4. How many bytes are contained in each of the following data types?
b. Doubleword = 4 bytes
c. Quadword = 8 bytes
5. What is the minimum number of binary bits needed to represent each of the following
unsigned decimal integers?
Ans: a. 65 = 7 bits
b. 409 = 9 bits
c. 16385 = 15 bits
Ans: The expression ¬X ∨ Y means "NOT X OR Y". It is true if either X is false or Y is true (or
both).
Ans: The expression (X ∧ Y) means "X AND Y". It is true only if both X and Y are true.
Ans: ¬F ∨ ¬T = T ∨ F = T. The negation of false is true, and true OR anything is true, so the
final value is T.
Chapter 2
1. The central processor unit (CPU) contains registers and what other basic elements?
Ans: The CPU also contains arithmetic logic units (ALU), control units, and cache memory.
2. The central processor unit is connected to the rest of the computer system using what
three buses?
Ans: The CPU is connected using the data bus, address bus, and control bus.
3. Why does memory access take more machine cycles than register access?
Ans: Memory access takes more cycles because accessing memory involves more steps, such as
addressing, fetching, and possible delays due to the slower speed of main memory compared to
registers.
4.What are the three basic steps in the instruction execution cycle?
5. Which two additional steps are required in the instruction execution cycle when a
memory operand is used?
Ans: When a memory operand is used, the additional steps are memory read and memory
write (if applicable).
Ans: The three basic modes of operation are Real Mode, Protected Mode, and Long Mode.
Ans: The eight 32-bit general-purpose registers are: EAX, EBX, ECX, EDX, ESI, EDI, EBP,
and ESP.
3. Name all six segment registers.
Ans: The six segment registers are: CS (Code Segment), DS (Data Segment), SS (Stack
Segment), ES (Extra Segment), FS, and GS.
Ans: The ECX register is primarily used as a counter in string operations and loops, such as in
the REP (repeat) prefix and other iteration instructions.
Ans: SRAM (Static Random Access Memory) is a type of memory that retains data as long as
power is supplied, without needing to be refreshed like DRAM. It is faster and more reliable but
more expensive. The most common use is as cache memory in processors.
2. Describe VRAM.
Ans: VRAM (Video Random Access Memory) is a type of memory used for storing video and
graphical data. It is primarily used in graphics cards to store frame buffers and textures,
improving the performance of video rendering.
3. List at least two features found in the Intel P965 Express chipset.
Ans: Two features of the Intel P965 Express chipset include support for Intel Core 2
processors and support for DDR2 memory.
Ans: Four types of RAM mentioned are SRAM, DRAM, SDRAM, and VRAM.
Ans: The 8259A PIC (Programmable Interrupt Controller) is used to manage interrupts in a
computer system, allowing the CPU to prioritize and handle multiple interrupt requests.
2.5.2 Section Review
1. Of the four levels of input/output in a computer system, which is the most universal
and portable?
Ans: The operating system (OS)-level I/O is the most universal and portable, as it provides a
standardized interface for interacting with hardware across different systems.
2. What characteristics distinguish BIOS-level input/output?
Ans: BIOS-level I/O is typically low-level, hardware-specific, and operates before the operating
system is loaded. It handles basic system functions like disk booting and keyboard input,
providing direct communication with the hardware.
3. Why are device drivers necessary, given that the BIOS already has code that
communicates with the computer’s hardware?
Ans: Device drivers are necessary because they provide a more advanced, OS-specific interface
for the hardware, allowing for proper interaction with software applications. BIOS-level code is
limited and can’t handle the full range of modern hardware features.
4. In the example regarding displaying a string of characters, which level exists between
the operating system and the video controller card?
Ans: The device driver level exists between the operating system and the video controller card,
translating OS requests into specific instructions for the hardware.
5. Is it likely that the BIOS for a computer running MS-Windows would be different from
that used by a computer running Linux?
Ans: No, the BIOS is typically independent of the operating system and is the same for both MS-
Windows and Linux. The OS interacts with the BIOS at a higher level, but the BIOS itself is
hardware-specific.
Chapter 3
3.1.11 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.
Hexadecimal: -23h
Octal: -43o
Binary: -100011
3. (Yes/No): Does the multiplication operator (*) have a higher precedence than the division
operator (/) in integer expressions?
Ans: Yes, the multiplication operator (*) has a higher precedence than the division operator (/) in
integer expressions.
4. Create a single integer expression that uses all the operators from Section 3.1.2.
Calculate the value of the expression.
Example expression: (5 + 3) * 4 / 2 - 1
5. Write the real number –6.2 × 10^4 as a real number literal using MASM syntax.
Ans: -6.2e4
Ans: Yes, string literals must be enclosed in single quotes in MASM syntax.
7.Reserved words can be instruction mnemonics, attributes, operators, predefined symbols,
and __________.
Ans: Labels
Ans: The INCLUDE directive is used to insert external files or libraries into the program,
typically including macros or predefined code that is needed for the program.
Ans: The .CODE directive identifies the start of the code segment where the executable
instructions of the program are written.
3. What are the names of the two segments in the AddTwo program?
Ans: The two segments in the AddTwo program are typically .DATA (for data definitions) and
.CODE (for the program's executable instructions).
Ans: In the AddTwo program, the AX register typically holds the sum after the addition.
Ans: The RET (return) or INT 20h statement halts the program in MASM assembly.
Ans: The assembler typically produces object files (with extensions like .obj or .o), which
contain machine code but are not yet executable.
2. (True/False): The linker extracts assembled procedures from the link library and inserts
them in the executable program.
Ans: True, the linker extracts and combines the necessary code from libraries into the final
executable program.
Ans: True, the modified source code must be reassembled and linked to create an updated
executable.
Ans: The operating system's loader reads and executes programs by loading them into
memory.
Ans: The linker produces executable files (with extensions like .exe or .out) and may also
produce static library files (like .lib or .a).
Ans: BYTE DB ?
(In MASM, DB is used for defining a byte, and ? indicates it is uninitialized.)
Ans: SBYTE DB ?
(In MASM, SBYTE refers to a signed 8-bit integer.)
Ans: The SDWORD data type can hold a 32-bit signed integer in MASM.
1. Declare a symbolic constant using the equal-sign directive that contains the ASCII code
(08h) for the Backspace key.
2. Declare a symbolic constant named SecondsInDay using the equal-sign directive and
assign it an arithmetic expression that calculates the number of seconds in a 24-hour
period.
3. Write a statement that causes the assembler to calculate the number of bytes in the
following array, and assign the value to a symbolic constant named ArraySize:
4. Show how to calculate the number of elements in the following array, and assign the
value to a symbolic constant named ArraySize:
6. Use TEXTEQU to create a symbol named Sample for a string constant, and then use the
symbol when defining a string variable named MyString.