Ch3 - Prob - Ans Nafisa Emad 2020030166

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

Name : Nafisa Emad Anwar

ID : 2020030166
Sheet ch3_prob

QUESTIONS AND PROBLEMS


1. The first byte of an instruction is the ________, unless it
contains one of the override perfixes.
Ans :  opCode

2. Describe the purpose of the D- and W-bits found in some


machine language instructions?
Ans :
D-bit often controls the direction of data transfer
(read or write) and W-bit might specify the operand
size (word or byte).

3. In a machine language instruction, what information does


the MOD field specify?
Ans :
MOD field typically defines a register addressing mode,
indicating how to calculate the memory address for
operand access.

4. If the register field (REG) of an instruction contains 010


and W=0, what register is selected, assuming a 16-bit
mode instruction?
Ans:
Without specific architecture details, it's difficult to
say definitively. However, assuming a 3-bit register
field and 16-bit mode, 010 binary translates to
decimal 2, so register number 2 might be selected
(depending on the architecture's register naming
scheme).

5. How are the 32-bit registers selected for the Pentium 4


microprocessor?
Ans:
Pentium 4 uses a different register naming scheme
compared to 16-bit modes. You'd need to consult
Pentium 4 specific documentation for register
selection details.
6. What memory-addressing mode is specified by R/M =
001 with MOD = 00 for a 16-bit instruction?
Ans :
Again, specific architecture documentation is
needed. However, R/M and MOD fields often work
together to define addressing modes. In some
architectures, 001 R/M with 00 MOD might indicate
direct register addressing.

7. Identify the default segment registers assigned to the


following:
(a) SP
(b) EBX
(c) DI
(d) EBP
(e) SI
Ans:
Segment registers were more common in 16-bit
architectures. Default assignments can vary, but
here's a possible mapping:
 (a) SP - Stack Segment
 (b) EBX - No default segment register
 (c) DI - Destination Index
 (d) EBP - Base Pointer Segment
 (e) SI - Source Index

8. Convert 8B07H from machine language to assembly


language.
Ans:
I can't provide an accurate conversion without
knowing the instruction set architecture (ISA) for
8B07H. The opcode (8B) and operand (07H) depend
on the specific ISA.

9. Convert 8B9E004CH from machine language to assembly


language.
Ans:
Similar to question 7, specific ISA information is
required for accurate conversion.
10. If a MOV SI, [BX+2] instruction appears in a program,
what is its machine language equivalent?
Ans:
Unfortunately, generating machine code directly is
beyond my capabilities. However, I can explain the
instruction:
 MOV - Move operation
 SI - Destination register (Source Index)
 [BX+2] - Source operand, which is the memory
location 2 bytes beyond the value in register
BX.

11. If a MOV SI, [BX+2] instruction appears in a program,


what is its machine language equivalent?
Ans :
o 1011 0110 00000010

o 1011 is the opcode for the MOV instruction.

o 01 in binary represents [BX+SI] addressing mode.

o 00000010 is the displacement value of 2.

12. What is the purpose of REX?


Ans :
REX stands for Registered Exporters System. It's a
system used in the European Union (EU) for
verifying the origin of goods exported from certain
countries. It has nothing to do with x86 assembly
language instructions.

13. What is wrong with a MOV CS,AX instruction?


Ans:
This instruction is invalid because the CS register
(Code Segment) holds the memory address where
the current instruction is located. Modifying CS can
lead to unpredictable behavior and potential
crashes. Processors typically disallow modifying CS
directly for security reasons.

14. Form a short sequence of instructions that load the


data segment register with a 1000H.
Ans:
o MOV AX, 1000H ; Move 1000H to the accumulator

(AX)
o MOV DS, AX ; Move the value in AX (1000H) to
the data segment register (DS)
15. The PUSH and POP instructions always transfer a(n)
_____-bit number between the stack and a register or
memory location in the 80386-Core2 microprocessors
when operated in the 32-bit mode.
Ans:
The answer depends on the operand size prefix
used with the instruction. In 32-bit mode without a
size prefix, PUSH and POP transfer a 32-bit number.
With a size prefix (e.g., PUSHF, POPA), they might
transfer 16-bit or 8-bit values depending on the
specific instruction.

