Computer Architecture and Assembly Language Programming
Provided by Sarim
Q1) Define LOADS
A load store architecture is an instruction set architecture that divides instructions
into two categories
Memory access (load and store between memory and registers) and ALU operations
(which only occur between registers).
3) Explain the purpose of using LDS instructio
There are two special instructions that load a segment register and a general-purpose
register from two consecutive memory locations.
in a program.
LES loads ES while LDS loads DS.
Both these instructions have two parameters, one is the general-purpose register to be
loaded and the other is the memory location from which to load these registers.
Q4) Write the name of four registers used in iAPX88 that can hold the address of
the data.
Name of four registers used in iAPX88 that can hold the address of the data.
BX, BP, SI, DI
Q5) Differences Between Near and Short Jump.
A short JMP is the relative JMP that you refer to. Itis encoded as two bytes; the actual
JMP and the number of bytes +/- relative to the current IP.A near jump allows you to jump within the current “segment” (using real mode terms) or
within the currently selected memory area in the CS selector.
Q6) Write an assembly language program for multiplication of two 4 bit numbers.
Answer:
[org 0x10]
va=b
mov eax, [num]
mov ebx, [num2]
vasatb
add eax, ebx
mov eax,0x4c00
int 0x21
Q7) Find Effective Address in Code.
Effective address
Base address of CS register X 104 + Address of IP
8) In ‘Graphics Pixel’ define the representation of BH, AL, CX and DX registers.
In graphics programming, BH, AL, CX, and DX registers may represent various
parameters such as color components, coordinates, or dimensions
For example, BH might represent the blue component of a pixel color, AL could be used
for storing individual pixel values, and CX and DX might hold coordinates for drawing
operations.
Q9) Name of registers for service number and file attributes, used in
Create/Truncate file using INT 21.INT 21h (DOS Interrupt), the registers AH and AL are used for service numbers and file
attributes, respectively, when performing file operations such as creating or truncating
files,
Q8) Write the code to hook INT 4 of the processor by changing its vector with the
address of a new routine “inthook”
Note: you are just required to write the code for interrupt hooking. No further
details are required.
Answer:
[org 0x10]
Mov ax,0
Mov ex, ax;
Mov word{es:0], myisr
Mov [es:2], cs
Mov ax, 1000
Mov bl, 2
Div bl
mov ax 0x4c00
Int 0x21
Q8) Define Topics Jumps, Flags Registers.
Answer:
Flags
The FLAGS register is the status register that contains the current state of a CPU. The
size and meanings of the flag bits are architecture dependent.
JumpsThe jump instruction transfers the program sequence to the memory address given in
the operand based on the specified flag.
Q10) Show illustration Ret or Call.
The CALL instruction interrupts the flow of a program by passing control to an internal
or external subroutine,
The RETURN instruction returns control from a subroutine back to the calling program
and optionally returns a value
Q11) Write ASCII Code, A ascii code is 65 find the a ASCII code?
ais 91
Q12) Write alternative instructions for CF, JBZ with character.
For CI
JC= Jump if carry
JB= Jump if below
INA‘
Jump if not above or equal
Q13) Write a program square of 3 accumulator terminates 2 times.
Answer:
[org 00100]
mov bx,3
mov cx,3
mov ax,0mov ax, 0x4c00
int 0x21
total: dw 0
Q14) Find background and foreground color attributes and their physical
address.
Answer:
Attributes for background and foreground color attributes byte RGB is
Foreground use 16 colors
Background use 8 colors
Q15) Difference between shift logical right and shift arithmetic right?
Shift Arithmeti
ht
A signed number holds the sign in its most significant bit. If this bit was
one a logical right shifting will change the sign of this number because of
insertion of a zero from the left.
‘Shift Logical Right
The shift logical right operation inserts a zero from the left and moves
every bit one position to the right and copies the rightmost bit in the carry
flag.
Q16) How MOVS instruction works?
The mov instruction copies the data item referred to by its second operand (i.e.
register contents, memory contents, or a constant value) into the location referred to byits first operand (Je. a register or memory). While register-to-register moves are
possible, direct memory-to-memory moves are not.
Q17) MOV [AX+BC+30]
Find which physical strategy use
The mode of addressing is known as register indirect mode. In this addressing mode,
the offset address of data is in either BX or SI or DI Register. The default segment is
either DS or ES. Example: MOV AX, [BX].
Q18) Purpose of "define byte”
The purpose of “define byte” in assembly language is to allocate memory for a byte-
sized variable or data item
Q19) Effective address
Effective address refers to the memory address that is calculated and used to access
data or operands in an instruction, taking into account any addressing modes or
displacement
Q20) Physical address
Physical address is the actual memory address in the physical memory hardware where
data is stored or retrieved
Q21) XOR and AND gateXOR and AND gates are fundamental logic gates used in digital electronics. XOR gate
performs exclusive OR operation while AND gate performs logical AND operation
22) What are the 3 illegal addressing modes
The three illegal addressing modes in assembly language depend on the architecture,
but commonly include addressing modes that are not supported or not allowed by the
processor, such as immediate addressing, indexed addressing without an index
register, and absolute addressing without a base address
23) Write instruction for A on blue background and write code to set es for
video memory
Answer:
MOV AH, 09h —_; Function to display string
MOVAL, 41h; ASCII code for ‘A’
MOV BL, 01h __; Video attribute for blue background
MOV BH, 00h ——_; Page number (0 for default)
MOV CX,01h ——_ ; Number of characters to display (1)
MOV DX, 0007h _; Video page and attribute (blue background)
INT 10h ; Call BIOS interrupt to display character with attribute
MOV AX, OB800h _; Start address of video memory (color text mode)
MOV ES, AX ; Set ES to point to video memory segment
Q24) What is purpose of Instructions Pointer Register?
The purpose of the Instruction Pointer (IP) register is to store the address of the next
instruction to be executed in the program sequenceQ25) SS:SP
Answer:
‘SS:SP measure the size of the stack segment and the stack pointer within it, indicating
the current top of the stack
Q25) Data bus control bus aur address bus thy sath memory aur processor to
hmy directions batni thi
Data bus carries data between the processor and memory or peripherals, the address
bus specifies the memory location or I/O port being accessed, and the control bus
carries control signals to coordinate data transfer between the processor and memory
or iO devices
26) Difference between shift logical right and shift arithmetic right?
The main difference between shift logical right and shift arithmetic right is that in shift
logical right, zeros are shifted into the vacant bit positions from the left, whereas in shift
arithmetic right, the sign bit (MSB) is replicated to fill the vacant bit positions from the
left.
Q27) How MOVS instructions works?
The MOVS instruction in assembly language is used to move a block of data from one
location to another. It works by copying the data from the source memory location to the
destination memory location, typically used for moving strings or arrays of data.
28) Instruction MOV [AX+BX+30] iska btana tha k is m konsa physical design ya
strategy use hogi?
The instruction MOV [AX+BX+30] indicates a memory access operation where the
physical addressing mode is usedThe processor calculates the physical memory address by adding the contents of AX,
BX, and the immediate value 30, and then retrieves or stores the data at that memory
location.
Q29) Multiplication of 2 4 bits number
Program for multiplication of two 4-bit numbers involves using iterative addition or
bitwise shifting to perform the multiplication operation.
30) Background and foreground colors k attributes
Answer:
MOV AH, 09h —_; Function to display string
MOV AL, ‘A’ ; ASCII code for 'A’
MOV BL,1Eh —_; Attribute byte for blue background and white foreground
MOV BH, 00h ——_; Page number (0 for default)
MOV CX, 01h —_ ; Number of characters to display (1)
MOV DX, 0007h __; Video page and attribute (blue background, white foreground)
INT 10h ; Call BIOS interrupt to display character with attribute
Q31) How instruction in carry flag is used as implied operand?
Instruction in carry flag is used as an implied operand by checking the carry flag status
after an arithmetic operation to determine if there was a carry or borrow during the
operation.
32) Write down names of four registers in iapx88 that hold the address of dataFour registers in iapx88 that hold the address of data are IP (Instruction Pointer), SP
(Stack Pointer), BP (Base Pointer), and DI (Destination Index).
33) Write a program in assembly language that clears the computer screen
Answer:
mov ah, 06h
moval, 20h ; ASCII code for space character
mov bh, 0
mov cx, 0
mov dh, 24
mov dll, 79
; mov bh, 07h ; Example: white text on black background
int 10h
mov ah, 4Ch.
int21h — ; Call DOS interrupt
et exit function code
34) How immediate operand is transferred into segment register? Explain with
an example.
Immediate operand can be transferred into a segment register by loading the immediate
value into a general-purpose register and then using an appropriate instruction to move
the value from the general-purpose register into the segment register
34) How many types of register which type is used lower to higher levels
Several types of registers in a computer system, including data registers, address
registers, control registers, and status registers.Registers used at lower levels include data registers and control registers, while those
used at higher levels include address registers and status registers.
35) Why is the most important register used in assembly architecture
The most important register used in assembly language programming is often
considered to be the program counter (PC) or instruction pointer (IP), as it keeps track
of the memory address of the next instruction to be executed, essential for program flow
control.
Q36) Write procedure to clear any selective bit
Answer:
mov ax, 0b1101 _; Value in AX register: 1101 (binary)
mov cx, 2 ; Clear the 3rd bit (0-indexed)
call clear_bit _; Call the procedure
Q37) In case of branching techniques used in Intel's architecture, which
instruction is used in temporary diversion and how?
In case of branching techniques used in Intel's architecture, the JMP (Jump) instruction
is used for temporary diversion. It is used to transfer control unconditionally to a
specified memory location.
Q38) Calculate physical memory address
a. 0010:0200
b, 0100:DFDA.
Answer:
a. Physical address = (Segment * 16) + Offset = (0010 * 16) + 0200 = 0x210
b. Physical address = (Segment * 16) + Offset = (0100 * 16) + DFDA = Ox10FDAQ39) Mov (si),ax which instruction mode is used?
The instruction mov (si), ax uses the Register Indirect addressing mode.
40) Why do we use ADC instead of Simple Add??
We use ADC (Add with Carry) instead of simple ADD when we need to perform addition
of two numbers along with the carry flag. ADC adds the source operand, the destination
operand, and the carry flag.
Q41) All components of flag register:
- overflow flag
= zero flag
- parity flag
- Signed flag
- carry flag
Answer:
Components of the flag register
+ Overflow flag (OF)
+ Zero flag (ZF)
+ Parity flag (PF)
+ Signed flag (SF)
+ Carry flag (CF)
42) Video k liya koi code likhna tha or bg clr black character clr green ma print
krna tha... Is ka code likhna thaAnswer:
mov ah, 0x08 _; Video interrupt function to set background and foreground color
mov bh, 0x00; Page number
mov bl, 0x00; Attribute (black background)
mov cx, 80; Number of columns (screen width)
mov dx, 0x02 _; Starting position (row 2, column 0)
intOx10 _; Video interrupt
mov ah, 0x09 _; Video interrupt function to print characters
mov al,'H' —; ASCII value of the character to print
mov bl, 0x02; Attribute (green foreground)
mov cx,1 —_ ; Number of times to print the character
intOx10 _; Video interrupt
43) What is the maximum memory that 8088 processor can access, Give
Mathematical explanation
Answer:
The maximum memory that an 8088 processor can access is 1 MB (220 bytes).
This is because the 8088 processor uses a 20-bit address bus, allowing it to address up
to 2°20 memary locations.
Mathematically, 2°20 = 1,048,576 bytes, which is equivalent to 1 MB
44) What will be effect of executing REPE and REPNE on zero flag?
The REPE (Repeat Equal) and REPNE (Repeat Not Equal) instructions affect the zero
flag
+ REPE: If the zero flag is set (ZF = 1), the REPE instruction will repeat the
following string instruction until the ZF becomes 0 or the CX register becomes 0.+ REPNE: If the zero flag is clear (ZF = 0), the REPNE instruction will repeat the
following string instruction until the ZF becomes 1 or the CX register becomes 0.
45) Define Divide overflow error?
Mov bi,
Mov ax,
Div bl
Answer:
Mov bl, 0x8432
Mov ax, 2
Div bl
46) Calculate the physical memory address generated by the following segment
offset pairs.
1. 1280 : 0321
2. FRFF : 4872
3. A4EB : 0333
4. FFFF : AAAA
5. 1234 : 4336
Answer:
Calculating physical memory address:
a. Physical address = (Segment * 16) + Offset = (1280 * 16) + 0321 = 20480 + 321 =
20801
b. Physical address = (FFFF * 16) + 4872 = 65535 * 16 + 4872 = 1048560 + 4872 =
1053432
c. Physical address = (A4FB * 16) + 0333 = 42107 * 16 + 0333 = 673712 + 333 =
674045d. Physical address = (FFFF * 16) + AAAA = 65535 * 16 + OxAAAA = 1048560 + 43690
= 1092250
e. Physical address = (1234 * 16) + 4336 = 46656 + 4336 = 50992
47) Why We use Add with carry instead of ADD instructions?
We use ADD with Carry (ADC) instead of simple ADD instructions when performing
addition operations involving carry flag. ADC adds two operands along with the carry
flag, allowing for multi-byte additions.
248) NOT operation with example
Answer:
Example!
Perform NOT operation on AL register
mov al, 10101010b ; AL = OxAA (binary)
not al ; NOT operation on AL
Q49) Selective
Answer:
Selective bit inversion operation on lower nibble of AL register
mov al, 11110000b_ ; AL = OxFO (binary)
mov bl, 00001111b ; BL = Ox0F (binary)
and al, bl ; Perform bitwise AND operation with BL
inversion operation on lower nibble
Q50) Interrupt operations
Interrupt operations are used for communication between hardware devices and the
CPU. They allow external devices to interrupt the CPU to request attention or service.Q51) Segment override prefix function
The segment override prefix function is used to override the default segment register
used by the memory access instruction. It allows specifying a different segment register
to access memory.
Q52) Difference assembler & compiler
The assembler converts assembly language code into machine code (binary executable
instructions), while the compiler converts high-level language code (like C, C++) into
machine code
Q53) Why address bus call unidirectional?
The address bus is unidirectional because it only carries addresses from the CPU to the
memory or /O devices. Data flows bidirectionally on data buses, while control signals
(like read/write signals) also have specific directions.
Q54) What is meant of implied Operand with example
Implied Operand refers to an operand that is implicitly understood by the instruction,
rather than explicitly specified in the instruction itselt.
Example of an implied operand is the Accumulator register (AX) in the instruction ADD
AX, BX, where the operand AX is not explicitly mentioned but is implied to be the
destination operand.
Q55) What will be effect of executing REPE and REPNE on zero flag+ REPE: Continues to repeat the following string instruction while the zero flag is
set (indicating equality).
+ REPNE: Continues to repeat the following string instruction while the zero flag is
clear (indicating inequality).
Q56) In assembly language define the "Base Register indirect + offset.
Base Register Indirect + Offset addressing mode in assembly language refers to
accessing memory using a base register (such as BX, BP) combined with an offset
value.
For example, in the instruction MOV AX, [BX+10], the contents of the memory address
calculated as BX + 10 are moved into the AX register.
Q57) Which of the following are not bitwise operator?AND,MOV,ADD,Mul,oR,Not,
TEST,Xor,DIV,ADC.
Among the given options, MOV, ADD, MUL, DIV, and ADC are not bitwise operators.
Q58) Different line of control bus behave differently. Briefly explain the different
operation performed by these lines.
+ Address lines: Transmit memory addresses from the processor to memory or /O
devices.
+ Data lines: Carry data between the processor and memory or /O devices.
+ Control lines: Control signals for operations like read, write, or interrupt handling,
Q59) calculate physical memory address generated by the following segment
offset pairs.
0010:0200,ii= 0100:DFAD
Answer:
i. Physical address = (0010h x 16) + 0200h = 0320h
ii, Physical address = (0100h x 16) + DFADh = 01000h + DFADh = DEADh
Q60) Assembly language program first 5 odd number k dx register mein store
krna tha.
mov ax, varl_ ; Move value of var1 into AX
add ax, var2_; Add value of var2 to AX
sub ax, var3_; Subtract value of var3 from AX
imul ax, 5; Multiply AX by 5
Q61) Why the default association of BP is with SS?
BP (Base Pointer) is by default associated with the SS (Stack Segment) because it is
commonly used as a base address pointer for accessing variables and parameters on
the stack
62) illustrate the mapping of two-dimensional coordinate system into the 1
dimensional video memory with the helping formula
Mapping of a two-dimensional coordinate system into 1-dimensional video memory can
be done using the formula:
Video_Memory_Address = (Row_Number x Number_of_Columns_per_Row +
Column_Number) x Bytes_per_Character
Q63) What is the direction of the following operation in the data bus?-Read
Write
+ Read: Data flows from memory or VO devices to the processor
+ Write: Data flows from the processor to memory or I/O devices.
Q64) Assembly language program first 5 odd number k dx register mein store
krna tha
Answer:
mov cx,5 — ; Set loop counter to 5
mov bx, 1 ; Initialize BX to first odd number
start:
mov dx, bx ; Move current odd number to DX
add bx, 2 ; Increment BX to next odd number
loop start; Repeat loop until CX becomes zero
Q65) Define the following assembly language expression: DAT: db 100
DAT: db 100 defines a data byte (db) named DAT with an initial value of 100
Q66) What are local variable, how they are generated, and what is the most
suitable place to store them?
Local variables are variables defined within a specific scope, such as within a function
or block of code.
They are typically allocated on the stack and can only be accessed within the scope in
which they are defined.Q67) Convert the logical expression into assembly language:
if (AX>BX>CX)&&(AX>BX