And and or instructions
0 stands for false and 1 for true.
and instruction
Logic and instruction, and operation by bit. False is false.
0&0=0 , 0&1=0 , 1&1=1
The corresponding bit of the operation object can be set to 0 through the and instruction, and other bits remain unchanged.
and al,11011111b take al Set bit 5 of to 0
or instruction
Logic or instruction that performs or operations by bit. If it is true, it is true.
0|0=0 , 0|1=1 , 1|1=1
The corresponding of the operation object can be set to 1 through the or instruction, and other bits remain unchanged.
or al,00100000b take al Set bit 5 of to 1
ASCII code
The process of text editing includes encoding and decoding according to ASCII encoding rules. Press the a key of the keyboard, the computer encodes the information of the key with the rule of ASCII code, and stores its conversion bit 61H in the specified space of the memory.
Data given in character form
In the assembler, use '...' to indicate that the data is given in character form, and the compiler converts them into corresponding ASCII code.
toggle case
The case of the same letter is 20 different from the hexadecimal of ASCII code. The ASCII code of a is 01000001, and the ASCII code of a is 0110001. The difference between case and case lies in the fifth digit. Changing the fifth digit can convert case.
assume cs:code,ds:data data segment db 'MuSic' data ends code segment start: mov ax,data mov ds,ax mov bx,0 mov cx,5 x: mov al,[bx] and al,11011111b ;Change the 5th bit binary code to mov [bx],al ;0 inc bx loop x mov ax,4c00h int 21h code ends end start
[bx+idata]
**[bx] can be used to indicate a memory unit, and [bx+idata] * * can also be used to represent a memory unit with an offset address of (bx)+idata.
mov ax,[bx+200]
Send the contents of a memory cell into ax. The segment address of the memory cell is in ds, and the offset address is the value in bx plus 200.
(ax)=((ds)*16+(bx)+200)
It can also be written as
mov ax,[200+bx] mov ax,200[bx] mov ax,[bx].200
Handle arrays as [bx+idata]
Convert 'MuSiC' and 'ReMiX' to uppercase and lowercase.
assume cs:code,ds:data data segment db 'MuSiC' db 'ReMiX' data ends code segment start: mov ax,data mov ds,ax mov bx,0 mov cx,5 x: mov al,[bx] ;Characters in the first string and al,11011111b mov [bx],al mov al,[bx+5] ;Characters in the second string or al,00100000b mov [bx+5],al inc bx loop x mov ax,4c00h int 21h code ends end start
SI and DI
si and di are registers with similar functions to bx in 8086 CPU. si and di cannot be divided into two 8-bit registers.
mov bx,0 mov ax,[bx] mov si,0 mov ax,[si] mov di,0 mov ax,[di] ;The functions of the three groups of instructions are the same
si and di can also be added with idata.
[bx+si] and [bx+di]
si and di can be represented by offset addresses.
[bx+si] and [bx+di] have similar meanings.
[bx+si] represents a memory unit with an offset address of (bx)+(si).
The contents of a memory unit are sent to ax. The length of the memory unit is 2 bytes and stores a word. The offset address is the value in bx plus the value in si, and the segment address is in ds.
(ax)=((ds)*16+(bx)+(si))
It can also be used
mov ax,[bx][si]
To show.
[bx+si+idata] and [bx+si+idata]
[bx+si+idata] and [bx+si+idata] have similar meanings.
[bx+si+idata] represents a memory unit whose offset address is (bx)+(si)+idata.
The contents of a memory unit are sent to ax, the offset address is the value in bx plus the value in si plus idata, and the segment address is in ds.
(ax)=((ds)*16+(bx)+(si)+idata)
It can also be described in the following format
mov ax,[bx+200+si] mov ax,[200+bx+si] mov ax,200[bx][si] mov ax,[bx].200[si] mov ax,[bx][si].200
Flexible application of different addressing modes
Several methods of locating memory addresses.
- [idata] use a constant to represent the address, which can be used to directly locate a memory unit.
- [bx] uses a variable to represent the memory address, which can be used to indirectly locate a memory unit.
- [bx+idata] a variable and constant are used to represent the address, and a memory unit can be located indirectly with a variable based on a starting address.
- [bx+si] the address is represented by two variables.
- [bx+si+idata] the address is represented by two variables and a constant.
When the program needs to use nested loops, the memory unit or stack is used to save the cx value of the outer loop. When the memory loop ends, the value is returned.
assume cs:code,ds:data,ss:stack data segment db 'ibm ' db 'dec ' db 'dos ' db 'vax ' data ends stack segment dw 0,0,0,0,0,0,0,0 ;Define stack segments stack ends code segment start: mov ax,stack mov ss,ax mov sp,10h mov ax,data mov ds,ax mov bx,0 mov cx,4 x0: push cx ;Define line cx 4 in stack mov si,0 mov cx,3 x: mov al,[bx+si] ;Circular column definition and al,11011111b mov [bx+si],al inc si loop x pop cx ;4 Out of the stack, loop the rows add bx,10h loop x0 mov ax,4c00h int 21h code ends end start