Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

MPL Oral Question Bank Solution

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Here are the solutions to the questions you provided:

1. What is an assembler?
- An assembler is a program that translates assembly language code into machine code
or object code. It converts mnemonic instructions and symbols into binary code that can
be understood and executed by the computer's processor.

2. What is NASM?
- NASM (Netwide Assembler) is a popular assembler used for x86 and x86-64
architectures. It is known for its simplicity and portability and is widely used in the
development of low-level software, operating systems, and embedded systems.

3. What is a 64-bit system call?


- A 64-bit system call is a mechanism provided by the operating system for applications
to request services or resources from the kernel in a 64-bit environment. It allows
programs running in 64-bit mode to interact with the underlying operating system for
various operations such as file I/O, memory management, process management, etc.

4. What are the 64-bit general-purpose registers?


- In x86-64 architecture, the 64-bit general-purpose registers are:
- RAX, RBX, RCX, RDX: Used for general-purpose operations, arithmetic, and data
movement.
- RSI, RDI, RBP, RSP: Used for data manipulation and memory access.
- R8-R15: Additional general-purpose registers for extended functionality.

5. What is the segment register 80386?


- In the 80386 processor, the segment registers are CS (Code Segment), DS (Data
Segment), SS (Stack Segment), ES (Extra Segment), FS (Extra Segment), and GS (Extra
Segment). These registers hold segment selectors that determine the base address of
memory segments used for different purposes.

6. What is the size of the segment register 80386?


- Each segment register in the 80386 is 16 bits in size.

7. Do you know any other assembler?


- Yes, there are several assemblers available for different architectures and platforms.
Some popular ones include GAS (GNU Assembler), TASM (Turbo Assembler), MASM
(Microsoft Macro Assembler), and FASM (Flat Assembler).

8. Explain the algorithm of assignment no ...?


- The algorithm for a specific assignment would depend on the requirements and the
task at hand. It would involve a step-by-step procedure to solve the problem or
implement the desired functionality. Please provide more details about the specific
assignment for a more detailed explanation.

9. Difference between .data and .bss section.


- In assembly language programming, the .data section is used to declare and initialize
global or static variables that occupy space in memory. The values of variables in the
.data section are stored in the executable file.
- The .bss section, on the other hand, is used to declare uninitialized global or static
variables. The variables in the .bss section do not occupy space in the executable file but
are allocated memory at runtime.

10. What is the read and write 64-bit system call?


- The read and write system calls are used for input and output operations in the
context of file handling. The read system call reads data from a file into a buffer, and the
write system call writes data from a buffer to a file. The 64-bit system call variant is
specifically used in a 64-bit environment.

11. Does the read system call return anything?


- Yes, the read system call returns the number of bytes read from the file or input
stream. If the read operation is successful, it returns a positive integer representing the
number of bytes read. If an error occurs, it returns a negative value.

12. How to define an 8-bit/16-bit/ 32-bit/64-bit hexadecimal number?


- An 8-bit hexadecimal number can be defined by prefixing it with '0x' or '0X' (e.g.,
0x2F).
- Similarly, a 16-bit number can be defined using two bytes in hexadecimal
representation.
- For 32-bit and 64-bit numbers, additional bytes are used accordingly.

13. How to declare an 8-bit/16-bit/32-bit/64-bit hexadecimal number in which section?


- Hexadecimal numbers can be declared in the code section or data section of an
assembly program, depending on the purpose and usage of the number.

14. BSS stands for? (Ans: Block Stack Symbol)


- The correct expansion of BSS in the context of assembly programming is "Block
Started by Symbol." It is a section in assembly programs where uninitialized variables are
declared.

15. How to represent a hexadecimal negative number?


- In most assembly languages, negative numbers are represented using two's
complement notation. To represent a negative hexadecimal number, the two's
complement of the positive equivalent is taken.
16. What is the significance of the RAX register in system calls (likewise for RDX, RSI,
RDI)?
- In x86 and x86-64 assembly, RAX (EAX in 32-bit) register is used to store the return
value of a system call. RDX is commonly used for holding the count or size, RSI for
source data address, and RDI for destination data address during system call arguments
and data transfer.

17. Define instructions, define directive.


- Instructions: In assembly programming, instructions are the commands that direct the
processor to perform specific operations. These operations can include arithmetic, logic,
control flow, memory access, etc.
- Define directive: The define directive is used to assign values to symbols or define
constants in assembly programs. It allows you to give names to specific values or
memory locations, making the code more readable and maintainable.

