|
The real mode in 80386 is provided only for backward compatibility
The Protected Mode does not use segment registers
I will omit this weird form of addressing mode.
Opcode DESTINATION, SOURCE |
Notes:
|
|
|
|
<----------- EAX ------------> +-------+-------+-------+-------+ | | AH | AL | +-------+-------+-------+-------+ <------ AX -----> EAX - 32 bits in register EAX AX - lower 16 bits in register EAX (Other parts of the EAX register is unchanged) AH - second last 8 bits in register EAX (Other parts of the EAX register is unchanged) AL - last 8 bits in register EAX (Other parts of the EAX register is unchanged) |
mov EBX, EAX - copy 32 bits in register EAX to EBX mov BX, AX - copy 16 bits in register EAX to EBX mov BL, AL - copy 8 bits in register EAX to EBX |
mov EBX, AX - src operand = 16 bit register AX destinaton operand = 32 bit register EBX mov BX, AL - src operand = 8 bit register AL destinaton operand = 16 bit register BX |
|
mov eax, 10 ;; Effect: eax = 00000000 00000000 00000000 00001010 |
VarName: DD 0 ;; Integer variable named "VarName" mov EAX, VarName ;; Copy value store in "VarName" to register EAX mov EAX, offset VarName ;; Store the memory address of "VarName" to register EAX |
Example: read the value from variable "sum"
int sum; sum = 1234; |
Example: get the memory address of variable "sum"
int sum; eax = address of the variable sum |
; ------------------------------------------- ; Code segment ; ------------------------------------------- .code start: ; invoke functionStdOut with parameter: addr HelloWorld mov eax, offset HelloWorld ;; eax = address "HelloWorld" push eax ;; Pass parameter to "StdOut" call StdOut ;; Call "StdOut" add esp, 4 ;; Pop parameter ; Exit.... invoke ExitProcess, 0 ;; Return to DOS ; ------------------------------------------- ; Data segment ; ------------------------------------------- .data HelloWorld db "Hello World !", 0 |
|
; ------------------------------------------- ; Code segment ; ------------------------------------------- .code start: mov eax, 1234 ;; eax = 1234 (binary) push eax ;; Pass 1234 mov eax, offset Str1 ;; eax = address of Str1 push eax ;; Pass parameter call crt_printf ;; Call "printf" add esp, 8 ;; Pop parameter ; Exit.... invoke ExitProcess, 0 ; ------------------------------------------- ; Data segment ; ------------------------------------------- .data Str1 db "Value = %d", 0 |
mov eax, offset VarName mov ebx, [eax] ;; Copy value stored at ;; memory location given by EAX ;; into register EBX |
mov ..., [eax] ;; Memory address given by EAX mov ..., [eax + 4] ;; Memory address (EAX + 4) mov ..., [eax + ebx] ;; Memory address (EAX + EBX) mov ..., [eax + 4*ebx] ;; Memory address (EAX + 4*EBX) mov ..., [eax + 4*ebx + 4] ;; Memory address (EAX + 4*EBX + 4) |
Program Example:
; ------------------------------------------- ; Data segment ; ------------------------------------------- .data ArrayA dd 1111, 2222, 3333, 4444 i dd 1 Str1 db "Result = %d", 0 ; ------------------------------------------- ; Program ; ------------------------------------------- .code start: ;; Access ArrayA[0] mov ebx, offset ArrayA ;; ebx = address(ArrayA) mov ebx, [ebx] ;; ebx = ArrayA[0] = 1111 push ebx push offset Str1 call crt_printf add esp, 8 ;; Pop parameter ;; Access ArrayA[1] mov ebx, offset ArrayA mov ebx, [ebx+4] ;; ebx = ArrayA[1] = 2222 push ebx push offset Str1 call crt_printf add esp, 8 ;; Pop parameter ;; Access ArrayA[i] mov ebx, offset ArrayA mov eax, i mov ebx, [ebx + 4*eax] ;; ebx = ArrayA[ i ] = 2222 push ebx push offset Str1 call crt_printf add esp, 8 ;; Pop parameter ;; Access ArrayA[i+1] mov ebx, offset ArrayA mov eax, i mov ebx, [ebx + 4*eax + 4] ;; ebx = ArrayA[ i+1 ] = 3333 push ebx push offset Str1 call crt_printf add esp, 8 ;; Pop parameter ; Exit.... invoke ExitProcess, 0 end start |
|
Byte(8 bits) --> Word(16 bits) cbw - convert byte to word - Effect: sign-extends AL to AX |
A note of warning: uses outdated addressing mode with segment registers (I have avoided this)