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

Assembly Language Assignment 1

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)
24 views

Assembly Language Assignment 1

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

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.

2. How will studying assembly language enhance your understanding of operating


systems?

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.

3. What is meant by a one-to-many relationship when comparing a high-level language to


machine language?

Ans: A one-to-many relationship means a single high-level language statement can translate
into multiple machine code instructions.

4. Explain the concept of portability as it applies to programming languages.

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.

6. Give an example of an embedded systems application.


Ans: A smart thermostat is an example, where embedded systems manage hardware directly to
control temperature settings.

7. What is a device driver?

Ans: A device driver is software that allows the operating system to communicate and control
hardware devices like printers, keyboards, or graphics cards.

8. Do you suppose type checking on pointer variables is stronger (stricter) in assembly


language, or in C and C++?

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?

Ans: Assembly language is hard to maintain, error-prone, and platform-dependent, making


it unsuitable for large-scale applications compared to high-level languages.

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: Assuming X is in EAX and Y is in EBX

MOV EAX, [X] ; Load value of X into EAX


MOV EBX, [Y] ; Load value of Y into EBX

IMUL EBX, EBX, 4 ; Multiply Y by 4, result stored in EBX

ADD EAX, EBX ; Add the result of Y * 4 to X

1.2.1 Section Review

1: In your own words, describe the virtual machine concept.

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.

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

8: Why don’t programmers write applications in machine language?

Ans: Machine language is difficult to understand, error-prone, and time-consuming to write,


making it impractical for application development.

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.

1.3.9 Section Review

1. Explain the term least significant bit (LSB).

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?

Ans: a. 11111000 = 248


b. 11001010 = 202

c. 11110000 = 240

3. What is the sum of each pair of binary integers?

Ans: a. 00001111 + 00000010 = 00010001 (17 in decimal)

b. 11010101 + 00000000 = 11010101 (213 in decimal)

c. 00001111 + 01101011 = 01111010 (122 in decimal)

4. How many bytes are contained in each of the following data types?

Ans: a. Word = 2 bytes

b. Doubleword = 4 bytes

c. Quadword = 8 bytes

d. Double quadword = 16 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

6. What is the hexadecimal representation of each of the following binary numbers?

Ans: 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: 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.2 Section Review

1. Describe the following boolean expression: ¬X ∨ Y.

Ans: The expression ¬X ∨ Y means "NOT X OR Y". It is true if either X is false or Y is true (or
both).

2. Describe the following boolean expression: (X ∧ Y).

Ans: The expression (X ∧ Y) means "X AND Y". It is 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 = F ∨ T = T. Since T OR anything is true, the final value is T.

4. What is the value of the boolean expression ¬(F ∨ T)?

Ans: ¬(F ∨ T) = ¬T = F. Since F OR T is true, its negation is false.

5. What is the value of the boolean expression ¬F ∨ ¬T?

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

2.1.5 Section Review

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?

Ans: The three steps are fetch, decode, and execute.

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

2.2.4 Section Review

1. What are the x86 processor’s three basic modes of operation?

Ans: The three basic modes of operation are Real Mode, Protected Mode, and Long Mode.

2. Name all eight 32-bit general-purpose registers.

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.

4. What special purpose does the ECX register serve?

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.

2.4.3 Section Review

1. Describe SRAM and its most common use.

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.

4. Name four types of RAM mentioned in this chapter.

Ans: Four types of RAM mentioned are SRAM, DRAM, SDRAM, and VRAM.

5. What is the purpose of the 8259A PIC controller?

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.

Ans: Decimal: -35

Hexadecimal: -23h

Octal: -43o

Binary: -100011

2. (Yes/No): Is A5h a valid hexadecimal literal?

Ans: Yes, A5h is a valid hexadecimal literal in MASM.

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

 Calculation: (5 + 3) = 8, 8 * 4 = 32, 32 / 2 = 16, 16 - 1 = 15

 Value of the expression: 15

5. Write the real number –6.2 × 10^4 as a real number literal using MASM syntax.

Ans: -6.2e4

6. (Yes/No): Must string literals be enclosed in single quotes?

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

8. What is the maximum length of an identifier?

Ans: The maximum length of an identifier in MASM is 255 characters.

3.2.4 Section Review


1. In the AddTwo program, what is the meaning of the INCLUDE directive?

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.

2. In the AddTwo program, what does the .CODE directive identify?

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

4. In the AddTwo program, which register holds the sum?

Ans: In the AddTwo program, the AX register typically holds the sum after the addition.

5. In the AddTwo program, which statement halts the program?

Ans: The RET (return) or INT 20h statement halts the program in MASM assembly.

3.3.3 Section Review

1. What types of files are produced by the assembler?

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.

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, the modified source code must be reassembled and linked to create an updated
executable.

4. Which operating system component reads and executes programs?

Ans: The operating system's loader reads and executes programs by loading them into
memory.

5. What types of files are produced by the linker?

Ans: The linker produces executable files (with extensions like .exe or .out) and may also
produce static library files (like .lib or .a).

3.4.13 Section Review

1. Create an uninitialized data declaration for a 16-bit signed integer.

Ans: SWORD SDWORD ?


(In MASM, SWORD refers to a signed 16-bit integer and ? indicates it is uninitialized.)

2. Create an uninitialized data declaration for an 8-bit unsigned integer.

Ans: BYTE DB ?
(In MASM, DB is used for defining a byte, and ? indicates it is uninitialized.)

3. Create an uninitialized data declaration for an 8-bit signed integer.

Ans: SBYTE DB ?
(In MASM, SBYTE refers to a signed 8-bit integer.)

4. Create an uninitialized data declaration for a 64-bit integer.


Ans: QWORD DQ ?
(In MASM, QWORD represents a 64-bit integer and DQ is used for defining uninitialized data.)

5. Which data type can hold a 32-bit signed integer?

Ans: The SDWORD data type can hold a 32-bit signed integer in MASM.

3.5.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: SECONDSINSDAY 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:

Ans: ArraySize EQU $ - myArray

4. Show how to calculate the number of elements in the following array, and assign the
value to a symbolic constant named ArraySize:

Ans: ArraySize EQU $ / 4


(Since each DWORD is 4 bytes, dividing by 4 gives the number of elements.)

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 "Hello, world!"


MyString DB Sample
7. Use TEXTEQU to assign the symbol SetupESI to the following line of code:

Ans: SetupESI TEXTEQU "mov esi,OFFSET myArray"


(This can then be used as SetupESI in the code.)

You might also like