18. What are the control transfer instructions?


- Control transfer instructions are used to alter the flow of execution in a program.
They include unconditional jumps (e.g., JMP) and conditional jumps (e.g., JNZ, JZ, JG,
JL) that allow branching to different parts of the code based on certain conditions.

19. What is the type of JUMP instruction?


- The JUMP instruction is a type of control transfer instruction used for unconditional
branching. It transfers program control to a specified memory location or label without
any condition.

20. Tell the difference between conditional JMP and unconditional JMP.
- Conditional JMP instructions perform a jump to a specified memory location or label
only if a certain condition is satisfied (e.g., JZ - jump if zero, JG - jump if greater).
- Unconditional JMP instructions always perform a jump to a specified memory
location or label without any condition.

21. Difference between signed conditional and unsigned conditional JMP:


- Signed conditional JMP instructions perform a jump based on the sign (positive or
negative) of a value. For example, JG (Jump if Greater) checks if the result of a previous
operation is greater than zero, considering it as a signed value.
- Unsigned conditional JMP instructions perform a jump based on the result of a
previous operation, considering it as an unsigned value. For example, JA (Jump if Above)
checks if the result of a previous operation is strictly greater than zero, treating it as an
unsigned value.

22. Enlist signed conditional JMP:


- Some signed conditional JMP instructions include:
- JG: Jump if Greater
- JL: Jump if Less
- JGE: Jump if Greater or Equal
- JLE: Jump if Less or Equal

23. Enlist unsigned conditional JMP:


- Some unsigned conditional JMP instructions include:
- JA: Jump if Above
- JB: Jump if Below
- JAE: Jump if Above or Equal
- JBE: Jump if Below or Equal

24. What is DB/DD/DW/DQ?


- DB: DB stands for Define Byte. It is a directive used to allocate memory for storing
bytes and initializes them with specified values.
- DD: DD stands for Define Doubleword. It is a directive used to allocate memory for
storing doublewords (32 bits) and initializes them with specified values.
- DW: DW stands for Define Word. It is a directive used to allocate memory for storing
words (16 bits) and initializes them with specified values.
- DQ: DQ stands for Define Quadword. It is a directive used to allocate memory for
storing quadwords (64 bits) and initializes them with specified values.

25. Difference between DB and RESB:


- DB is a directive used to allocate memory for storing bytes and initializes them with
specified values. It also reserves space in the executable file for the initialized data.
- RESB is a directive used to reserve a specified number of bytes in memory without
initializing them. It does not allocate space in the executable file but allocates memory at
runtime.

26. What is the significance of '$' in NASM:


- In NASM, the '$' symbol represents the current address or offset within the assembly
program. It is often used to refer to the current location for calculating relative addresses
or for self-referencing purposes.

27. Explain instructions used in your program? Explain any instruction (learn all
instructions):
- It is not clear what specific instructions you want an explanation for. Assembly
language instructions encompass a wide range of operations, such as arithmetic (ADD,
SUB, MUL, DIV), logical (AND, OR, XOR, NOT), data movement (MOV, PUSH,
POP), control flow (JMP, CALL, RET), and many more. If you specify a particular
instruction, I can provide an explanation.
28. Define addressing modes:
- Addressing modes determine how the operands of an instruction are accessed or
addressed in memory. They specify the location or addressing method for the source or
destination data of an instruction. Common addressing modes include immediate,
register, memory direct, memory indirect, indexed, and more.

29. What are the types of addressing modes?


- Some common types of addressing modes are:
- Immediate addressing: The operand value is specified directly in the instruction
itself.
- Register addressing: The operand value is stored in a register.
- Memory direct addressing: The operand value is stored at a specific memory
location.
- Memory indirect addressing: The operand value is stored at a memory location
specified by a register or memory location.
- Indexed addressing: The operand value is accessed

using a combination of a register and an offset value.

30. Explain -------- addressing mode with a suitable example:


- You left the question incomplete. Please provide the specific addressing mode you
want an explanation for, and I'll be happy to provide an example and explanation.

31. Identify the addressing mode used in the -------- instruction:


- To provide an answer, please specify the instruction for which you would like to
identify the addressing mode.