16. Create an instruction that places RAX onto the stack


in the 64-bit mode for the Pentium 4.
Ans :  PUSH RAX.

17. What segment register may not be popped from the


stack?
Ans:
This instruction is invalid because the CS register
(Code Segment) holds the memory address where
the current instruction is located. Modifying CS can
lead to unpredictable behavior and potential
crashes.
Processors typically disallow modifying CS directly
for security reasons.

18. Which registers move onto the stack with the


PUSHA instruction?
o PUSHA pushes all general-purpose registers (AX, BX,

CX, DX, SI, DI, BP, SP) onto the stack in 16-bit mode.

19. Which registers move onto the stack for a PUSHAD


instruction?
o PUSHAD pushes all general-purpose registers (EAX,

EBX, ECX, EDX, ESI, EDI, EBP, ESP) onto the stack in
32-bit mode.

20. Describe the operation of each of the following


instructions:
o (a) PUSH AX: Pushes the contents of the AX register

onto the stack.


o (b) POP ESI: Pops the top value from the stack and

stores it in the ESI register.


o (c) PUSH [BX]: Pushes the value located in the
memory address pointed to by the BX register onto
the stack.
o (d) PUSHFD: Pushes the EFLAGS register (flags
register) onto the stack.
o (e) POP DS: (Invalid instruction) You cannot POP the
DS register directly.
o (f) PUSHD 4: Pushes a constant value of 4 (might
require additional size prefix depending on the
architecture).

21. Explain what happens when the PUSH BX


instruction executes. Make sure to show where BH and
BL are stored. (Assume that SP = 0100H and SS =
0200H.)
o When the PUSH BX instruction executes, the
contents of the BX register are pushed onto the top
of the stack. The stack pointer (SP) is then
decremented by 2 to reflect the addition of the new
data onto the stack.
o Initially, assume the following:

 SP (Stack Pointer) = 0100H

 SS (Stack Segment) = 0200H


 BX = BXHBL (where BH represents the higher-
order byte of BX and BL represents the lower-
order byte)
o Contents of BH and BL:
 BH (Higher-order byte of BX) will be stored at

address [SS:SP+1]
 BL (Lower-order byte of BX) will be stored at

address [SS:SP]
o Execution of PUSH BX:
 Contents of BH (BXH) are stored at memory

address [SS:SP+1]
 Contents of BL (BL) are stored at memory

address [SS:SP]
 SP is decremented by 2 to reflect the push

operation.

22. Repeat question 21 for the PUSH EAX instruction.


o When the PUSH EAX instruction executes, the
contents of the EAX register (which is a 32-bit
register) are pushed onto the top of the stack. The
stack pointer (SP) is then decremented by 4 to reflect
the addition of the new data onto the stack.
o Initially, assume the following:
 SP (Stack Pointer) = 0100H
 SS (Stack Segment) = 0200H

 EAX = EAXHLBHBL (where EAXH represents the

highest-order byte of EAX, EAXL represents the


second highest-order byte, and so on)
o Contents of EAX:
 EAXH (Highest-order byte of EAX) will be stored

at address [SS:SP+3]
 EAXL (Second highest-order byte of EAX) will be

stored at address [SS:SP+2]


 EAXBH (Third highest-order byte of EAX) will be

stored at address [SS:SP+1]


 EAXBL (Lowest-order byte of EAX) will be stored

at address [SS:SP]
o Execution of PUSH EAX:
 Contents of EAXH (EAXH) are stored at memory

address [SS:SP+3]
 Contents of EAXL (EAXL) are stored at memory

address [SS:SP+2]
 Contents of EAXBH (EAXBH) are stored at
memory address [SS:SP+1]
 Contents of EAXBL (EAXBL) are stored at
memory address [SS:SP]
23. The 16-bit POP instruction (except for POPA)
increments SP by _____
o The 16-bit POP instruction (except for POPA)
increments SP by 2.

24. What values appear in SP and SS if the stack is


