Desc

5
3. Addressing Modes Background The CPU accesses data in various ways. The modes for addressing the data are determined during the processor design and cannot be changed by the user. Objective Know how to use and recognize different addressing modes. Pre-Lab Read section 4.1 in the textbook. Given the following four instructions: a) mov [1000h], bx b) mov bx, 1000h c) mov bx, [bx] d) add bx, 1000h Which of these will load register bx with the data value 1000h? Which of these will load register bx with the contents of memory specified by the address in ds:bx? Lab Be sure to add breakpoints to the examples when you enter them into the computer. A. Register addressing mode The register addressing mode does not involve the transfer of data from memory; therefore, this mode is relatively fast. The source and destination registers must match in size. Assemble the following instructions and examine the content of the internal registers MOV BX, DX ;copy contents of DX into BX MOV ES, AX ;copy contents of AX int ES ADD AL, BH ;add the contents of BH to the contents of AL and store in AL What are the contents of the registers after the instructions above?

Transcript of Desc

Page 1: Desc

3. Addressing Modes

Background

The CPU accesses data in various ways. The modes for addressing the data are determined during theprocessor design and cannot be changed by the user.

ObjectiveKnow how to use and recognize different addressing modes.

Pre-Lab

Read section 4.1 in the textbook. Given the following four instructions:

a) mov [1000h], bxb) mov bx, 1000hc) mov bx, [bx]d) add bx, 1000h

Which of these will load register bx with the data value 1000h? Which of these will load register bx withthe contents of memory specified by the address in ds:bx?

Lab

Be sure to add breakpoints to the examples when you enter them into the computer.

A. Register addressing mode

The register addressing mode does not involve the transfer of data from memory; therefore, this mode isrelatively fast.

The source and destination registers must match in size. Assemble the following instructions and examinethe content of the internal registers

MOV BX, DX ;copy contents of DX into BX

MOV ES, AX ;copy contents of AX int ES

ADD AL, BH ;add the contents of BH to the contents of AL and store in AL

What are the contents of the registers after the instructions above?

Page 2: Desc

B. Immediate addressing mode

In the immediate addressing mode, the source operand is a constant. With this address mode, the operand(a constant) is specified as an operand following the instruction mnemonic.

This mode cannot be used for segment registers or the flag register.

Type the following instructions and dump the contents of memory in the present code segment. Do theabove exercise using DEBUG.

MOV AX 3F50H ;move 3F50H into AX

MOV CX, 425 ;load decimal value 425 into CX

MOV BL, 40H ;load 40H into BL

Do both programs offer options in decimal?

What is the op code and the operand produced from the 2nd instruction?

How does it differ from the others? Is it stored in decimal?

If we want to load an immediate value into either a flag register or a segment register, we must firststore it in a general purpose register.

For example,

MOV AX, 3F60

MOV DS, AX

The two addressing modes that we have just examined do not require access to any external memorylocations, however, the remaining modes will require such accesses.

C. Direct addressing mode

The direct addressing mode requires the memory location of the data as part of the instruction. The addressof the data immediately follows the instruction. Notice the brackets present in the instructions below. , Thebrackets signify that the number is a memory offset value and not an immediate operand.

What are the differences between MOV AX, [0010] and MOV AX, 10H? What is stored in AL aftereach instruction is executed?

Page 3: Desc

D. Register Indirect addressing

For register indirect addressing, the address of the memory location is held in a register. The registersreserved for this are SI, DI, and BX. The logical address is usually stored in the register pair formed by DSand an offset in either SI, DI or BX. As an example, MOV AL, [BX] copies the contents of thememory location pointed to by DS:BX into AL. The brackets indicate that BX contains a memory

location.

If the above instruction does NOT have brackets included, the assembler produces an error. What isthe cause of the error?

E. Based relative addressing mode

In the based relative addressing mode, base registers BX and BP plus a displacement value determine theeffective address. The default segments for the logical address are DS for BX ad SS for BP.

Assemble:

MOV CX, [BX] + 20; move DS: BX + 20 into CX

; physical address = DS (shifted left) + BX + 20

The effective address is the offset register + the displacement (BX + 20) for this example.

What are the contents of BX?

What are the contents of CX?

Do the contents of CX change with MOV CX, [BX +20] or MOV CX, 20 [BX]?

F. Indexed Relative Addressing modes

This addressing mode works the same as the based relative addressing mode, except the index registers areDI and SI. The default segment for each is DS.

Assemble:

MOV [SI + 10], AX

What is the memory location where AX is stored? (give both the physical and logical address)

G. Based Indexed Addressing Mode

The based indexed addressing mode is a combination of the based relative addressing mode and theindexed relative addressing mode.

In this mode each instruction requires one base and one index register.

MOV CL, [BX][DI + 8] ; physical address DS (shifted left) + BX + DI + 8

Page 4: Desc

Do the contents of CL change if we use MOV CL, [BX][DI]+8 versus MOV CL,[BX + DI + 8]?

Many instructions can use the addressing modes described above. For example, ADD DL, [BX]would add the contents of memory pointed to by DS:BX to DL and store the result in DL.

Lab Report

Applying what you learned

Give the addressing mode for the following instructions. And comment the instructions:

a) MOV AX, DS

b) MOV CX, [3000]

c) MOV [BP + 6], AL

d) MOV BX, 3675H

e) MOV AH, [BX + SI + 50]

f) MOV CX, DS

What are the contents of memory location DS: 1210 after execution of each of the following sets ofinstructions?

a) MOV BX, 129FH MOV [1210], BX

b) MOV DX, 8C68H MOV [1210], DX

Page 5: Desc