0% found this document useful (0 votes)
12 views

Assignment no 1 assembly language

Assignment assembly language 1

Uploaded by

sibghaaslam71
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment no 1 assembly language

Assignment assembly language 1

Uploaded by

sibghaaslam71
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Assignment no 1

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.

1.2: “Section review”


1. In your own words, describe the virtual machine concept.
Ans: Virtual Machine Concept: A virtual machine (VM) is a software-based emulation of a
physical computer that allows programs to run as if they were on a real machine. It provides an
abstraction layer that makes the program independent of the underlying hardware.
2. Why do you suppose translated programs often execute more quickly than interpreted
ones?
Ans: Translated Programs vs. Interpreted: Translated programs (like compiled ones) execute
faster because they are directly converted into machine code, which the CPU can execute
immediately. Interpreted programs, on the other hand, require decoding and execution by an
interpreter during runtime, which introduces overhead.
3. (True/False): When an interpreted program written in language L1 runs, each of its
instructions is decoded and executed by a program written in language L0.
Ans: True: When an interpreted program runs, each instruction is decoded and executed by an
interpreter program written in a different language (usually lower-level, like C or assembly).
4. Explain the importance of translation when dealing with languages at different virtual
machine levels.
Ans: Importance of Translation: Translation between different virtual machine levels allows
code written in high-level languages to be executed on various hardware platforms. It ensures
that high-level abstractions can run on different machine architectures without direct
modification.
5. At which level does assembly language appear in the virtual machine example shown in
this section?
Ans: Assembly Language Level: In the virtual machine example, assembly language typically
appears just above machine language, serving as a human-readable representation of the machine
code.
6. What software utility permits compiled Java programs to run on almost any computer?
Ans: Java Utility: The Java Virtual Machine (JVM) allows compiled Java programs (bytecode)
to run on almost any computer, providing portability across different platforms.
7. Name the four virtual machine levels named in this section, from lowest to highest.
Ans: Four Virtual Machine Levels: From lowest to highest:
1. Machine Language
2. Assembly Language
3. High-Level Language
4. Virtual Machine (e.g., JVM)
8. Why don’t programmers write applications in machine language?
Ans: Why Not Machine Language: Programmers avoid writing in machine language because it
is difficult to understand, error-prone, and time-consuming. High-level languages are more
abstract, easier to work with, and less prone to errors.
9. Machine language is used at which level of the virtual machine shown in Figure 1-1?
Ans: Machine Language Level: Machine language is used at the lowest level of the virtual
machine.
10. Statements at the assembly language level of a virtual machine are translated into
statements at which other level?
Ans: Assembly Language Translation: Statements in assembly language are translated into
machine language, which the CPU can directly execute.

1.3: “Section review”


1. Explain the term least significant bit (LSB).
Ans: Least Significant Bit (LSB): The least significant bit (LSB) is the rightmost bit in a binary
number. It represents the smallest possible value (1 or 0) in the number and changes the overall
value the least.
2. What is the decimal representation of each of the following unsigned binary integers?
Ans: Decimal Representation of Unsigned Binary Integers:
a.11111000:
1×27+1×26+1×25+1×24+0×23+0×22+0×21+0×20
= 128 + 64 + 32 + 16 = 240
b. 11001010:
1×27+1×26+0×25+0×24+1×23+0×22+1×21+0×20
= 128 + 64 + 8 + 2 = 202
c. 11110000:
1×27+1×26+1×25+1×24+0×23+0×22+0×21+0×20
= 128 + 64 + 32 + 16 = 240
3. What is the sum of each pair of binary integers?
Ans: Sum of Binary Integers:
a.00001111+00000010:
00001111 = 15, 00000010 = 2 → 15 + 2 = 00010001
b.11010101+01101011:
11010101 = 213, 01101011 = 107 → 213 + 107 = 11011100
c.00001111+00001111:
00001111 = 15 → 15 + 15 = 00011110
4. How many bytes are contained in each of the following data types?
a. word
b. doubleword
c. quadword
d. double quadword
Ans: Bytes in Each Data Type:
a. Word: 2 bytes (16 bits)
b. Doubleword: 4 bytes (32 bits)
c. Quadword: 8 bytes (64 bits)
d. Double Quadword: 16 bytes (128 bits)
5. What is the minimum number of binary bits needed to represent each of the following
unsigned decimal integers?
a. 65
b. 409
c. 16385
Ans: Minimum Number of Binary Bits for Unsigned Decimal Integers:
a. 65: The minimum number of bits is 7
b. 409: The minimum number of bits is 9
c. 16385: The minimum number of bits is 15
6. What is the hexadecimal representation of each of the following binary numbers?
Ans: Hexadecimal Representation of Binary Numbers:
a. 0011 0101 1101 1010 = 35DA
b. 1100 1110 1010 0011 = CEA3
c. 1111 1110 1101 1011 = FEDB
7. What is the binary representation of the following hexadecimal numbers?
Ans: Binary Representation of Hexadecimal Numbers:
a. A4693FBC = 1010 0100 0110 1001 0011 1111 1011 1100
b. B697C7A1 = 1011 0110 1001 0111 1100 0111 1010 0001
c. 2B3D9461 = 0010 1011 0011 1101 1001 0100 0110 0001

