Tutorial_1
Tutorial_1
EEE/ECE/INSTR F241
Microprocessors Programming and Interfacing
Tutorial 1
1. Using register addressing mode, write an assembly code to swap the values between two
registers in 8086.
2. Imagine you are working with a data structure where each element is 4 bytes. Write an
assembly program that moves data 30H in the third element using base plus indexed addressing
mode. Assume base address of the array to be 1000H.
3. Repeat problem 2 with register relative addressing.
4. Write an assembly code to load a value from a specific memory location (23FEH) into AX. What
is the addressing mode you will use and what will be the instruction size in bytes? Let the memory
contents at 23FEH be 26H, at 23FFH be 13H, and at 2400H be 4FH. What will be the value in AX
after execution of the code?
5. Write a program that loads a word from memory using register indirect addressing, then adds
an immediate value to it, and then stores the result back in the memory at the same location.
6. Write an assembly routine that stores a 16-bit number (30H) in the memory (assume location
to be 23FEH) using register indirect addressing mode.
7. Write an assembly routine to copy contents of CS register into DS register.
8. Write an assembly routine to copy a 4-byte data from memory location 20FFH to 21EEH.
9. What will be the contents of AH after execution of following command, if the contents of
memory location 13ADH was FFH?
10. Suppose you want to copy 16-bit data from a memory location to a register. However, you
need to optimize on the size of the machine code. You will transfer the content to which register?
Explain with reasons.
11. Determine the 8086 physical memory address where the data 25H will be stored after the
following instruction. Assume CS=1000H, DS=2000H, ES=3000H, SS=4000H
MOV AX,25
MOV BP, AX
MOV [BP], AX
12. Assume the DS register is initialized with FF30H. Determine the physical address where the
MSB of the data will get stored using the following instructions
MOV BX,0F30
MOV AX,1234
MOV [BX+100],AX
13. Determine the ending physical address of a code segment, if the CS register is initialized with
F035H
14. Write assembly instructions to initialize DS register with 1000H and ES register with 2000H
15. Consider two segments:
Code Segment (CS): 2000H
Stack Segment (SS): 1F80H
If the stack pointer (SP) is initialized to 100H and the instruction pointer (IP) is set to 0500H, do
the segments overlap? If so, determine the overlapping range of addresses.
16. Consider the following code
MOV AX, 1000
MOV DS, AX
MOV BX, 0500
MOV AX, 1234
MOV ES, AX
MOV [BX], AX ; without segment override
MOV ES:[BX], AX ; with segment override
Identify the physical addresses where the data 1234H is stored in both cases.
17. Given the following initializations:
Code Segment (CS): ABCDH
Data Segment (DS): 1234H
Stack Segment (SS): 5678H
Offset Values:
Instruction Pointer (IP): 0F12H
Base Pointer (BP): 0A0AH
Stack Pointer (SP): 0BEEH
Calculate the physical addresses for the following:
Current instruction address in the code segment.
The location of the top of the stack (location pointed by SP)
The effective address referenced by [BP + 200H].
18. A program is relocated, and its CS and DS registers are updated to new values:
Before relocation: CS = 2000H, DS = 3000H
After relocation: CS = F000H, DS = F100H
Offset values remain the same before and after relocation.
a) If the instruction pointer (IP) was 0A0BH before relocation, what is the physical address of the
instruction after relocation?
b) If the data offset was 0200H before relocation, what is the physical address of the data after
relocation?
19. If the CS register is initialized to 4A60H, what is the range of IP so that code is always accessed
with in the segment register
20. If the CS register is initialized to FF10H, what is the range of IP so that memory wrap around
(reaches the end of memory and starts from the beginning again) does not occur when accessing
instructions