# Assembly 尋址模式和MOV指令

• 寄存器尋址

• 立即尋址

• 存儲器尋址

## 寄存器尋址

MOV DX, TAX_RATE ; Register in first operand
MOV COUNT, CX ; Register in second operand
MOV EAX, EBX ; Both the operands are in registers

## 立即尋址

BYTE_VALUE DB 150 ; A byte value is defined WORD_VALUE DW 300 ; A word value is defined ADD BYTE_VALUE, 65 ; An immediate operand 65 is added
MOV AX, 45H ; Immediate constant 45H is transferred to AX

## 直接存儲器尋址

MOV BX, WORD_VALUE ; Operand from the memory is added to register

## 直接偏移量尋址

BYTE_TABLE DB 14, 15, 22, 45 ; Tables of bytes
WORD_TABLE DW 134, 345, 564, 123 ; Tables of words

MOV CL, BYTE_TABLE[2] ; Gets the 3rd element of the BYTE_TABLE
MOV CL, BYTE_TABLE + 2 ; Gets the 3rd element of the BYTE_TABLE
MOV CX, WORD_TABLE[3] ; Gets the 4th element of the WORD_TABLE
MOV CX, WORD_TABLE + 3 ; Gets the 4th element of the WORD_TABLE

## 間接尋址

MY_TABLE TIMES 10 DW 0 ; Allocates 10 words (2 bytes) each initialized to 0 MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110 ADD EBX, 2 ; EBX = EBX +2 MOV [EBX], 123 ; MY_TABLE[1] = 123

## MOV指令

### 語法:

MOV指令的語法是：

MOV destination, source

MOV指令可以具有以下五種形式之一：

MOV register, register MOV register, immediate
MOV memory, immediate
MOV register, memory
MOV memory, register

• MOV操作操作數應該是同樣大小

• 源操作數的值保持不變

MOV指令產生引起歧義次數。例如，下面語句：

MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110

Type Specifier

BYTE

1

WORD

2

DWORD

4

QWORD

8

TBYTE

10

### 例子:

section .text global _start ;must be declared for linker (ld) _start: ;tell linker entry yiibai ;writing the name 'Zara Ali' mov edx,9 ;message length
mov ecx, name ;message to write
mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel

``````mov \[name\], dword 'Nuha' ; Changed the name to Nuha Ali ;writing the name 'Nuha Ali' mov    edx,8 ;message length
mov    ecx,name ;message to write
mov    ebx,1 ;file descriptor (stdout) mov    eax,4 ;system call number (sys\_write) int 0x80 ;call kernel
mov    eax,1 ;system call number (sys\_exit) int 0x80 ;call kernel``````

section .data
name db 'Zara Ali '

Zara Ali Nuha Ali