1.4: “Section review”


1. Describe the following boolean expression: ¬X ∨ Y.
Ans: ¬X ∨ Y: This is the logical OR of the negation of X and Y. It evaluates to true if either X is
false or Y is true.
2. Describe the following boolean expression: (X ∧ Y).
Ans: (X ∧ Y): This is the logical AND of X and Y. It evaluates to true only if both X and Y are
true.
3. What is the value of the boolean expression (T ∧ F) ∨ T?
Ans: (T ∧ F) ∨ T: The value is T. (T ∧ F) is F, and F ∨ T is T.
4. What is the value of the boolean expression ¬ (F ∨ T)?
Ans: ¬ (F ∨ T): The value is F. (F ∨ T) is T, and negating it gives F.
5. What is the value of the boolean expression ¬F ∨ ¬T?
Ans: ¬F ∨ ¬T: The value is T. (¬F is T and ¬T is F, so T ∨ F is T).

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).

2.2: “Section review”


1. What are the x86 processor’s three basic modes of operation?
Ans: Three basic modes of operation of the x86 processor:
 Real mode
 Protected mode
 Long mode
2. Name all eight 32-bit general-purpose registers.
Ans: Eight 32-bit general-purpose registers:
 EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP
3. Name all six segment registers.
Ans: Six segment registers:
 CS (Code Segment)
 DS (Data Segment)
 SS (Stack Segment)
 ES (Extra Segment)
 FS
 GS
4. What special purpose does the ECX register serve?
Ans: Special purpose of the ECX register: ECX is commonly used as a counter in loop
operations and for string operations (such as in the REP prefix).

2.3: “Section review”


1. Describe SRAM and its most common use.
Ans: SRAM (Static Random Access Memory): SRAM is a type of volatile memory that retains
data as long as power is supplied. It is faster and more reliable than DRAM but is more
expensive and consumes more power. Its most common use is in cache memory for processors.
2. Describe VRAM.
Ans: VRAM (Video Random Access Memory): VRAM is a type of memory used specifically
for storing video and image data. It allows for faster processing of graphics and is commonly
used in graphics cards for rendering high-resolution images and videos.
3. List at least two features found in the Intel P965 Express chipset.
Ans: Two features of the Intel P965 Express chipset:
 Supports Intel Core 2 Duo and Core 2 Quad processors.
 Features DDR2 and DDR3 memory support.
4.Name four types of RAM mentioned in this chapter.
Ans: Four types of RAM mentioned:
 DRAM (Dynamic RAM)
 SRAM (Static RAM)
 SDRAM (Synchronous DRAM)
 VRAM (Video RAM)
5. What is the purpose of the 8259A PIC controller?
Ans: Purpose of the 8259A PIC controller:
 The 8259A Programmable Interrupt Controller (PIC) manages interrupt requests (IRQs)
from various hardware devices and ensures they are processed by the CPU in an orderly
manner.

2.4: “Section review”


1. Of the four levels of input/output in a computer system, which is the most universal and
portable?
Ans: Most universal and portable level of I/O:
 High-level I/O (often referred to as user-level I/O) is the most universal and portable
because it is implemented through software interfaces that can be used across different
hardware platforms without requiring hardware-specific adjustments.
2. What characteristics distinguish BIOS-level input/output?
Ans: Characteristics that distinguish BIOS-level I/O:
 BIOS-level I/O provides basic, low-level interaction with the hardware. It operates before
the operating system is loaded and is responsible for essential tasks such as detecting and
initializing hardware components (e.g., hard drives, keyboards). It typically uses direct
hardware access and is specific to the system’s firmware.
3. Why are device drivers necessary, given that the BIOS already has code that
communicates with the computer’s hardware?
Ans: Necessity of device drivers:
 Device drivers are necessary because the BIOS provides only basic, hardware-agnostic