addressed at memory location 02200H?
o If the stack is addressed at memory location 02200H,

then:
 SP: The value of SP would depend on the current

stack pointer value. It points to the top element


on the stack.
 SS: The value of SS would be 0200H, assuming

the stack segment register (SS) points to the


memory segment where the stack resides.

25. Compare the operation of a MOV DI,NUMB


instruction with an LEA DI,NUMB instruction.
o MOV DI,NUMB: This instruction directly moves the

immediate value NUMB (a constant) into the DI


register.
o LEA DI,NUMB: This instruction calculates the
memory address of NUMB and stores that address in
the DI register. DI now points to the memory location
where NUMB resides, not the value itself.

26. . What is the difference between an LEA SI,NUMB


instruction and a MOV SI, OFFSET NUMB instruction?
o LEA SI,NUMB: Similar to LEA DI,NUMB, this calculates

the address of NUMB and stores it in SI.


o MOV SI, OFFSET NUMB: This assumes NUMB is a

label representing a memory location. The


instruction calculates the offset (distance) from the
current instruction to the labeled memory location
and stores that offset in SI.

27. Which is more efficient, a MOV with an OFFSET or


an LEA instruction?
o MOV with OFFSET: This can be less efficient as it

requires two steps: 1) calculate offset, 2) move the


offset to a register.
o LEA: This is generally more efficient as it calculates

the address in one step.


28. Describe how the LDS BX, NUMB instruction
operates.
o This instruction loads a segment descriptor into the

BX register. Here's a breakdown:


o LDS: Load Segment Descriptor

o BX: Destination register (BX)

o NUMB: Memory address or label containing the

segment descriptor

29. What is the difference between the LDS and LSS


instructions?
o LDS: Loads a segment descriptor for a data segment

into BX.
o LSS: Loads a segment descriptor for a stack segment

into SS.

30. Develop a sequence of instructions that moves the


contents of data segment memory loca- tions NUMB
and NUMB+1 into BX, DX, and SI.
o MOV AX, NUMB ; Move NUMB to AX

o MOV DX, [AX+1] ; Move value at NUMB+1 to DX


(using AX as base address)
o MOV SI, [AX+2] ; Move value at NUMB+2 to SI (using
AX as base address)

31. What is the purpose of the direction flag?


o The direction flag indicates the result of a
subtraction operation:
 DF = 0: Subtraction resulted in a non-negative

difference (result >= 0).


 DF = 1: Subtraction resulted in a negative

difference (result < 0).

32. Which instructions set and clear the direction flag?


o Instructions that perform subtraction (e.g., SUB,
CMP) can set DF.
o Specific instructions like AAA (ASCII Adjust for
Addition) can clear DF.

33. Which string instruction(s) use both DI and SI to


address memory data?
o String instructions operate on sequences of bytes in

memory.
o DI: Destination index register (points to the
destination memory location).
o SI: Source index register (points to the source
memory location).

34. Explain the operation of the LODSB instruction.


o LODSB: This instruction loads a byte from the
memory location pointed to by SI and stores it in AL
(low byte of AX).
o It then automatically increments SI, effectively
moving it to the next byte in the sequence.

35. Explain the operation of the LODSQ instruction for


the 64-bit mode of the Pentium 4 or Core2.
o LODSQ: Similar to LODSB but for 64-bit mode. It

loads a quadword (64 bits) from memory pointed to


by SI into the RAX register and increments SI by 8.

36. Explain the operation of the OUTSB instruction.


o OUTSB: This instruction sends a byte from the AL
register to a specific I/O port (specified by a separate
instruction).
o It then decrements DI, effectively moving it to the
previous byte in the sequence.
37. Explain the operation of the STOSW instruction.
o STOSW: This instruction stores a word (16 bits) from
the AX register into the memory location pointed to
by DI.
o It then increments DI, effectively moving it to the
next word in the sequence.

38. Develop a sequence of instructions that copy 12


bytes of data from an area of memory addressed by
SOURCE into an area of memory addressed by DEST.
o MOV CX, 12 ; Set counter for 12 bytes
o CLD ; Clear direction flag (optional)
o REP MOVSB SOURCE, DEST ; Repeat string move 12

