8086 assembly notes 01

reg / sreg

reg: register

The set of reg includes: ax, bx, cx, dx, ah, al, bh, bl, ch, cl, dh, dl, sp, bp, si, di

sreg: segment register

The collection of sreg includes: ds, ss, cs, es

bx yes of bp

  • In 8086CPU, only these 4 registers (bx, bp, si, di) can be used […]to address the memory unit
    • Correct instruction form:mov ax,[bx] mov ax,[bx+si]
    • Wrong instruction form:mov ax,[cx] mov ax,[ax]
  • In […]can occur in a single four registers, or to only four combinations appear: bx and si, bx and di, Si and BP, BP and di
    • Wrong usage:mov ax,[bx+bp] mov ax,[si+di]
  • As long as the […]register bp is used in, and the segment address is not explicitly given in the instruction, the segment address will be in ss by default

The location of the data

Assembly language uses three concepts to indicate the location of data

  • Immediate number (idata)
    • For the data directly contained in the machine instruction (in the instruction buffer of the CPU before execution), for example mov ax.1, the 1 is the immediate data
  • register
  • Segment address (SA) and offset address (EA)
    • The register storing the segment address can be the default
      • The default scene in ds
        • mov ax,[0]
        • mov ax,[bx]
        • mov ax,[bx+8]
        • mov ax,[bx+si]
        • mov ax,[bx+si+8]
      • The default scene in ss
        • mov ax,[bp]
        • mov ax,[bp+8]
        • mov ax,[bp+si]
        • mov ax,[bp+si+8]
    • The register storing the segment address can also be explicitly given
      • mov ax,ds:[bp]
      • mov ax, es: [bx]
      • mov ax,ss:[bx+si]
      • mov ax,cs:[bx+si+8]

The length of the data

8086CPU instructions can handle two sizes of data, byte and word, so it is necessary to specify in the machine instruction whether the instruction performs a word operation or a byte operation. The 32-bit processor also introduces Double word (double word), four words are also introduced in 64-bit processors

  • Specify the size of the data to be processed by the register name
    • Specify word operation
      • mov ax,1
      • mov bx,ds:[0]
      • mov ds,ax
      • mov ds:[0],ax
      • inc ax
      • add ax,1000
    • Indicates that it is a byte operation
      • mov al, 1
      • mov al, bl
      • mov al,ds:[0]
      • mov ds:[0],al
      • inc al
      • add al, 100
  • In the absence of a register name, use the operator X ptr to specify the length of the memory unit. X can be word or byte in the 8086 assembly instruction
    • Use word ptr to specify the access word (word) unit
      • mov word ptr ds:[0],1
      • inc word ptr [bx]
      • inc word ptr ds:[0]
      • add word ptr [bx],2
    • Use byte ptr to specify the access byte (byte) unit
  • Other methods
    • Some instructions default to access bytes (byte) or words (word)
      • The push instruction only performs word operations:push [1000H]

Structured access data

Generally speaking, we can use [bx+idata+si] to access the data in the structure

  • Use bx to locate the entire structure
  • Use idata to locate a certain data item in the structure
  • Use si to locate each element in the array item

So you can also use a more convenient way of writing, for example:[bx].idata [bx].idata[si]

div

div is the division instruction (division), when using div for division

  • Divisor: 8-bit or 16-bit, in register or memory unit
  • Dividend: (default) placed in AX or DX and AX
divisor Dividend
8th place 16 bits (AX)
16th place 32 bit (DX+AX)
Calculation 8th place 16th place
Quotient AL AX
remainder AH DX

div instruction format:

  • div reg
  • div memory unit
    • div byte ptr ds:[0]
    • div word ptr es:[0]

db、dw、dd

db

db represents a byte in assembly, which is 8 bits per byte. Each time data is read, an offset is added by 1 after reading.

dw

dw represents a word in assembly, which is two bytes and 16 bits. Each time data is read, an offset is added to 2 after reading.

dd

dd represents a double word in assembly, which is four bytes and 32 bits. Each time data is read, an offset is added to 4 after reading.

after

Dup is used in conjunction with db, dw, dd and other data definition directives to repeat data

  • db number of repetitions dup (repeated byte data)
  • dw number of repetitions dup (repeated font data)
  • dd Number of repetitions dup (repeated double word data)

Example

  • db 3 dup(0)
    • Three bytes are defined, and their values ​​are all 0, which is equivalent to db 0,0,0
  • db 3 dup(0,1,2)
    • 9 bytes are defined, their values ​​are (0,1,2,0,1,2,0,1,2), which is equivalent to db 0,1,2,0,1,2,0,1, 2
  • db 3 dup(‘abc’,‘ABC’)
    • 18 bytes are defined, their value is ('abcABCabcABCabcABC'), which is equivalent to db'abcABCabcABCabcABC'

Guess you like

Origin blog.csdn.net/kelxLZ/article/details/111129172