functionality. Device drivers offer specialized instructions that enable the operating
system to communicate with specific hardware devices in a way that supports advanced
features and ensures compatibility with modern software and hardware configurations.
4. In the example regarding displaying a string of characters, which level exists between the
operating system and the video controller card?
Ans: Level between the operating system and the video controller card:
 Device drivers exist between the operating system and the video controller card. These
drivers facilitate communication by translating OS-level commands into instructions the
video controller can understand.
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: BIOS differences between MS-Windows and Linux systems:
 No, the BIOS is not typically different based on the operating system (MS-Windows or
Linux). The BIOS is a firmware layer that interacts with the hardware directly and
operates independently of the OS. However, the way the operating system interacts with
the BIOS (through boot loaders or initialization routines) may vary, but the BIOS itself
remains the same.

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.

3.2: “Section review”


1. In the AddTwo program, what is the meaning of the INCLUDE directive?
Ans: The INCLUDE directive is used to insert the contents of another file into the current
assembly source code. This is typically used to include libraries or predefined macros that
provide additional functionality or constants needed by the program.
2. In the AddTwo program, what does the .CODE directive identify?
Ans: The .CODE directive identifies the section of the assembly program where the executable
code (instructions) will be written. It tells the assembler to begin the code segment of the
program.
3. What are the names of the two segments in the AddTwo program?
Ans: The two segments in the AddTwo program are typically:
 .DATA (used for data declaration, where variables are stored)
 .CODE (used for the program's executable instructions)
4. In the AddTwo program, which register holds the sum?
Ans: The sum is typically stored in the AX register (for 16-bit operations) or EAX register (for
32-bit operations).
5. In the AddTwo program, which statement halts the program?
Ans: The statement that halts the program is usually INT 20h, which is an interrupt used to
terminate the program in MS-DOS-based environments.

3.3: “Section review”


1. What types of files are produced by the assembler?
Ans: Types of files produced by the assembler:
 Object files (.obj or .o).
2. (True/False): The linker extracts assembled procedures from the link library and inserts
them in the executable program.
Ans: True.
3. (True/False): When a program’s source code is modified, it must be assembled and
linked again before it can be executed with the changes.
Ans: True.
4. Which operating system component reads and executes programs?
Ans: The loader.
5. What types of files are produced by the linker?
Ans: Executable files (.exe or .out), and sometimes dynamic link library files (.dll or .so).

3.4: “Section review”


1. Create an uninitialized data declaration for a 16-bit signed integer.
Ans: myInt SWORD ?
SWORD specifies a 16-bit signed word, and ? indicates it is uninitialized.
2. Create an uninitialized data declaration for an 8-bit unsigned integer.
Ans: myByte BYTE ?
BYTE specifies an 8-bit unsigned integer, and ? indicates it is uninitialized.
3. Create an uninitialized data declaration for an 8-bit signed integer.
Ans: mySignedByte SBYTE ?
SBYTE specifies an 8-bit signed integer, and ? indicates it is uninitialized.
4. Create an uninitialized data declaration for a 64-bit integer.
Ans: myLongInt QWORD ?
QWORD specifies a 64-bit integer, and ? indicates it is uninitialized.
5. Which data type can hold a 32-bit signed integer?
Ans: SDWORD (signed double word) can hold a 32-bit signed integer.

3.5: “Section review”


1. Declare a symbolic constant using the equal-sign directive that contains the ASCII code
(08h) for the Backspace key.
Ans: Backspace EQU 08h
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.
Ans: SecondsInDay EQU 24 * 60 * 60
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:
myArray WORD 20 DUP(?)
Ans: ArraySize EQU $ - OFFSET myArray
(Here, $ refers to the current address, and OFFSET myArray gives the starting address of the
array. The difference between these values gives the total size of the array in bytes.)
4. Show how to calculate the number of elements in the following array, and assign the
value to a symbolic constant named ArraySize:
myArray DWORD 30 DUP(?)
Ans: ArraySize EQU SIZEOF myArray / TYPE myArray
(SIZEOF calculates the total size of the array, and TYPE gives the size of each element, in this
case, a DWORD (4 bytes).)
5. Use a TEXTEQU expression to redefine “proc” as “procedure.”
Ans: proc TEXTEQU "procedure"
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.
Ans: Sample TEXTEQU "This is a sample string"
MyString DB Sample
7. Use TEXTEQU to assign the symbol SetupESI to the following line of code: mov
esi,OFFSET myArray
Ans: SetupESI TEXTEQU "mov esi, OFFSET myArray"
You can then use SetupESI in your code, like so:
SetupESI

You might also like