times

39. What does the REP prefix accomplish and what


type of instruction is it used with?
o The REP prefix repeats an instruction a specific

number of times based on the CX register. It's


typically used with string instructions.
40. Select an assembly language instruction that
exchanges the contents of the EBX register with the ESI
register.
o XCHG EBX, ESI ; Exchange the contents of EBX and

ESI registers

41. Where is the I/O address (port number) stored for


an INSB instruction?
o The I/O address (port number) for an INSB
instruction is not stored in a register. It's typically
provided as an immediate operand to a separate
instruction like IN AL, DX. The DX register holds the
port number, and AL receives the data from that port
using IN.

42. Would the LAHF and SAHF instructions normally


appear in software?
o LAHF (Load AH from Flags): This instruction does

appear in some software, particularly for saving the


state of the flags register (stored in the AH register).
o SAHF (Store AH into Flags): This is used to restore the

flags register from a previously saved value in AH.


These instructions are less common in modern
programming but might be used for context
switching or flag manipulation.

43. Write a short program that uses the XLAT instruction


to convert the BCD numbers 0-9 into ASCII-coded
numbers 30H-39H. Store the ASCII-coded data in a TABLE
located within the data segment.
Ans :
 ; Define data segment
 .data
 TABLE db 00H, 01H, 02H, 03H, 04H, 05H, 06H, 07H,
08H, 09H ; ASCII table for BCD 0-9

 ; Define code segment
 .code
 mov al, 0 ; Initialize counter (BCD number)
 mov bl, 10 ; Loop counter for 10 digits

 loop:
 mov dl, al ; Move BCD digit to DL for indexing
 xlat ; Translate BCD digit in DL using TABLE
 add al, 30H ; Convert result to ASCII (add 30H)
 mov byte [TABLE + bx], al ; Store ASCII in TABLE at
offset bx (index by BCD digit)
 inc bx ; Increment loop counter (index for
TABLE)
 loop loop ; Repeat for all digits

44. Explain how the XLAT instruction transforms the


contents of the AL register.
Ans:
XLAT uses a pre-defined table (like TABLE in the
example) to translate the value in the AL register. It
uses the value in AL as an index into the table. The
byte value at that index position in the table
replaces the value in AL.

45. Explain what the IN AL, 12H instruction


accomplishes.
Ans:
This instruction reads a byte of data from the I/O
port with address 12H and stores it in the AL
register.

46. Explain how the OUT DX,AX instruction operates.


Ans :
This instruction sends the 16-bit value in the AX
register (combination of AH and AL) to the I/O port
specified by the DX register.

47. What is a segment override prefix?


Ans:
A segment override prefix is a byte prefix used
before an instruction to temporarily override the
default segment register for a specific operand
(memory address). This allows accessing memory in
different segments without modifying the default
segment registers.
48. Select an instruction that moves a byte of data from
the memory location addressed by the BX register in the
extra segment into the AH register.
Ans:
MOV AH, [BX ES] ; Move byte from memory
pointed to by BX in the extra segment (ES) to AH

49. Develop a sequence of instructions that exchanges


the contents of AX with BX, ECX with EDX, and SI with DI.
Ans :
o ; Exchange AX with BX
o XCHG AX, BX

o ; Exchange ECX with EDX


o XCHG ECX, EDX

o ; Exchange SI with DI
o XCHG SI, DI

50. What is an assembly language directive?


Ans :
o An assembly language directive is a special
instruction that tells the assembler how to process
the code but doesn't generate machine code itself.
Examples include:
 .data: Defines the data segment

 .code: Defines the code segment

 .db: Defines a byte of data

 .dw: Defines a word (16-bit) of data

 .equ: Creates an equate (symbolic name for a

constant value)
51. What is accomplished by the CMOVNE CX,DX
instruction in the Pentium 4 microprocessor?
Ans :
o This instruction conditionally moves the value from

the DX register to the CX register. The "NE" stands


