Chapter data transfer, and the address arithmetic

4.1 Data transfer instructions

4.1.2 Operand Type

Operands are three basic types:

    1. Immediate - digital text expression
    2. Register operand - using the CPU registers named
    3. Memory operand - referenced memory location
Number of operations Explanation
reg8 8 general-purpose registers: AH, AL, BH, BL, CH, CL, DH, DL
Regl6 16-bit general purpose registers: AX, BX, CX, DX, SI, DI, SP, BP
reg32 32-bit general purpose registers: EAX, EEX, ECX, EDX, ESI, EDI, ESP, EBP
reg General-purpose registers
comfortable 16-bit segment register: CS, DS, SS, ES, FS, GS
imm 8, 16-bit or 32-bit immediate data
imm8 8, immediate byte value
imm16 16, immediate word values
imm32 32-bit immediate data, double word value
reg/mem8 8 operand may be an 8-bit general purpose registers or memory byte
reg/mem16 16-bit immediate data may be a 16 bit general purpose register or a memory word
reg/mem32 32-bit immediate which can be 32-bit double word general register or memory
mem 8, 16-bit or 32-bit memory operand

 

Direct memory operand: variable name referenced is the offset within the data segment.

 

4.2 Addition and subtraction

4.2.4 NEG instruction

NEG: the digital conversion by the corresponding complementary codes to obtain its opposite number.

TITLE Add and Subtract

INCLUDE Irvine32.inc

;计算26+(-25)
.data
Val SDWORD 25

.code
main PROC
mov eax,Val
neg eax;-25
add eax,26

call DumpRegs

INVOKE ExitProcess,0
main ENDP
END main

 

4.3 and operators and data related directives

OFFSET operator returns the offset of the data label. This offset in bytes, it indicates the start address of the data from the reference distance data segment.

TITLE test

INCLUDE Irvine32.inc

.data
Val SDWORD 25
Val1 SDWORD 66

.code
main PROC
mov esi,OFFSET Val
mov edi,OFFSET Val1
mov eax,0
mov eax,[esi]

call DumpRegs

INVOKE ExitProcess,0
main ENDP
END main

 

ALIGN directive to align a variable byte boundaries, word boundaries, or double word boundary paragraph boundary.

bVal BYTE ?           ;00404000h
ALIGN 2 
wVal WORD ?           ;00404002h
bVal2 BYTE ?          ;00404004h
ALIGN 4 
dVal DWORD ?          ;00404008h
dVal2 DWORD ?         ;0040400Ch

 

PTR operator can be used to rewrite the operand has been declared a type size.

TITLE test

INCLUDE Irvine32.inc

.data
Val SDWORD 12345678h

.code
main PROC
mov eax,0
mov ax,WORD PTR Val;ax=5678h

call DumpRegs

INVOKE ExitProcess,0
main ENDP
END main

 

TYPE operator returns a single element of variable size, the size in bytes of the calculation. For example, the TYPE byte, the return value is 1; TYPE word is, the return value is 2; TYPE double word, the return value is 4; TYPE quadword, the return value is 8.

 

Number, the number of elements LENGTHOF operator computing elements in the array is an array of numeral value appears in the same row defined.

 

LABEL directive may be inserted into a label, and the definition of its size attribute, but does not allocate storage for the reference.

.data
val16 LABEL WORD
val32 DWORD 12345678h
.code
mov ax,val16          ; AX = 5678h
mov dx,[val16+2]      ; DX = 1234h

 

4.4 Indirect Addressing

4.4.1 indirect operand

Protected Mode

Any 32-bit general purpose registers (EAX, EBX, ECX, EDX, ESI, EDI, EBP, and ESP) can constitute a parenthesize indirect operands.

Index operand

Indexing operand refers to adding a constant in the register to generate a valid address. Each 32-bit general purpose registers can be used as index registers. MASM can use different symbols to represent the indexed operation (brackets is a partial symbols):

16-bit register

In real-address mode, generally a 16-bit register as the indexed operation. In this case, the register can be used only SI, DI, BX and BP:

Indexed scale factor operation

In calculating the shift amount, index operand must consider the size of each array element. Such as the embodiment of the double word, the subscript (3) to be multiplied by 4 (a double word size) to generate content for the offset of the array elements 400h

 

4.4.4 Pointer

TITLE Test Program 

. Irvine32 the INCLUDE inc is 
; create user-defined types 
PBYTE TYPEDEF the PTR BYTE 
PWORD TYPEDEF the PTR WORD 
PDWORD TYPEDEF the PTR DWORD 

.data 
Strl BYTE . 1 , 2 , . 3 
Str2 in WORD . 4 , . 5 , . 6 
Str3 starting DWORD . 7 , . 8 , . 9 
; Create pointer variable 
PTr1 PBYTE Strl 
ptr2 PWORD Str2 in 
ptr3 PDWORD Str3 

.code 
main the PROC 
MOV ESI, PTr1 ; the value of the pointer variable assignment 
MOV EAX, 0 
MOV al,[esi + TYPE Str1]

mov eax,0
mov esi,ptr2
mov ax,[esi + TYPE Str2]

mov eax,0
mov esi,ptr3
mov eax,[esi + TYPE Str3]

call DumpRegs

exit
main ENDP
END main

 

Guess you like

Origin www.cnblogs.com/Mayfly-nymph/p/11482983.html