32. What are the directives used in your program? Explain any directives (learn all
directives):
- It is not clear which specific directives you want an explanation for. Directives in
assembly language provide instructions to the assembler or linker for various purposes
such as defining symbols, reserving memory, including libraries, and more. Some
common directives include ORG, DB, DW, DD, RESB, SECTION, GLOBAL,
EXTERN, and many others. If you specify a particular directive, I can provide an
explanation.

33. What are the steps to execute an assembly language program on NASM?
- The steps to execute an assembly language program on NASM typically include:
1. Install NASM on your system.
2. Write your assembly code using a text editor and save it with a .asm extension.
3. Open the terminal or command prompt and navigate to the directory where your
assembly file is located.
4. Assemble the code using the NASM assembler by running the command: `nasm -f
<output-format> <input-file.asm> -o <output-file>`.
5. Link the assembled object file using a linker like ld by running the command: `ld
<input-file.o> -o <output-file>`.
6. Execute the compiled program by running the command: `./<output-file>` (on
Unix-based systems) or `<output-file>` (on Windows systems).

34. What is the Global and Extern directive?


- The Global directive is used to declare a symbol or label as globally accessible or
visible to other modules or files. It allows the symbol to be referenced from other
modules during linking.
- The Extern directive is used to declare a symbol or label that is defined in another
module or file. It informs the assembler that the symbol will be resolved during the
linking process and does not need to be defined in the current module.

35. What are the string instructions and how do they work?
- String instructions in assembly language are a set of instructions specifically designed
for manipulating strings of characters or bytes. They provide functionality such as
copying, comparing, searching, and manipulating strings. Examples of string instructions
include MOVSB (move byte from the source to the destination), CMPSB (compare byte
from the source with the byte at the destination), SCASB (scan byte in the string with the
byte in AL), and many more.

36. What are the bit-related instructions?


- Bit-related instructions in assembly language are instructions that operate on
individual bits within a byte or register. They include instructions for setting, clearing,
testing, and manipulating specific bits. Examples of bit-related instructions include AND,
OR, XOR, TEST, SET, and CLEAR instructions.

37. Which flags get affected after the -------- instruction?


- To provide an answer, please specify the instruction for which you would like to know
the affected flags.

38. What is a procedure? How to define and call a procedure?


- A procedure is a named block of code that performs a specific task or operation. It
allows code reuse and modular programming. In assembly language, a procedure is
defined using labels and can be called from other parts of the program. To define a
procedure, you specify a label followed by the procedure code. To call a procedure, you
use the CALL instruction followed by the label of the procedure.

39. What is a macro? How to define and call a macro?


- A macro is a sequence of instructions or statements that is defined once and can be
used multiple times throughout the program. It allows code reuse
and simplifies repetitive tasks. Macros are defined using the MACRO directive, followed
by the macro code, and ended with the ENDM directive. To call a macro, you simply use
its name followed by any required parameters.

40. What is an interrupt? Define interrupt.


- An interrupt is a signal generated by a device or software that interrupts the normal
flow of a program's execution. It is used to handle events or perform time-critical tasks.
When an interrupt occurs, the processor suspends its current execution, saves the current
state, and transfers control to a predefined interrupt handler routine. The interrupt handler
handles the interrupt and resumes the execution of the program.

41. How to handle an interrupt?


- Handling interrupts involves defining interrupt handler routines and setting up
interrupt vectors. The steps to handle an interrupt vary depending on the specific interrupt
and the platform you are working with. In general, you need to:
- Identify the interrupt source and its associated interrupt number or vector.
- Write an interrupt handler routine to handle the interrupt.
- Set up the interrupt vector table to point to the interrupt handler routine.
- Enable interrupts and establish the necessary interrupt handling mechanisms in your
program.

42. What are the different ways to write ADD instructions (using different addressing
modes)?
- The ADD instruction can be written using various addressing modes, including:
- Immediate addressing: ADD reg, immediate
- Register addressing: ADD reg1, reg2
- Memory direct addressing: ADD reg, [mem]
- Memory indirect addressing: ADD reg, [reg]
- Indexed addressing: ADD reg, [reg + offset]
43. Differentiate between a procedure and a macro.
- Procedures and macros serve different purposes in assembly language:
- Procedure: A procedure is a named block of code that performs a specific task or
operation. It is defined once and can be called multiple times from different parts of the
program. Procedures promote code reusability and modular programming.
- Macro: A macro is a sequence of instructions or statements that is defined once and
can be expanded or instantiated multiple times throughout the program. Macros allow
code reuse and simplification of repetitive tasks.