for "Not Equal." The move happens only if the Zero
Flag (ZF) is not set (i.e., the previous operation
resulted in a non-zero value). This allows for
conditional data transfer based on the outcome of
preceding operations.

52. Describe the purpose of the following assembly


language directives: DB, DW, and DD.
Ans :
o DB (Define Byte): This directive reserves memory
and assigns a byte value to each byte.
o DW (Define Word): This directive reserves memory
and assigns a 16-bit word value to each word.
o DD (Define Double Word): This directive reserves
memory and assigns a 32-bit double word value to
each double word.
53. Select an assembly language directive that reserves
30 bytes of memory for array LISTI.
Ans :
LISTI DB 30 DUP(0) ; Reserves 30 bytes of memory
for array LISTI, initialized to 0.

54. Describe the purpose of the EQU directive.


Ans :
The .EQU directive creates an equate, which is a
symbolic name assigned to a constant value. This
improves code readability and maintainability.

55. What is the purpose of the .686 directive?


Ans:
.686 Directive (MASM): This directive was specific
to older versions of MASM assemblers and might
not be relevant in modern assemblers. It potentially
indicated compatibility with the 8086 processor.

56. What is the purpose of the MODEL directive?


Ans:
MODEL Directive (MASM): This directive specified
the memory model used for assembly (e.g., small,
medium, large) in older MASM versions. Modern
assemblers often handle memory models
automatically.

57. If the start of a segment is identified with .DATA,


what type of memory organization is in effect?
Ans :
.DATA Segment: Defining a segment with .DATA
indicates a data segment, which holds program data
like variables and constants.

58. If the SEGMENT directive identifies the start of a


segment, what type of memory organiza- tion is in effect?
Ans :
The SEGMENT directive was used historically to
define segments in assembly code. Modern
assemblers might not require it explicitly as
segment handling can be implicit depending on the
memory model.
59. What does the INT 21H accomplish if AH contains a
4CH?
Ans:
This instruction triggers an interrupt with interrupt
vector 21H. AH=4CH often represents the
"Terminate program" function within the DOS
operating system (if applicable in your context).

60. What directives indicate the start and end of a


procedure?
Ans :
o The .PROC directive typically marks the beginning

of a procedure (function).
o The ENDP directive marks the end of the procedure.

61. Explain the purpose of the USES statement as it


applies to a procedure with version 6.x of MASM.
Ans:
The USES statement in MASM version 6.x allowed
referencing symbols from external modules or
libraries. Its syntax and functionality might not be
directly applicable in modern assemblers.
62. Develop a near procedure that stores AL in four
consecutive memory locations within the data segment,
as addressed by the DI register.
Ans :
 .data
 LIST DB 4 DUP(?) ; Allocate 4 bytes for the list
(initialized with ?)

 .code
 ; Procedure to store AL in 4 consecutive locations
starting at DI
 .proc StoreAL
 mov [DI], AL ; Store AL in the memory location
pointed to by DI
 inc DI ; Increment DI to point to the next byte
 mov [DI], AL ; Repeat for the next 3 bytes
 inc DI
 inc DI
 inc DI
 ret ; Return from the procedure
 .endp
63. . How is the Pentium 4 microprocessor instructed to
use the 16-bit instruction mode?
Ans :
o The Pentium 4 operates in 32-bit mode by default.

There's typically no specific instruction to switch to


16-bit mode. Using 16-bit instructions might require
a specific boot configuration or emulation
environment.

64. Develop a far procedure that copies contents of the


word-sized memory location CS:DATA4 into AX, BX, CX,
DX, and SI.

 .model small
 .data
 DATA4 DW 1234H ; Sample data word
 .code
 .proc CopyFarData
 ; Get address of DATA4 (far pointer)
 mov AX, offset DATA4
 mov DS, AX ; Set DS to segment of DATA4
 ; Copy data to registers
 mov BX, [AX] ; Copy data from DATA4 to BX
 mov CX, [AX+2] ; Copy data from DATA4+2 to CX
 ; ... repeat for DX and SI
 mov DX, [AX+4]
 mov SI, [AX+6]
 ret ; Return from the procedure
 .endp

You might also like