44. Differentiate between a procedure and an interrupt.


- Procedures and interrupts have different purposes and mechanisms in assembly
language:
- Procedure: A procedure is a named block of code that performs a specific task or
operation. It is called explicitly from different parts of the program and returns control
back to the calling code after execution. Procedures are part of the normal program flow.
- Interrupt: An interrupt is a signal generated by a device or software that interrupts
the normal flow of a program's execution. When an interrupt occurs, the processor
suspends its current execution and transfers control to a predefined interrupt handler
routine. Interrupts are used to handle events or perform time-critical tasks.

45. How to call an interrupt?


- To call an interrupt in assembly language, you typically use the INT instruction
followed by the interrupt number. For example, to call interrupt 0x21 (DOS service
interrupt) in x86 assembly, you would write: INT 0x21.

46. What do you mean by a maskable interrupt?


- A maskable interrupt is an interrupt that can be selectively enabled or disabled by the
program. The program can control whether the interrupt is allowed to interrupt the
normal execution of the program or if it should be ignored. Maskable interrupts provide a
mechanism for prioritizing and handling different types of interrupts based on the
program's requirements.

47. What are the types of procedures?


- There are different types of procedures in assembly language, including:
- Near Procedure: A near procedure is a procedure that resides within the same code
segment as the calling code. It is used for

local or short-distance subroutine calls.


- Far Procedure: A far procedure is a procedure that resides in a different code
segment than the calling code. It is used for calling procedures in other code segments.

48. Differentiate between Far and Near Procedure.


- Far Procedure:
- Resides in a different code segment than the calling code.
- Requires segment and offset addresses to access the procedure.
- Used for calling procedures in other code segments.
- Useful for inter-segment calls and large programs with multiple code segments.

- Near Procedure:
- Resides within the same code segment as the calling code.
- Can be called directly using a simple label.
- Used for local or short-distance subroutine calls.
- Suitable for small programs or code within the same segment.

49. Can we use a loop inside a macro?


- Yes, loops can be used inside macros. Macros can contain any valid assembly
language instructions, including loop instructions such as LOOP, LOOPNZ, LOOPZ, etc.
The use of loops inside macros allows for repetitive tasks or iterations to be handled
conveniently.

50. How to iterate a block of code in assembly?


- In assembly language, code iteration can be achieved using loop instructions. The
LOOP instruction is commonly used to iterate a block of code a specific number of times.
The loop counter is typically decremented with each iteration, and the loop continues
until the counter reaches zero.

51. How to convert HEX to ASCII (byte/word)?


- To convert a hexadecimal value to ASCII representation, you can use the appropriate
instructions to convert each nibble (half-byte) to its ASCII character equivalent. The
conversion depends on whether you want to convert a byte or a word (2 bytes).
- Byte Conversion: To convert a hexadecimal byte to ASCII, you can extract the upper
and lower nibbles using logical AND and shift operations and then add the ASCII offset
value ('0' or 'A') to each nibble to get the corresponding ASCII characters.
- Word Conversion: To convert a hexadecimal word to ASCII, you can convert each
byte separately using the same process as for a byte conversion.

52. How to check if protection is enabled in the processor?


- The method to check if protection is enabled in the processor depends on the specific
protection mechanism you are referring to. In x86 processors, you can check if the
processor is running in protected mode or real mode by examining the value of the
control register CR0. The protection mechanism can be determined by checking the value
of specific bits in the control register.

53. What are the control registers?


- Control registers are special-purpose registers in the x86 architecture that control
various operating modes, system behavior, and processor features. The most commonly
used control registers are:
- CR0: Control Register 0, which controls the processor's operating mode, cache, and
other system settings.
- CR2: Control Register 2, which holds the address of the most recent page fault.
- CR3: Control Register 3, which contains the physical base address of the page
directory.
- CR4: Control Register 4, which controls various system and processor features, such
as virtualization, debugging, and more.

54. Define the Machine Status Word (MSW).


- The Machine Status Word (MSW) is a control register (CR0) in the x86 architecture
that stores various system and processor status flags. It contains control bits that
determine the operating mode, task switching, floating-point unit usage, and more.

55. How to read the value from the MSW (specify instruction)?
- To read the value from the MSW (Machine Status Word), you can use the MOV
instruction to move the value of the MSW

into a general-purpose register. For example: `MOV AX, CR0`.

56. What is the size of the MSW?


- The size of the MSW (Machine Status Word) is 32 bits in most x86 processors.

57. What is LDT, GDT, IDT?


- LDT: The Local Descriptor Table (LDT) is a data structure used in x86 processors to
store segment descriptors specific to a task or process. It is used in protected mode for
managing memory access and protection.
- GDT: The Global Descriptor Table (GDT) is a data structure used in x86 processors to
store segment descriptors for the entire system. It contains descriptors for code segments,
data segments, and system segments.
- IDT: The Interrupt Descriptor Table (IDT) is a data structure used in x86 processors to
store interrupt and exception handlers. It contains descriptors that specify the location and
attributes of the handlers for each interrupt or exception.

58. What is LDTR, GDTR, IDTR?


- LDTR: The Local Descriptor Table Register (LDTR) is a control register (CR0) in the
x86 architecture used to store the segment selector for the LDT (Local Descriptor Table).
- GDTR: The Global Descriptor Table Register (GDTR) is a control register (CR0) in
the x86 architecture used to store the base address and size of the GDT (Global
Descriptor Table).
- IDTR: The Interrupt Descriptor Table Register (IDTR) is a control register (CR0) in
the x86 architecture used to store the base address and size of the IDT (Interrupt
Descriptor Table).

59. What is the size of LDTR, GDTR, IDTR?


- The size of LDTR (Local Descriptor Table Register), GDTR (Global Descriptor Table
Register), and IDTR (Interrupt Descriptor Table Register) is 48 bits (6 bytes).

60. How to read the content of LDTR, GDTR, IDTR, TR, MSW?
- To read the content of LDTR, GDTR, IDTR, TR (Task Register), and MSW (Machine
Status Word), you can use the MOV instruction to move the value of the corresponding
control register into a general-purpose register. For example:
- LDTR: `MOV AX, LDTR`
- GDTR: `MOV AX, GDTR`
- IDTR: `MOV AX, IDTR`
- TR: `MOV AX, TR`
- MSW: `MOV AX, CR0`

61. What is the task register? What is its size?


- The Task Register (TR) is a control register (CR0) in the x86 architecture used to store
the segment selector for the TSS (Task State Segment). The TSS contains information
about the current task or process. The size of the Task Register is 16 bits (2 bytes).

62. How to do multitasking?


- Multitasking in assembly language involves switching between different tasks or
processes to give the illusion of concurrent execution. It requires the use of the Task State
Segment (TSS), task switches, and appropriate management of registers, stack, and other
resources. The specific method for multitasking depends on the operating system and the
hardware platform you are working with.

63. What is the TSS (Task State Segment)?


- The Task State Segment (TSS) is a data structure used in x86 processors to store
information about a task or process. It includes details such as the task's stack pointers,
registers, flags, and other context information needed for task switching and restoring the
state of a task.

64. Draw the flag register, control register, descriptor format

.
- Unfortunately, as a text-based AI, I cannot draw images or diagrams. However, I can
describe the formats briefly:
- Flag Register: The Flag Register (FLAGS) is a 16-bit register in the x86 architecture
that stores various status flags, such as carry, zero, sign, overflow, and others. The flags
can be modified by arithmetic and logical instructions.
- Control Register Format: The control registers (CR0, CR2, CR3, CR4) in the x86
architecture have a 32-bit format. They store control bits for various system and
processor settings.
- Descriptor Format: Segment descriptors in the x86 architecture have a specific
format. A descriptor consists of 8 bytes and includes fields for segment limit, base
address, access rights, and other attributes. The format of the descriptor varies depending
on whether it is a code segment, data segment, system segment, or gate descriptor.

65. What is recursion?


- Recursion is a programming technique in which a function calls itself during its
execution. It allows a function to solve a problem by breaking it down into smaller,
similar subproblems. Recursion involves a base case that terminates the recursive calls
and a recursive case that makes the function call itself with a modified input.

66. Where does the command line get stored?


- In assembly language, the command line arguments are typically stored on the stack.
The command line arguments are passed to a program when it is executed, and they are
pushed onto the stack in reverse order. The program can access the command line
arguments by referencing the stack pointer (SP) and accessing the argument values
relative to the stack pointer.

You might also like